1
\$\begingroup\$

I have a code, that add a vertex array to a shape, my code is:

PolygonDef shape = new PolygonDef(); 
for (int i=0; i<vertices.size(); i++) {
    Vec2 v = vertices.get(i);
    shape.addVertex(new Vec2(v.x/RATIO,v.y/RATIO));
}        

But its very strange because not working good on any of my polygon creator tool.

So with a triangle, it work good:

    ArrayList<Vec2> vertices = new ArrayList<Vec2>();

    vertices.add(new Vec2(0,-size.height/2));
    vertices.add(new Vec2(size.width/2,size.height/2));
    vertices.add(new Vec2(-size.width/2,size.height/2));

but with a bigger polygon of 50 to 60 vertices it's not working.

How I can create a usable vertex array from a shape? I have a greyscaled image with black and white colors... How can use this shape (image) to define my vertex array good?

And in box2D with the addVertex how I can add this points to make a normal usable polygon? (counter clockwise?)

\$\endgroup\$
1
\$\begingroup\$

(J)Box2D polygons are limited to 8 vertices. When you say it's "not working" I assume you mean you're getting the assert that fires when you pass in arrays that are too large, which should've led you to this yourself.

You will need to triangulate your polygons.

\$\endgroup\$
1
  • \$\begingroup\$ yeah I know that 8 vertices, but I recompiled the original Jbox2D source codes, with the number 64. "public static final int maxPolygonVertices = 64;" and made a new .jar file from it. How can I triangulate my polygons? \$\endgroup\$ – lacas May 4 '11 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.