XNA边界框到顶点碰撞检测
我们正在为我们学校的项目制作一个3D FPS游戏,我们在进行精确的碰撞检测时遇到了一个小问题。 事实上,我们正在使用这个库来检测它们,因为它非常有效。但是,我们必须发送到此库中的方法以测试碰撞的默认“框”是BoundingSphere,但我们希望测试与BoundingBox的碰撞(例如,播放器将表示为BoundingBox,我们将使用模型进行测试) 我已经到了可以通过修改代码将边界框发送到库的地步,但是在这一点上,我不知道该怎么做才能使边界框实际充当一个边界框。事实上,当时我计算碰撞时,就好像它是一个边界球。亲自看看:XNA边界框到顶点碰撞检测,xna,collision-detection,collision,vertex,bounding-box,Xna,Collision Detection,Collision,Vertex,Bounding Box,我们正在为我们学校的项目制作一个3D FPS游戏,我们在进行精确的碰撞检测时遇到了一个小问题。 事实上,我们正在使用这个库来检测它们,因为它非常有效。但是,我们必须发送到此库中的方法以测试碰撞的默认“框”是BoundingSphere,但我们希望测试与BoundingBox的碰撞(例如,播放器将表示为BoundingBox,我们将使用模型进行测试) 我已经到了可以通过修改代码将边界框发送到库的地步,但是在这一点上,我不知道该怎么做才能使边界框实际充当一个边界框。事实上,当时我计算碰撞时,就好像它
private bool nodeCollisions(BoundingBox b, BspNode node)
{
float radius = Vector3.Distance(b.Min, b.Max) / 2;
float squaredBoundingSphereRadius = radius * radius;
Vector3 center = b.Min + (b.Max - b.Min) / 2;
foreach (int i in node.faces)
{
Face face = mGeometry.faces[i];
Vector3 pos1, pos2, pos3;
pos1 = mGeometry.vertices[face.v1];
pos2 = mGeometry.vertices[face.v2];
pos3 = mGeometry.vertices[face.v3];
// check collision with triangle bounding sphere first
if (b.Intersects(face.boundingSphere) == false)
{
continue;
}
Vector3 closestPoint = closestPointInTriangle(center, pos1, pos2, pos3);
float squaredDist = (closestPoint - center).LengthSquared();
if (squaredDist <= squaredBoundingSphereRadius)
{
return true;
}
}
return false;
}
私有布尔节点冲突(边界框b,BspNode节点)
{
浮动半径=矢量3.距离(b.Min,b.Max)/2;
float squaredboundingspherradius=半径*半径;
向量3中心=b.Min+(b.Max-b.Min)/2;
foreach(node.faces中的int i)
{
面=M几何。面[i];
向量3位置1,位置2,位置3;
pos1=mGeometry.顶点[face.v1];
pos2=mGeometry.vertices[face.v2];
pos3=mGeometry.vertices[face.v3];
//首先检查与三角形边界球体的碰撞
如果(b.相交(面.边界球体)==false)
{
继续;
}
向量3闭合点=闭合点三角形(中心,位置1,位置2,位置3);
float squaredist=(closestPoint-center).LengthSquared();
如果(平方数)