group.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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->objectList[p]; };
  33. Shape *getUnboxable(const int p) { return this->unboxableObjectList[p]; };
  34. Intersect intersect(Ray r);
  35. BoundingBox getLocalBounds();
  36. BoundingBox getBounds();
  37. void updateBoundingBox();
  38. void updateTransform();
  39. bool includes(Shape *b);
  40. uint32_t getObjectCount() { return this->objectCount; };
  41. uint32_t getUnboxableCount() { return this->unboxableObjectCount; };
  42. Group(const char *name = nullptr);
  43. void lock();
  44. const char *getName() { return this->name; };
  45. void dumpMe(FILE * fp);
  46. };
  47. #endif /* DORAYME_GROUP_H */