Graphics Reference
In-Depth Information
if (Abs(t[0] * R[2][0] - t[2] * R[0][0]) > ra + rb) return 0;
// Test axisL=A1xB1
ra = a.e[0] * AbsR[2][1] + a.e[2] * AbsR[0][1];
rb = b.e[0] * AbsR[1][2] + b.e[2] * AbsR[1][0];
if (Abs(t[0] * R[2][1] - t[2] * R[0][1]) > ra + rb) return 0;
// Test axisL=A1xB2
ra = a.e[0] * AbsR[2][2] + a.e[2] * AbsR[0][2];
rb = b.e[0] * AbsR[1][1] + b.e[1] * AbsR[1][0];
if (Abs(t[0] * R[2][2] - t[2] * R[0][2]) > ra + rb) return 0;
// Test axisL=A2xB0
ra = a.e[0] * AbsR[1][0] + a.e[1] * AbsR[0][0];
rb = b.e[1] * AbsR[2][2] + b.e[2] * AbsR[2][1];
if (Abs(t[1] * R[0][0] - t[0] * R[1][0]) > ra + rb) return 0;
// Test axisL=A2xB1
ra = a.e[0] * AbsR[1][1] + a.e[1] * AbsR[0][1];
rb = b.e[0] * AbsR[2][2] + b.e[2] * AbsR[2][0];
if (Abs(t[1] * R[0][1] - t[0] * R[1][1]) > ra + rb) return 0;
// Test axisL=A2xB2
ra = a.e[0] * AbsR[1][2] + a.e[1] * AbsR[0][2];
rb = b.e[0] * AbsR[2][1] + b.e[1] * AbsR[2][0];
if (Abs(t[1] * R[0][2] - t[0] * R[1][2]) > ra + rb) return 0;
// Since no separating axis is found, the OBBs must be intersecting
return 1;
}
To make the OBB-OBB test as efficient as possible, it is important that the axes are
tested in the order given in Table 4.1. The first reason for using this order is that by
testing three orthogonal axes first there is little spatial redundancy in the tests, and
the entire space is quickly covered. Second, with the setup given here, where A is
transformed to the origin and aligned with the coordinate system axes, testing the
axes of A is about half the cost of testing the axes of B . Although it is not done here,
the calculations of R and AbsR should be interleaved with the first three tests, so that
they are not unnecessarily performed in their entirety when the OBB test exits in one
of the first few if statements.
If OBBs are used in applications in which they often tend to have one axis aligned
with the current world up, for instance, when traveling on ground, it is worthwhile
special-casing these “vertically aligned”OBBs. This simplification allows for a much
 
Search WWH ::




Custom Search