intersection.cpp 771 B

12345678910111213141516171819202122232425262728293031323334
  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. Tuple overHitP = hitP + normalV * getEpsilon();
  23. return Computation(this->object,
  24. this->t,
  25. hitP,
  26. eyeV,
  27. normalV,
  28. overHitP,
  29. inside);
  30. }