问题
Im 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 shouldnt be there somewhere the stored data for the actual points of the shape ?
To clear things up: I have a polygon Shape wich is rotated. And now i want to get all the Points of the Polygone where they are actual are. Is there a method i can use ? or do i have to calculate the transformation, wich wouldnt make much sense to me.
Im using box2dweb for javascript.
回答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++):
b2Vec2 worldPos = body->GetWorldPoint( localPos );
回答2:
You get the transform of the body and apply it to each vertex. This transforms local vertex positions to world positions.
来源:https://stackoverflow.com/questions/11900380/box2d-get-shape-points-from-rotated-body