Box2D: How to get the position of a static body?

旧巷老猫 提交于 2019-12-01 10:11:14

问题


I have a Box2D world with a mixture of static and dynamic bodies. On collisions, I can only get the positions of the dynamic ones.

Is it possible to get the positions of static objects?

N.b., this is a development of a previous question, Box2D: How to get the position of a sensor?


回答1:


I found a way - in the collision, the center of the AABB will give the position

contact.GetFixtureA().GetAABB().GetCenter()



回答2:


You can get the position vector using the following code:

b2Transform t = body->GetTransform();
b2Vec2 pos = b2Vec2(t.p.x,t.p.y);


来源:https://stackoverflow.com/questions/5666834/box2d-how-to-get-the-position-of-a-static-body

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