/* * 3D Engine * clipping.h: * Based on pikuma.com 3D software renderer in C * Copyright (c) 2021 986-Studio. All rights reserved. * * Created by Manoƫl Trapier on 11/03/2021. */ #ifndef THREEDENGINE_SOURCE_INCLUDE_CLIPPING_H #define THREEDENGINE_SOURCE_INCLUDE_CLIPPING_H #include #include /*********************************************************************************************************************** * Constants **********************************************************************************************************************/ #define MAX_NUM_POLYGON_VERTICES (10) #define MAX_NUM_POLYGON_TRIANGLES (10) /*********************************************************************************************************************** * Data types **********************************************************************************************************************/ typedef enum faceenum_t { TOP_PLANE = 0, RIGHT_PLANE, BOTTOM_PLANE, LEFT_PLANE, NEAR_PLANE, FAR_PLANE, /* Keep at the end */ TOTAL_PLANES } faceenum_t; typedef struct plane_t { vec3_t point; vec3_t normal; } plane_t; typedef struct polygon_t { vec3_t vertices[MAX_NUM_POLYGON_VERTICES]; int num_vertices; } polygon_t; /*********************************************************************************************************************** * Prototypes **********************************************************************************************************************/ void initFrustumPlanes(double fovY, double aspectRatio, double zNear, double zFar); /* ---- Public polygon stuff ---- */ void clipPolygon(polygon_t *poly); void createTriangleFromPolygon(polygon_t *polygon, triangle_t *triangleList, uint32_t *outNumber); static inline polygon_t createPolygonFromTriangle(vec3_t p1, vec3_t p2, vec3_t p3) { polygon_t ret = { .vertices = { [0] = p1, [1] = p2, [2] = p3, }, .num_vertices = 3 }; return ret; } #endif /* THREEDENGINE_SOURCE_INCLUDE_CLIPPING_H */