Reputation: 338
I have a polygon shape in Box2D. The shape is a Triangle, wich I expect to have 3 vertices. In fact all shapes that I create will output 8 vertices. Why is this? And if I output the vertex count, that is always the correct amount. I dont want to render unnecessary lines, tough I would like to get the vertex data from the shape.
@Override
public void setShape(Vec2[] vector) {
// TODO Auto-generated method stub
super.setShape(vector);
//A NEW SHAPE
shape = new PolygonShape();
//THE TRIANGLES VECTORS
Vec2[] vec = new Vec2[3];
vec[0] = new Vec2(10, 0);
vec[1] = new Vec2(0, 10);
vec[2] = new Vec2(0, 0);
//SET THE VERTICES
shape.set(vec, vec.length);
}
@Override
public void render() {
// TODO Auto-generated method stub
super.render();
//GET THE VERTICES
Vec2[] vector = shape.m_vertices;
System.out.print("\n" + "Vertices: " + vector.length);
}
will always output 8. Why?
Upvotes: 0
Views: 1821
Reputation: 43427
The polygon is represented in the original c++ code with a fixed number of 8 vertices, possibly for performance reasons. you are seeing the consequence of this.
The actual vertex count is tracked, so just use that for rendering.
Upvotes: 1