Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?)

share|improve this question

1 Answer 1

(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.

share|improve this answer
    
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? –  lacas May 4 '11 at 9:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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