40 #ifndef __VMML__INTERSECTION__HPP__
41 #define __VMML__INTERSECTION__HPP__
43 #include <vmmlib/vector.hpp>
61 , _direction (
vmml::normalize( direction ))
79 const vec3 _direction;
84 template<
typename T >
88 const vec3 center =
vec3(sphere.x(), sphere.y(), sphere.z());
89 const T radius = sphere.w();
91 const vec3 centerVec = center - _origin;
92 const T vecProjection = centerVec.dot(_direction);
94 const T sqDistance = centerVec.squared_length();
95 const T sqRadius = radius * radius;
98 if( vecProjection < 0 && sqDistance > sqRadius )
102 const T sqCenterToProj = sqDistance - vecProjection * vecProjection;
104 if( sqCenterToProj > sqRadius )
108 const T distSurface = sqrt( sqRadius - sqCenterToProj );
110 if(sqDistance > sqRadius)
111 t = vecProjection - distSurface;
113 t = vecProjection + distSurface;
intersection(const vec3 &origin, const vec3 &direction)
Constructors.
heavily inspired by boost::enable_if http://www.boost.org, file: boost/utility/enable_if.hpp, Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine
bool test_sphere(const vec4 &sphere, T &t) const
Ray Sphere Intersection - Optimized solution "Real-time Rendering 3rd Edition".