CreatePolygon From Texture

Topics: Developer Forum, User Forum
Nov 7, 2010 at 9:01 AM
Edited Nov 7, 2010 at 9:03 AM

Hi Farseer,

I've just started making the transition from 2.1.3 to 3.0. It's been a long night. Anyways, after playing around with creating fixtures from textures I ran into some issues. Mainly, this one:

public static List<Vertices> CreatePolygon(uint[] data, int width, int height, float hullTolerance,byte alphaTolerance, bool multiPartDetection, bool holeDetection) {

return TextureConverter.CreateVertices(data, width, height, hullTolerance, alphaTolerance, holeDetection, multiPartDetection);

}

So, I'm not sure if I'm seeing things but it looks like these parameters need to be switched. Maybe this has changed in a patch? Thought I'd give you a heads up.

 

Nov 7, 2010 at 9:46 AM
Edited Nov 7, 2010 at 9:05 AM

Oh I might as well mention that once I fixed this issue I ran into something else that was interesting. It seems that the 3.0 CreateVerticies method mentioned above is returning one addition vertex than its 2.1.3 counterpart (exact same parameters and texture data). I don't know enough about the algorithm, to know if this is a problem. One other thing I thought I might add. In 2.1.3 I am able to create a polygon from one of the vertices in the list using this line _body = BodyFactory.Instance.CreatePolygonBody(Engine.activeScreen.PhysicsSimulator, polygon, mass); - no problem. However, in 3.0 using what I assume is its counterpart:


            FarseerPhysics.Collision.Shapes.PolygonShape polygon = new FarseerPhysics.Collision.Shapes.PolygonShape(vertices);   
_body = BodyFactory.CreateBody(World);
_body.BodyType = BodyType.Dynamic;
_geom = _body.CreateFixture(polygon, mass);

Gives me a debug assert error. The last call being at PolygonShape.cs line 88 then PolygonShape line 50.  I've managed to work around it using this,

	    _body = BodyFactory.CreateBody(World);         
var triangles = FarseerPhysics.Common.Decomposition.EarclipDecomposer.ConvexPartition(polygon);
foreach (var triangle in triangles) {
var shape = new FarseerPhysics.Collision.Shapes.PolygonShape(triangle);
_body.CreateFixture(shape);
}

Pretty new here, so I really have no clue what's going on in these algorithms. But, I do know that there are now some holes the geometry that were not there in 2.1.3. Let me know what you think.

Edit: For some reason the posts were out of order?? I must be dreaming