Box2d get Shape Points from rotated body

本秂侑毒 提交于 2019-12-25 05:22:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!