2
\$\begingroup\$

When you use PolygonShape.set(Vector2[] vertices), is there a limit of vertices of the array which is passed to the method?

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

Calling set on com.badlogic.gdx.physics.box2d.PolygonShape calls set on org.jbox2d.collision.shapes.PolygonShape, which does check the Settings.maxPolygonVertices (see PolygonShape source).

Thus, unless you've set org.jbox2d.common.Settings.maxPolygonVertices to something yourself, the number of vertices needs to be between 3 and 8 (inclusive) as the default is set to

/**
 * The maximum number of vertices on a convex polygon.
 */
public static int maxPolygonVertices = 8;

Be careful about changing that number as it has an impact on performance.

\$\endgroup\$
0
\$\begingroup\$

Method that you mentioned looks like this:

public void set (Vector2[] vertices) {
    Vec2[] v = new org.jbox2d.common.Vec2[vertices.length];
    for (int i = 0; i < v.length; i++) {
        v[i] = new Vec2(vertices[i].x, vertices[i].y);
    }
    shape.set(v, v.length);
}

Other methods in PolygonShape and her parent - Shape don't have the length limits too. I'm 100% sure that PolygonShape has no limit of vertices :_)

\$\endgroup\$

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.