我想在XNA 4.0中使用BoundingBox类来检测立方体与立方体或立方体与球体之间的碰撞。我知道BoundingSphere,但不知道如何使用BoundingBox。有没有关于此的好样例!谢谢!
我想在XNA 4.0中使用BoundingBox类来检测立方体与立方体或立方体与球体之间的碰撞。我知道BoundingSphere,但不知道如何使用BoundingBox。有没有关于此的好样例!谢谢!
你可以像这样创建边界框:
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
}