如何使 b2body 多边形绕其质心旋转?
这应该不难,但我无法让它发挥作用。
基本上,用户通过在屏幕上绘制线条来创建 b2body 多边形。我希望 b2body 旋转(或绕其质心旋转)。我可以对我制作的所有其他形状执行此操作,因为它们的位置已经设置为中心。但是当我制作 b2PolygonShape 时,位置设置为 0,0。因为用户正在制作形状,所以我无法确定它的质心在哪里。即使我确实知道,我似乎也无法围绕它旋转。我尝试了ApplyAngularVelocity,但对象绕原点(0,0)旋转。我尝试了ApplyTorque,但该对象完全没有执行任何操作。它就坐在那里。请帮忙。
This shouldn't be hard but I can't get it to work.
Basically, the user creates a b2body polygon by making lines on the screen. I want that b2body to spin (or rotate around it's mass center). I can do this with all the other shapes I make because their position is already set to their center. But when I make a b2PolygonShape the position is set to 0,0. Because the user is making the shape I can't be sure where it's mass center is. And even if I did know I can't seem to rotate around it. I tried ApplyAngularVelocity but the object spun around the origin (0,0). I tried ApplyTorque and the object did absolutely nothing. It just sat there. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ApplyTorque 或 ApplyAngularImpulse 应该可以做到。检查主体是否具有非零转动惯量且未设置为固定旋转。
可以使用 GetWorldCenter() 找到质心。
ApplyTorque or ApplyAngularImpulse should do it. Check that the body has a non-zero rotational inertia and is not set to be fixedRotation.
The center of mass can be found with GetWorldCenter().