1

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.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
fehrlich
  • 2,497
  • 2
  • 26
  • 44

2 Answers2

6

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 );
iforce2d
  • 8,194
  • 3
  • 29
  • 40
  • but GetWorldPoint also "just" calculates the position. Shouldnt it be stored somewhere or does box2d calculates the real position every tick ? And is there an invert function of GetWorldPoint or do i have to implement it by myself like GetBodyPoint(worldPos) – fehrlich Aug 11 '12 at 15:45
  • 1
    The world point is not stored anywhere, for the reasons I explained above. Box2D only calculates the real position when necessary, and it's not necessary every tick. If you check the Box2D manual, you will see there is a GetLocalPoint which works as the inverse of GetWorldPoint. http://www.box2d.org/manual.html – iforce2d Aug 11 '12 at 20:03
1

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

Steven Lu
  • 41,389
  • 58
  • 210
  • 364