intersect.cpp 622 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Intersect implementation
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <stdlib.h>
  10. #include <intersect.h>
  11. #define MIN_ALLOC (2)
  12. Intersect::Intersect()
  13. {
  14. this->allocated = MIN_ALLOC;
  15. this->list = (Intersection **)calloc(sizeof(Object *), MIN_ALLOC);
  16. this->num = 0;
  17. }
  18. void Intersect::add(Intersection *i)
  19. {
  20. if ((this->num + 1) < this->allocated)
  21. {
  22. this->allocated *= 2;
  23. this->list = (Intersection **)realloc(this->list, sizeof(Object *) * this->allocated);
  24. }
  25. this->list[this->num++] = i;
  26. }