csg.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * CSG header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_CSG_H
  10. #define DORAYME_CSG_H
  11. #include <shape.h>
  12. class CSG : public Shape
  13. {
  14. public:
  15. enum OperationType
  16. {
  17. UNION,
  18. DIFFERENCE,
  19. INTERSECTION
  20. };
  21. protected:
  22. Shape *left;
  23. Shape *right;
  24. OperationType operation;
  25. BoundingBox bounds;
  26. protected:
  27. void localIntersect(Ray r, Intersect &xs);
  28. Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
  29. BoundingBox getLocalBounds();
  30. bool intersectionAllowed(bool leftHit, bool inLeft, bool inRight);
  31. void filterIntersections(Intersect &xs, Intersect &ret);
  32. void updateBoundingBox();
  33. BoundingBox getBounds();
  34. public:
  35. CSG(OperationType operation, Shape *left, Shape *right);
  36. void intersect(Ray &r, Intersect &xs);
  37. bool includes(Shape *b);
  38. void updateTransform();
  39. void lock();
  40. void dumpMe(FILE *fp);
  41. };
  42. #endif /* DORAYME_CSG_H */