intersection.cpp 686 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Intersection implementation
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <intersection.h>
  10. #include <shape.h>
  11. Computation Intersection::prepareComputation(Ray r)
  12. {
  13. Tuple hitP = r.position(this->t);
  14. Tuple normalV = this->object->normalAt(hitP);
  15. Tuple eyeV = -r.direction;
  16. bool inside = false;
  17. if (normalV.dot(eyeV) < 0)
  18. {
  19. inside = true;
  20. normalV = -normalV;
  21. }
  22. return Computation(this->object,
  23. this->t,
  24. hitP,
  25. eyeV,
  26. normalV,
  27. inside);
  28. }