Example #1
0
OBB Frustum::MinimalEnclosingOBB(float expandGuardband) const
{
	assume(IsFinite());
	assume(front.IsNormalized());
	assume(up.IsNormalized());

	OBB obb;
	obb.pos = pos + (nearPlaneDistance + farPlaneDistance) * 0.5f * front;
	obb.axis[1] = up;
	obb.axis[2] = -front;
	obb.axis[0] = Cross(obb.axis[1], obb.axis[2]);
	obb.r = float3::zero;
	for(int i = 0; i < 8; ++i)
		obb.Enclose(CornerPoint(i));

	// Expand the generated OBB very slightly to avoid numerical issues when
	// testing whether this Frustum actually is contained inside the generated OBB.
	obb.r.x += expandGuardband;
	obb.r.y += expandGuardband;
	obb.r.z += expandGuardband;
	return obb;
}