22 #ifndef __ND_FAST_RAY_H__
23 #define __ND_FAST_RAY_H__
25 #include "ndCoreStdafx.h"
28 #include "ndClassAlloc.h"
36 ,m_p0(l0 & ndVector::m_triplexMask)
37 ,m_p1(l1 & ndVector::m_triplexMask)
43 } D_GCC_NEWTON_ALIGN_32;
53 ndFloat32 BoxIntersect(
const ndVector& minBox,
const ndVector& maxBox)
const;
57 D_CORE_API ndFloat32 PolygonIntersect(
const ndVector& normal, ndFloat32 maxT,
const ndFloat32*
const polygon, ndInt32 strideInBytes,
const ndInt32*
const indexArray, ndInt32 indexCount)
const;
65 } D_GCC_NEWTON_ALIGN_32 ;
70 ,m_minT(ndFloat32(0.0f))
71 ,m_maxT(ndFloat32(1.0f))
73 ndAssert(m_p0.m_w == ndFloat32(0.0f));
74 ndAssert(m_p1.m_w == ndFloat32(0.0f));
75 ndAssert(m_diff.m_w == ndFloat32(0.0f));
77 ndAssert(m_diff.DotProduct(m_diff).GetScalar() > ndFloat32(0.0f));
78 m_isParallel = (m_diff.Abs() <
ndVector(1.0e-8f));
79 m_dpInv = m_diff.Select(
ndVector(ndFloat32(1.0e-20f)), m_isParallel).Reciproc() & ndVector::m_triplexMask;
80 m_unitDir = m_diff.Normalize();
83 inline ndRay ndFastRay::PointDistance(
const ndVector& point)
const
87 ndFloat32 t = ndClamp(m_diff.DotProduct(point - m_p0).GetScalar() / m_diff.DotProduct(m_diff).GetScalar(), ndFloat32(0.0f), ndFloat32(1.0f));
88 return ndRay (m_p0 + m_diff.Scale(t), point);
91 inline ndInt32 ndFastRay::BoxTest(
const ndVector& minBox,
const ndVector& maxBox)
const
94 ndVector test(((m_p0 <= minBox) | (m_p0 >= maxBox)) & m_isParallel);
95 if (test.GetSignMask() & 0x07)
100 ndVector tt0(m_dpInv * (minBox - m_p0));
101 ndVector tt1(m_dpInv * (maxBox - m_p0));
103 ndVector t0(m_minT.GetMax(tt0.GetMin(tt1)));
104 ndVector t1(m_maxT.GetMin(tt0.GetMax(tt1)));
105 t0 = t0.GetMax(t0.ShiftTripleRight());
106 t1 = t1.GetMin(t1.ShiftTripleRight());
107 t0 = t0.GetMax(t0.ShiftTripleRight());
108 t1 = t1.GetMin(t1.ShiftTripleRight());
109 return ((t0 < t1).GetSignMask() & 1);
113 ndFloat32 tmin = 0.0f;
114 ndFloat32 tmax = 1.0f;
116 for (ndInt32 i = 0; i < 3; ++i)
120 if (m_p0[i] <= minBox[i] || m_p0[i] >= maxBox[i])
127 ndFloat32 t1 = (minBox[i] - m_p0[i]) * m_dpInv[i];
128 ndFloat32 t2 = (maxBox[i] - m_p0[i]) * m_dpInv[i];
152 inline ndFloat32 ndFastRay::BoxIntersect(
const ndVector& minBox,
const ndVector& maxBox)
const
154 ndVector test(((m_p0 <= minBox) | (m_p0 >= maxBox)) & m_isParallel);
155 if (test.GetSignMask() & 0x07)
157 return ndFloat32(1.2f);
159 ndVector tt0(m_dpInv * (minBox - m_p0));
160 ndVector tt1(m_dpInv * (maxBox - m_p0));
161 ndVector t0(m_minT.GetMax(tt0.GetMin(tt1)));
162 ndVector t1(m_maxT.GetMin(tt0.GetMax(tt1)));
163 t0 = t0.GetMax(t0.ShiftTripleRight());
164 t1 = t1.GetMin(t1.ShiftTripleRight());
165 t0 = t0.GetMax(t0.ShiftTripleRight());
166 t1 = t1.GetMin(t1.ShiftTripleRight());
169 t0 = maxDist.Select(t0, mask);
170 ndAssert((mask.GetSignMask() & 1) == (t0.m_x < ndFloat32(1.0f)));
171 return t0.GetScalar();