Xna Farseer创建矩形宽度高度

Xna Farseer创建矩形宽度高度,xna,height,width,box2d,farseer,Xna,Height,Width,Box2d,Farseer,基于Box2D的farseerxna4.0c#物理引擎 如果我使用BodyFactory.CreateRectangle(世界,w,h,密度,新向量2(x,y));方法来创建实体 我怎样才能从身体得到宽度和高度 目前我正在保存宽度和高度,但我想知道它是否可以从夹具或形状或其他东西中检索。我做了一些尝试,但没有成功。这将为我创建的每个实体节省两个浮动 谢谢您的帮助。我会在开头说我从来没有使用过Farseer,但是看看类定义,似乎没有简单的方法可以得到您想要的。如果查看BodyFactory.Cre

基于Box2D的farseerxna4.0c#物理引擎

如果我使用BodyFactory.CreateRectangle(世界,w,h,密度,新向量2(x,y));方法来创建实体

我怎样才能从身体得到宽度和高度

目前我正在保存宽度和高度,但我想知道它是否可以从夹具或形状或其他东西中检索。我做了一些尝试,但没有成功。这将为我创建的每个实体节省两个浮动


谢谢您的帮助。

我会在开头说我从来没有使用过Farseer,但是看看类定义,似乎没有简单的方法可以得到您想要的。如果查看BodyFactory.CreateRectangle方法,它不会直接存储高度或宽度值:

    public static Body CreateRectangle(World world, float width, float height, float density, Vector2 position,
                                       object userData)
    {
        if (width <= 0)
            throw new ArgumentOutOfRangeException("width", "Width must be more than 0 meters");

        if (height <= 0)
            throw new ArgumentOutOfRangeException("height", "Height must be more than 0 meters");

        Body newBody = CreateBody(world, position);
        Vertices rectangleVertices = PolygonTools.CreateRectangle(width / 2, height / 2);
        PolygonShape rectangleShape = new PolygonShape(rectangleVertices, density);
        newBody.CreateFixture(rectangleShape, userData);

        return newBody;
    }
公共静态实体CreateRectangle(世界、浮动宽度、浮动高度、浮动密度、矢量2位置、,
对象(用户数据)
{
如果(宽度)