csg.h 982 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. Intersect localIntersect(Ray r);
  28. Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
  29. BoundingBox getLocalBounds();
  30. bool intersectionAllowed(bool leftHit, bool inLeft, bool inRight);
  31. Intersect filterIntersections(Intersect &xs);
  32. void updateBoundingBox();
  33. BoundingBox getBounds();
  34. public:
  35. CSG(OperationType operation, Shape *left, Shape *right);
  36. Intersect intersect(Ray r);
  37. bool includes(Shape *b);
  38. void updateTransform();
  39. void dumpMe(FILE *fp);
  40. };
  41. #endif /* DORAYME_CSG_H */