clipping.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * 3D Engine
  3. * clipping.h:
  4. * Based on pikuma.com 3D software renderer in C
  5. * Copyright (c) 2021 986-Studio. All rights reserved.
  6. *
  7. * Created by Manoël Trapier on 11/03/2021.
  8. */
  9. #ifndef THREEDENGINE_SOURCE_INCLUDE_CLIPPING_H
  10. #define THREEDENGINE_SOURCE_INCLUDE_CLIPPING_H
  11. #include <vector.h>
  12. #include <triangle.h>
  13. /***********************************************************************************************************************
  14. * Constants
  15. **********************************************************************************************************************/
  16. #define MAX_NUM_POLYGON_VERTICES (10)
  17. #define MAX_NUM_POLYGON_TRIANGLES (10)
  18. /***********************************************************************************************************************
  19. * Data types
  20. **********************************************************************************************************************/
  21. typedef enum faceenum_t
  22. {
  23. TOP_PLANE = 0,
  24. RIGHT_PLANE,
  25. BOTTOM_PLANE,
  26. LEFT_PLANE,
  27. NEAR_PLANE,
  28. FAR_PLANE,
  29. /* Keep at the end */
  30. TOTAL_PLANES
  31. } faceenum_t;
  32. typedef struct plane_t
  33. {
  34. vec3_t point;
  35. vec3_t normal;
  36. } plane_t;
  37. typedef struct polygon_t
  38. {
  39. vec3_t vertices[MAX_NUM_POLYGON_VERTICES];
  40. int num_vertices;
  41. } polygon_t;
  42. /***********************************************************************************************************************
  43. * Prototypes
  44. **********************************************************************************************************************/
  45. void initFrustumPlanes(double fovY, double aspectRatio, double zNear, double zFar);
  46. /* ---- Public polygon stuff ---- */
  47. void clipPolygon(polygon_t *poly);
  48. void createTriangleFromPolygon(polygon_t *polygon, triangle_t *triangleList, uint32_t *outNumber);
  49. static inline polygon_t createPolygonFromTriangle(vec3_t p1, vec3_t p2, vec3_t p3)
  50. {
  51. polygon_t ret =
  52. {
  53. .vertices =
  54. {
  55. [0] = p1,
  56. [1] = p2,
  57. [2] = p3,
  58. },
  59. .num_vertices = 3
  60. };
  61. return ret;
  62. }
  63. #endif /* THREEDENGINE_SOURCE_INCLUDE_CLIPPING_H */