I'm not quite sure how I can make use of GetVertices() in b2PolygonShape for what I intend to do... but as I understand it, I need to use it. Basically, I want to collect the positions of the vertices in the polygon. My reason for this is so that I can put them into another structure which I use for rendering. I use this structure to make multiple shapes with the same body appear as a single shape. How do I collect the positions of my polygon's vertices? I'm probably undereducated, which is why I cant figure out GetVertices().
Collecting polygon vertecies?
General DiscussionSomething like this... For more info see the documentation for b2PolygonShape and b2CircleShape...
Code:
void DrawBody(b2Body& body, int color) {
b2Shape* shape = body.GetShapeList();
while(shape) {
if(shape->GetType() == e_polygonShape) {
b2PolygonShape* polyShape = (b2PolygonShape*)shape;
// code to draw the polygon
} else if(shape->GetType() == e_circleShape) {
b2CircleShape* circleShape = (b2CircleShape*)shape;
// code to draw the circle
}
}
}
b2Shape* shape = body.GetShapeList();
while(shape) {
if(shape->GetType() == e_polygonShape) {
b2PolygonShape* polyShape = (b2PolygonShape*)shape;
// code to draw the polygon
} else if(shape->GetType() == e_circleShape) {
b2CircleShape* circleShape = (b2CircleShape*)shape;
// code to draw the circle
}
}
}
You can also see an example of this in b2World::DrawShape.
Original thread: https://box2d.org/forum/viewtopic.php?t=847