Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在XNA 4.0中选中边界框?_Xna_Xna 4.0_Collision_Bounding Box - Fatal编程技术网

如何在XNA 4.0中选中边界框?

如何在XNA 4.0中选中边界框?,xna,xna-4.0,collision,bounding-box,Xna,Xna 4.0,Collision,Bounding Box,我想在XNA 4.0中使用类BoundingBox来检查立方体与立方体或立方体与球体之间的碰撞?我知道BoundingSphere,但不知道如何使用BoundingBox。这方面有什么好的样品吗!谢谢 您可以这样创建边界框: Vector3 CenterOfBox = new Vector3(10,10,10); int Width = 10; int Height = 10; BoundingBox BoundingBox1 = new BoundingBox(CenterOfBox - ne

我想在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));
更多信息:

假设您有BoundingBox1和BoundingBox2

然后,您可以检查它们是否与以下对象相交:

if(BoundingBox1.Intersect(BoundingBox2))
{
    //They hit
}
else
{
    //They don't hit
}
也可以在Intersect函数中传递边界球体


更多信息:

查找XNA类信息的一个好方法是用谷歌搜索它们,或者访问它们,谢谢!你知道如何检查一个ModelBone的BoundingSphere???@Google New ModelBone没有边界,它是一个位置的固定器。您应该使用ModelMesh来计算boundingsphere,ModelMesh具有属性“boundingsphere”(或者您可以在骨骼的位置创建一个球体)@GoogleNew您应该查看