Get vertice list of a polygon shape body

允我心安 提交于 2019-12-04 18:43:18

Based on @James Webster's code:

Array<Vector2> verts = new Array<Vector2>();
Fixture f = body.getFixtureList().get(0);
PolygonShape s = f.shape;

// this is needed to temporarily keep the vertex, getVertex is a void method
Vector2 tmp = new Vector2();
for (int i = 0; i < s.getVertexCount(); i++) {
    // fill tmp with the vertex
    s.getVertex(i, tmp));
    verts.add(new Vector2(tmp));
}

I haven't worked with LibGDX, but I have worked with Box2D and looking at the API, I'd suggest:

//Assuming only 1 fixture per body and a polygon shape


Array<Vector2>verts = new Array<Vector2>();
Fixture f = body.getFixtureList().get(0);
PolygonShape s = f.shape;
for (int i = 0; i < s.getVertexCount(); i++)
{
    verts.add(s.getVertex(i, /*I couldn't figure out what this param is supposed to be*/));
}

This was typed without an IDE, watch out for blatant errors! I haven't done Java in a long time either.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!