cmesh.h 853 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. *** :: cmesh ::
  3. ***
  4. ***
  5. **/
  6. #ifndef cmesh_h
  7. #define cmesh_h
  8. #include "cengine.h"
  9. typedef struct {
  10. vec3 a, b, c;
  11. vec3 norm;
  12. sphere bound;
  13. } ctri;
  14. ctri ctri_new(vec3 a, vec3 b, vec3 c, vec3 norm);
  15. ctri ctri_transform(ctri t, mat4 m, mat3 mn);
  16. ctri ctri_transform_space(ctri t, mat3 s, mat3 sn);
  17. bool ctri_inside_plane(ctri t, plane p);
  18. bool ctri_outside_plane(ctri t, plane p);
  19. bool ctri_intersects_plane(ctri t, plane p);
  20. typedef struct cmesh {
  21. bool is_leaf;
  22. union {
  23. struct {
  24. plane division;
  25. struct cmesh* front;
  26. struct cmesh* back;
  27. };
  28. struct {
  29. ctri* triangles;
  30. int triangles_num;
  31. sphere bound;
  32. };
  33. };
  34. } cmesh;
  35. cmesh* col_load_file(char* filename);
  36. void cmesh_delete(cmesh* cm);
  37. sphere cmesh_bound(cmesh* cm);
  38. void cmesh_subdivide(cmesh* cm, int iterations);
  39. #endif