Skip to content Skip to sidebar Skip to footer

Box2d Get Shape Points From Rotated Body

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

Solution 1:

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++):

b2Vec2worldPos= body->GetWorldPoint( localPos );

Solution 2:

You get the transform of the body and apply it to each vertex. This transforms local vertex positions to world positions.

Post a Comment for "Box2d Get Shape Points From Rotated Body"