Box2d get Shape Points from rotated body Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Box2d get Shape Points from rotated body without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m a little confused at the moment. If I get my Shape from my fixture in Box2d it returns me the points (with ->getVertices) related to the position of the body and angle. But shouldn’t be there somewhere the stored data for the actual points of the shape?

To clear things up: I have a polygon Shape which is rotated. And now I want to get all the Points of the Polygon where they are actual are. Is there a method I can use? or do I have to calculate the transformation, which wouldn’t make much sense to me.

I’m using box2dweb for JavaScript.


Yes, you’ll need to calculate the current position using the body transformation. The points are stored in local (body) coordinates so that moving the body (one point) does not require all the many points of the fixtures to be updated. Consider a body moving through an empty area, with no collisions being calculated… the physics engine does not need the fixture points at all. The points would also quickly lose precision if you stored them in world coordinates.

If you want to draw the fixture you can get the current world position of the points like this (C++):

b2Vec2 worldPos = body->GetWorldPoint( localPos );
We are here to answer your question about Box2d get Shape Points from rotated body - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji