我想从我的 Box 类中计算 AABB(轴对齐边界框)。
盒子类:
Box{
Point3D center; //x,y,z
Point3D halfSize; //x,y,z
Point3D rotation; //x,y,z rotation
};
AABB 类(方框,但没有旋转):
BoundingBox{
Point3D center; //x,y,z
Point3D halfSize; //x,y,z
};
Ofc,当rotation = (0,0,0), BoundingBox = Box
. 但是如何计算包含 Box 中所有内容的最小 BoundingBox whenrotation = (rx,ry,rz)
呢?
如果有人问:旋转是弧度,我在 DirectX 矩阵旋转中使用它:
XMMATRIX rotX = XMMatrixRotationX( rotation.getX() );
XMMATRIX rotY = XMMatrixRotationY( rotation.getY() );
XMMATRIX rotZ = XMMatrixRotationZ( rotation.getZ() );
XMMATRIX scale = XMMatrixScaling( 1.0f, 1.0f, 1.0f );
XMMATRIX translate = XMMatrixTranslation( center.getX(), center.getY(), center.getZ() );
XMMATRIX worldM = scale * rotX * rotY * rotZ * translate;