我有一个由中心点和半径表示的球体,位于物体坐标空间。该球体使用可能包括缩放、旋转和平移的变换矩阵转换为世界坐标空间。 我需要在世界空间中为球体构建一个轴对齐的边界框,但我不确定如何做。
这是我的当前方法,它适用于某些情况:
public void computeBoundingBox() {
// center is the middle of the sphere
// averagePosition is the middle of the AABB
// getObjToWorldTransform() is a matrix from obj to world space
getObjToWorldTransform().rightMultiply(center, averagePosition);
Point3 onSphere = new Point3(center);
onSphere.scaleAdd(radius, new Vector3(1, 1, 1));
getObjToWorldTransform().rightMultiply(onSphere);
// but how do you know that the transformed radius is uniform?
double transformedRadius = onSphere.distance(averagePosition);
// maxBound is the upper limit of the AABB
maxBound.set(averagePosition);
maxBound.scaleAdd(transformedRadius, new Vector3(1, 1, 1));
// minBound is the lower limit of the AABB
minBound.set(averagePosition);
minBound.scaleAdd(transformedRadius, new Vector3(-1,-1,-1));
}
然而,我对这种方法的可靠性持怀疑态度。对于非均匀缩放,它不应该失败吗?