我想在XNA 4.0中使用类BoundingBox检查多维数据集与多维数据集或多维数据集与球体之间的碰撞?我知道BoundingSphere但我不知道对BoundingBox的使用。有关于此的任何好样品!谢谢!
答案 0 :(得分:4)
你制作这样的边界框:
Vector3 CenterOfBox = new Vector3(10,10,10);
int Width = 10;
int Height = 10;
BoundingBox BoundingBox1 = new BoundingBox(CenterOfBox - new Vector(Width/2,Height/2,Width/2),CenterOfBox + new Vector(Width/2,Height/2,Width/2));
更多信息:http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.boundingbox.boundingbox.aspx
假设你有BoundingBox1和BoundingBox2
然后你可以检查它们是否相交:
if(BoundingBox1.Intersect(BoundingBox2))
{
//They hit
}
else
{
//They don't hit
}
您还可以在Intersect函数中传递BoundingSphere
更多信息:http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.boundingbox.intersects.aspx