更改 box2d 的旋转中心
我有一个 b2PolygonShape 主体并对其施加力。
_recbody->ApplyForce( b2Vec2(6.0, -6.0), _recbody->GetWorldCenter() );
我想将身体的旋转中心更改为更靠近身体的前方。 因此,applyForce 和碰撞使身体不会在中心转动,而是更多地在前面转动。
I have a b2PolygonShape body and apply a force to it.
_recbody->ApplyForce( b2Vec2(6.0, -6.0), _recbody->GetWorldCenter() );
I want to change the centre of rotation of the body to be more in the front of the body.
So that applyForce and also collisions make the body not turn in the centre but more in the front.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一篇相当老的帖子,但是从第一个答案构建,您应该使用 Set 并定义盒子的顶点,而不是使用 SetAsBox()。我发现 SetAtBox 使用宽度和高度从中心向所有 4 个边创建,因此无论您做什么,重心都将是形状的中心,但另一方面,如果您使用 Set,即使你只是画一个盒子,你可以将它限制在一侧。
例如:
这将形成一个重心向左上角移动的形状,因为我们只在右侧向下绘制多边形(没有超过 [0,0] 点)。
I know this is quite an old post, but building from the first answer, instead of using SetAsBox(), you should use Set and define the vertices of the box. I found that SetAtBox creates from the center, towards all 4 sides using width and height, so no matter what you do, the center of gravity will be the center of the shape, but on the other hand, if you use Set, even if you're just drawing a box, you can limit it to one side only.
For example:
This will make a shape with the center of gravity shifted towards the upper left corner because we only drew the polygon on the right side going down (Nothing past the [0,0] point).
在此论坛中找到此内容
“无论您在何处创建实际形状,物体的质心都将从 bodyDef.position.Set() 坐标设置。如果您将 boxDef.SetAsBox() 坐标偏移所需的量,则应该得到达到你想要的效果。”
Found this in this forum
"The center of mass of a body will be set from the bodyDef.position.Set() coordinates, regardless of where you create the actual shape. If you offset the boxDef.SetAsBox() coordinates by the amount required, this should get the effect you're after."