clipping.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /***********************************************************************************************************************
  18. * Data types
  19. **********************************************************************************************************************/
  20. typedef enum faceenum_t
  21. {
  22. TOP_PLANE = 0,
  23. RIGHT_PLANE,
  24. BOTTOM_PLANE,
  25. LEFT_PLANE,
  26. NEAR_PLANE,
  27. FAR_PLANE,
  28. /* Keep at the end */
  29. TOTAL_PLANES
  30. } faceenum_t;
  31. typedef struct plane_t
  32. {
  33. vec3_t point;
  34. vec3_t normal;
  35. } plane_t;
  36. typedef struct polygon_t
  37. {
  38. vec3_t vertices[MAX_NUM_POLYGON_VERTICES];
  39. int num_verticices;
  40. } polygon_t;
  41. /***********************************************************************************************************************
  42. * Prototypes
  43. **********************************************************************************************************************/
  44. void initFrustumPlanes(double fov, double aspectRation, double zNear, double zFar);
  45. /* ---- Public polygon stuff ---- */
  46. void clipPolygon(polygon_t *poly);
  47. static inline polygon_t createPolygonFromTriangle(vec3_t p1, vec3_t p2, vec3_t p3)
  48. {
  49. polygon_t ret =
  50. {
  51. .vertices =
  52. {
  53. [0] = p1,
  54. [1] = p2,
  55. [2] = p3,
  56. },
  57. .num_verticices = 3
  58. };
  59. return ret;
  60. }
  61. #endif /* THREEDENGINE_SOURCE_INCLUDE_CLIPPING_H */