This project is read-only.

Help with creating a triangle...

Mar 10, 2010 at 1:13 AM

Hello,

It would be great if you could help me once again. I implemented a basic ear clipping algorithm but I got an error importing a triangle, a negative area in the ComputeCentroid(ref FixedArray8<Vector2> vs, int count) function in the PolygonShape class.

This code replicates my problem (the error occurs when the shape.set() function is invoked):

 

            Body body;
BodyDef bd; PolygonShape shape; Fixture f;
bd = new BodyDef(); bd.angularDamping = 10.0f; bd.type = BodyType.Dynamic; bd.position = position; body = scene.world.CreateBody(bd); shape = new PolygonShape(); shape.Set(new Vector2[] {new Vector2(4.3f, 5.5f), new Vector2(3.3f, 1.0f), new Vector2(2.1f, 0.0f)}, 3); f = body.CreateFixture(shape, 1.0f); f.SetRestitution(0.1f);

 

What am I doing wrong?

Mar 10, 2010 at 4:25 AM
Edited Mar 10, 2010 at 4:26 AM

From the comment on PolygonShape.Set:

//Copy vertices. This assumes the vertices define a convex polygon.

// It is assumed that the exterior is the the right of each edge.

You have a convex shape but the exterior is to the *left* of one of your edges.

If you use:

shape.Set(new Vector2[] {new Vector2(2.1f, 0.0f),
                                     new Vector2(3.3f, 1.0f),
                                     new Vector2(4.3f, 5.5f)}, 3);

Then it should work fine.

Mar 10, 2010 at 6:01 AM
Edited Mar 10, 2010 at 6:01 AM

Ok, thanks. :)