group.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Group header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_GROUP_H
  10. #define DORAYME_GROUP_H
  11. #include <shape.h>
  12. #include <stdio.h>
  13. /* TODO: Add a way to force(?) material from group to be applied on childs */
  14. class Group : public Shape
  15. {
  16. private:
  17. uint32_t allocatedObjectCount;
  18. Shape* *objectList;
  19. uint32_t objectCount;
  20. uint32_t allocatedUnboxableObjectCount;
  21. Shape* *unboxableObjectList;
  22. uint32_t unboxableObjectCount;
  23. char name[32 + 1];
  24. protected:
  25. Intersect localIntersect(Ray r);
  26. Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
  27. BoundingBox bounds;
  28. public:
  29. bool isEmpty();
  30. void addObject(Shape *s);
  31. void removeObject(Shape *s);
  32. Shape *operator[](const int p) { return this->getObject(p); };
  33. Shape *getObject(const int p) { return this->objectList[p]; };
  34. Shape *getUnboxable(const int p) { return this->unboxableObjectList[p]; };
  35. Intersect intersect(Ray r);
  36. BoundingBox getLocalBounds();
  37. BoundingBox getBounds();
  38. void updateBoundingBox();
  39. void updateTransform();
  40. bool includes(Shape *b);
  41. uint32_t getObjectCount() { return this->objectCount; };
  42. uint32_t getUnboxableCount() { return this->unboxableObjectCount; };
  43. Group(const char *name = nullptr);
  44. void lock();
  45. const char *getName() { return this->name; };
  46. void dumpMe(FILE * fp);
  47. };
  48. #endif /* DORAYME_GROUP_H */