plane.cpp 855 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Plane implementation
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <tuple.h>
  10. #include <ray.h>
  11. #include <shape.h>
  12. #include <plane.h>
  13. #include <math_helper.h>
  14. Intersect Plane::localIntersect(Ray r)
  15. {
  16. double t;
  17. Intersect ret = Intersect();
  18. if (fabs(r.direction.y) < getEpsilon())
  19. {
  20. /* With a direction == 0, the ray can't intersect the plane */
  21. return ret;
  22. }
  23. t = -r.origin.y / r.direction.y;
  24. ret.add(Intersection(t, this));
  25. return ret;
  26. }
  27. Tuple Plane::localNormalAt(Tuple point, Intersection *hit)
  28. {
  29. return Vector(0, 1, 0);
  30. }
  31. BoundingBox Plane::getLocalBounds()
  32. {
  33. BoundingBox ret;
  34. ret | Point(-INFINITY, 0-getEpsilon(), -INFINITY);
  35. ret | Point(INFINITY, 0+getEpsilon(), INFINITY);
  36. return ret;
  37. }