C# XNA 3D碰撞矩阵不工作

C# XNA 3D碰撞矩阵不工作,c#,matrix,3d,xna,collision,C#,Matrix,3d,Xna,Collision,我之前问过一个问题,为什么我的碰撞没有起作用。我得到了一个有意义的好答案:将我在DrawModel方法中所做的相同转换应用于isCollision方法。然而,这并没有起作用。我无法理解如何在isCollision方法中进行相同的转换。如果有人能帮助我,那就太好了。谢谢方法如下: private bool checkPlayerCollision(Model model1, Matrix world1) { //Make floor matrix Matrix floorMatri

我之前问过一个问题,为什么我的碰撞没有起作用。我得到了一个有意义的好答案:将我在DrawModel方法中所做的相同转换应用于isCollision方法。然而,这并没有起作用。我无法理解如何在isCollision方法中进行相同的转换。如果有人能帮助我,那就太好了。谢谢方法如下:

private bool checkPlayerCollision(Model model1, Matrix world1)
{
    //Make floor matrix
    Matrix floorMatrix = Matrix.CreateTranslation(new Vector3(0, 0, 0));
    //Make ship1 matrix
    Matrix ship1WorldMatrix = Matrix.CreateTranslation(ship1loc);
    //Make ship2 matrix
    Matrix ship2WorldMatrix = Matrix.CreateTranslation(ship2loc);
    //Check for collision with floor
    if (IsCollision(model1, world1, floor, floorMatrix)) return true;
    //Check for collision with ship1
    if (IsCollision(model1, world1, model, ship1WorldMatrix)) return true;
    //Check for collision with ship2
    if (IsCollision(model1, world1, model, ship2WorldMatrix)) return true;
    return false;
}
这就是检查播放器碰撞,我检查所有模型是否与播放器模型发生碰撞

private bool IsCollision(Model model1, Matrix world1, Model model2, Matrix world2)
{
    for (int meshIndex1 = 0; meshIndex1 < model1.Meshes.Count; meshIndex1++)
    {
        BoundingSphere sphere1 = model1.Meshes[meshIndex1].BoundingSphere;
        sphere1 = sphere1.Transform(world1);

        for (int meshIndex2 = 0; meshIndex2 < model2.Meshes.Count; meshIndex2++)
        {
            BoundingSphere sphere2 = model2.Meshes[meshIndex2].BoundingSphere;
            sphere2 = sphere2.Transform(world2);

            if (sphere1.Intersects(sphere2))
                return true;
        }
    }
    return false;
}
这就是我画模型和做矩阵变换的方法。
您可以根据要求提供更多代码和更多信息。

您应该根据所有三种变换(比例、旋转、平移,按此顺序)构建世界矩阵。如果您在游戏中只使用翻译,那么您的方法应该可以很好地工作。也许你的模特搞砸了。尝试渲染边界球体以查看它们是否真正相交。 这是一个非常好的例子

我不知道如何在中进行相同的转换 分离法。如果有人能帮助我,那就太好了

在应用任何移动或旋转后,通过在更新方法中构建变换矩阵来实现这一点。然后保存构建的矩阵并传递它,以便在碰撞测试方法和绘制方法中使用

Matrix TransformationMatrix;   
void Update()
        {
        TransformationMatrix = Matrix.Create...X(RotationX) * Matrix.Create...Y(RotationY) * transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(loc);
        }
然后

Matrix TransformationMatrix;   
void Update()
        {
        TransformationMatrix = Matrix.Create...X(RotationX) * Matrix.Create...Y(RotationY) * transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(loc);
        }
(IsCollision(TransformationMatrix )
{
sphere.Transform(TransformationMatrix );
} 
DrawModel(TransformationMatrix )
{
 effect.World = TransformationMatrix ;
}