I think you version is similar to the version in Netwon by use different simd API.
- Code: Select all
DG_INLINE dgFloat32 BoxIntersect (const dgVector& minBox, const dgVector& maxBox) const
{
dgVector test (((m_p0 <= minBox) | (m_p0 >= maxBox)) & m_isParallel);
if (test.GetSignMask() & 0x07) {
return dgFloat32 (1.2f);
}
dgVector tt0 ((minBox - m_p0).CompProduct4(m_dpInv));
dgVector tt1 ((maxBox - m_p0).CompProduct4(m_dpInv));
dgVector t0 (m_minT.GetMax(tt0.GetMin(tt1)));
dgVector t1 (m_maxT.GetMin(tt0.GetMax(tt1)));
t0 = t0.GetMax(t0.ShiftTripleRight());
t1 = t1.GetMin(t1.ShiftTripleRight());
t0 = t0.GetMax(t0.ShiftTripleRight());
t1 = t1.GetMin(t1.ShiftTripleRight());
dgVector mask (t0 < t1);
dgVector maxDist (dgFloat32 (1.2f));
t0 = (t0 & mask) | maxDist.AndNot(mask);
dgAssert ((mask.GetSignMask() & 1) == (t0.m_x < dgFloat32 (1.0f)));
return t0.m_x;
}
The one in Newton does uses an early out part at the beginning that makes it about 30% slower than your version
Although that part can be predicated in the code, I decided not to because it will no make the code fasters.
The reasons are these.
1- the early out at the beginning of the function and the branch will cost less that the code body the followed
2- when you study patterns of line an box intersections, it is rare that the line Is parallel to the box,
this mean that CPUs with branch prediction will cache the predict the branch as not taken and will take a hit actionably,
as oppose to always take the take the long pass with more instructions. this of course should be test it
I do not see how you version it deal parallel lines to one face or with origin inside the box.
on the Plucker bull *, I will no go but what people say in video game papers,
every person who reinvent the wheel thinks his version is more round than the wheel,
this seem to be a specially traits of the self pointed expert in Gamedevelop.net
The truth is that the plucker non sense is twice slower, the reason is that the code does no a line intersection if does a line test, if you need the intersection param, you still have to do the long version If the ray test
The version that Bird posted look very fast, I bet that in simd can be about twice as fast as our because all the conditionals can be simdsice to have no early out, plus almost all of the calculation at the beginning can be recomputed.
so maybe is I a good candidate to try out.
- Code: Select all
Vector3 d = (p2 - p1) * 0.5f; // this is the center of the line can be precomputed as line.center, I do not know what it mean foeth code
Vector3 e = (max - min) * 0.5f; // this is box size and can be precomputed as box.size
Vector3 c = p1 + d - (min + max) * 0.5f; // (min + max) * 0.5f is the box orgin can be precomputed as box.center
Vector3 ad = d.Absolute(); // this can also be precompyte
it will reduce to
Vector3 c (p1 + line.center - box.size);
after looking at it I think the one bird post can be about 2 to three time faster, I wonder if it can be modified to calculate the intersection.