Box2d从旋转的身体获取形状点 [英] Box2d get Shape Points from rotated body

查看:130
本文介绍了Box2d从旋转的身体获取形状点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻我有点困惑。如果我从Box2d的固定装置中获取形状,它将向我返回与物体的位置和角度有关的点(带有-> getVertices)。但是不应该在某个地方存储该形状的实际点的数据吗?

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 ?

要清理一下:我有一个多边形,它的形状是旋转的。现在,我想获取所有Polygone的实际点。我可以使用一种方法吗?还是我必须计算转换,对我来说就没有多大意义了。

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.

我使用box2dweb for javascript。

Im using box2dweb for javascript.

推荐答案

是的,您需要使用主体变换来计算当前位置。这些点存储在本地(身体)坐标中,因此移动身体(一个点)不需要更新固定装置的所有许多点。考虑一个在空白区域中移动的物体,没有计算碰撞...物理引擎根本不需要固定点。如果将点存储在世界坐标中,这些点也将很快失去精度。

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.

如果要绘制固定装置,则可以像这样获得这些点的当前世界位置( C ++):

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 );

这篇关于Box2d从旋转的身体获取形状点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆