group.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. void localIntersect(Ray r, Intersect &xs);
  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. void intersect(Ray &r, Intersect &xs);
  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. void setBounds(BoundingBox &bb) { this->bounds | bb; };
  46. const char *getName() { return this->name; };
  47. void dumpMe(FILE * fp);
  48. };
  49. #endif /* DORAYME_GROUP_H */