0

当我想在 Farseer 中创建多边形时,我总是收到很多错误消息。

“FarseerPhysics.Common.Vertices”不包含“CreatePolygon”的定义“FarseerPhysics.Factories.BodyFactory”不包含“Instance”的定义当前上下文中不存在名称“physicsSimulator”名称“triangleGeomtry”有当前上下文中不存在名称“GeomFactory”当前上下文中不存在名称“physicsSimulator”当前上下文中不存在

怎么了?如何在 Farseer 中创建多边形?

        triangleSprite = Content.Load<Texture2D>("triangle"); // Load the Sprite
        data = new uint[triangleSprite.Width * triangleSprite.Height]; 
        triangleSprite.GetData(data);
        verts = Vertices.CreatePolygon(data, triangleSprite.Width, triangleSprite.Height); 
        polygonOrigin = verts.GetCentroid(); 
        triangleBody = BodyFactory.Instance.CreatePolygonBody(physicsSimulator, verts, 3);
        triangleBody.Position = new Vector2(400, 600);
        triangleGeomtry = GeomFactory.Instance.CreatePolygonGeom(physicsSimulator, triangleBody, verts, 0);
4

1 回答 1

0

Heres how I'm doing it.. Using XNA 4 and Farseer 3.3.1

        //List of vectors defining my custom poly
        Vector2[] vlist = 
            {
                ConvertUnits.ToSimUnits(new Vector2(25,0)) 
                ,ConvertUnits.ToSimUnits(new Vector2(15,25)) 
                ,ConvertUnits.ToSimUnits(new Vector2(-15,25)) 
                ,ConvertUnits.ToSimUnits(new Vector2(-25,0))
                ,ConvertUnits.ToSimUnits(new Vector2(-15,-10))
                ,ConvertUnits.ToSimUnits(new Vector2(15,-10))
            };

        //get farseer 'vertices' from vectors
        Vertices _shapevertices = new Vertices(vlist);

        //feed vertices array to BodyFactory.CreatePolygon to get a new farseer polygonal body
        _newBody = BodyFactory.CreatePolygon(_world, _shapevertices, _stats.Density);

I'm defining the shape myself but I know farseer has tools included that will give you the 'vertices' object based on a sprite if you want to do that.

The texture to polygon section here runs through how to do that.

于 2013-05-20T13:17:10.370 回答