Ray.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "Ray.h"
  2. #include "Plane.h"
  3. namespace cln {
  4. //==============================================================================
  5. // getTransformed =
  6. //==============================================================================
  7. Ray Ray::getTransformed(const Transform& transform) const
  8. {
  9. Ray out;
  10. out.origin = origin.getTransformed(transform);
  11. out.dir = transform.getRotation() * dir;
  12. return out;
  13. }
  14. //==============================================================================
  15. // testPlane =
  16. //==============================================================================
  17. float Ray::testPlane(const Plane& plane) const
  18. {
  19. float dist = plane.test(origin);
  20. float cos_ = plane.getNormal().dot(dir);
  21. if(cos_ > 0.0) // the ray points to the same half-space as the plane
  22. {
  23. if(dist < 0.0) // the ray's origin is behind the plane
  24. {
  25. return 0.0;
  26. }
  27. else
  28. {
  29. return dist;
  30. }
  31. }
  32. else
  33. {
  34. if(dist > 0.0)
  35. {
  36. return 0.0;
  37. }
  38. else
  39. {
  40. return dist;
  41. }
  42. }
  43. }
  44. } // end namespace