| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include "Ray.h"
- #include "Plane.h"
- namespace cln {
- //==============================================================================
- // getTransformed =
- //==============================================================================
- Ray Ray::getTransformed(const Transform& transform) const
- {
- Ray out;
- out.origin = origin.getTransformed(transform);
- out.dir = transform.getRotation() * dir;
- return out;
- }
- //==============================================================================
- // testPlane =
- //==============================================================================
- float Ray::testPlane(const Plane& plane) const
- {
- float dist = plane.test(origin);
- float cos_ = plane.getNormal().dot(dir);
- if(cos_ > 0.0) // the ray points to the same half-space as the plane
- {
- if(dist < 0.0) // the ray's origin is behind the plane
- {
- return 0.0;
- }
- else
- {
- return dist;
- }
- }
- else
- {
- if(dist > 0.0)
- {
- return 0.0;
- }
- else
- {
- return dist;
- }
- }
- }
- } // end namespace
|