plane.cpp 822 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. void Plane::localIntersect(Ray r, Intersect &xs)
  15. {
  16. double t;
  17. if (fabs(r.direction.y) < getEpsilon())
  18. {
  19. /* With a direction == 0, the ray can't intersect the plane */
  20. }
  21. else
  22. {
  23. t = -r.origin.y / r.direction.y;
  24. xs.add(Intersection(t, this));
  25. }
  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. }