Farseer / XNA断言失败,由相机矩阵修改的身体的Vector2位置

时间:2011-08-29 20:17:32

标签: matrix xna camera assertions farseer

我创建了一个带矩阵的相机,用它来移动2D中的视点。基本上我从这个模板开始: http://torshall.se/?p=272

我的课程中还有一个用鼠标生成盒子的简单代码:

public void CreateBodies()
    {
        mouse = Mouse.GetState();

        if (mouse.RightButton == ButtonState.Pressed)
        {
            Bodies += 1;
            if (Bodies >= MaxBodies)
                Bodies = 0;

            rectBody[Bodies] = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(rectangle.Width), ConvertUnits.ToSimUnits(rectangle.Height), 1);
            rectBody[Bodies].Position = ConvertUnits.ToSimUnits(mouse.X, mouse.Y);
            rectBody[Bodies].BodyType = BodyType.Dynamic;
        }
    }

这个工作非常好但是当我移动''相机'时,鼠标没有在正确的位置发生变化,我在game1.cs和我的方法中做了一点修改以获得世界的协调。我的老鼠:

mouse = Mouse.GetState();
        Matrix inverse = Matrix.Invert(camera.transform);
        Vector2 mousePos = Vector2.Transform(new Vector2(mouse.X, mouse.Y), inverse);

        TE.CreateBodies(mousePos);


public void CreateBodies(Vector2 mousePosition)
    {
        mouse = Mouse.GetState();
        MousePosition = mousePosition;

        if (mouse.RightButton == ButtonState.Pressed)
        {
            Bodies += 1;

            if (Bodies >= MaxBodies)
            {
                Bodies = 0;
            }

            rectBody[Bodies] = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(rectangle.Width), ConvertUnits.ToSimUnits(rectangle.Height), 1);
            rectBody[Bodies].BodyType = BodyType.Dynamic;

            rectBody[Bodies].Position = ConvertUnits.ToSimUnits(MousePosition);


        }

    }

现在这应该给我世界的坐标。我的鼠标,但我有一个问题,当我运行程序并点击屏幕上的某个地方创建一个框我收到此错误:

http://img68.xooimage.com/files/6/a/4/bob-2c526f4.png

发生了什么事? :/

编辑:

这是在body.cs的第439行:

Debug.Assert(!float.IsNaN(value.X) && !float.IsNaN(value.Y));

0 个答案:

没有答案