Graphics Reference
In-Depth Information
if (s1.r >= s0.r)
s = s1;
else
s = s0;
} else {
// Spheres partially overlapping or disjoint
float dist = Sqrt(dist2);
s.r = (dist + s0.r + s1.r) * 0.5f;
s.c = s0.c;
if (dist > EPSILON)
s.c += ((s.r - s0.r) / dist) * d;
}
}
6.5.3 Merging Two OBBs
Computing an OBB from two OBBs is a bit more complicated. A straightforward
solution is to use the techniques presented in Chapter 4. For instance, the 16 vertices
of the two boxes can be passed directly to the ComputeOBB() function (which uses the
eigenvectors of the covariance matrix for the points as the box axes). This could be
further combined with the min-principal-component technique described in Section
4.4.4. The latter is used for the bottom-up construction in the BoxTree algorithm
described in [Barequet96].
A drawback with these techniques is the cost of the iterative algorithms used to
compute the eigenvectors, making them less suitable for real-time use. An alternative
noniterative solution is presented in [Eberly00]. He suggests combining the rotations
of the two OBBs by converting them into quaternions, interpolating halfway between
them and then converting back to a rotation matrix, now determining the axes of the
OBB. The extents are then established through projection onto these axes. Note that
in the pseudocode presented in [Eberly00] the OBB center is determined before the
OBB extents are calculated. In general, this will not fit the OBB as tightly as possible.
To make the OBB tight with respect to the two OBBs, the center point should be
calculated after the extents have been established.
6.5.4 Merging Two k -DOPs
Merging two k -DOPs is just as easy as merging two AABBs. For each k -DOP axis, the
bounding k -DOP is defined by the smaller of the min values and the larger of the max
values for the two DOPs to be bounded. Per definition, no planes can bound tighter
than these do. The implementation is strikingly similar to the AABB merging code.
 
Search WWH ::




Custom Search