【问题标题】:How to check bounding box in XNA 4.0?如何检查 XNA 4.0 中的边界框?
【发布时间】:2012-12-23 11:00:55
【问题描述】:

我想在 XNA 4.0 中使用类 BoundingBox 来检查立方体与立方体或立方体与球体之间的碰撞?我知道 BoundingSphere,但我不知道使用 BoundingBox。有任何关于这个的好样本!谢谢!

【问题讨论】:

标签: xna xna-4.0 collision bounding-box


【解决方案1】:

你制作这样的边界框:

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

【讨论】:

  • 谢谢!你知道如何检查一个 ModelBone 的 BoundingSphere 吗??
  • @Google New ModelBone 没有边界,它是一个位置的持有者。你应该得到它的ModelMesh来计算boundingsphere,ModelMeshes有属性“BoundingSphere”(或者你可以在骨骼的位置制作一个球体)
猜你喜欢
  • 1970-01-01
  • 2012-03-23
  • 1970-01-01
  • 2011-11-17
  • 1970-01-01
  • 1970-01-01
  • 2013-08-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多