作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 pybox2d manual它指出以下内容:
pybox2d uses radians for angles. The body rotation is stored in radians and may grow unbounded. Consider normalizing the angle of your bodies if the magnitude of the angle becomes too large (use b2Body.SetAngle).
但是,当我尝试实现一些东西来“标准化”角度时,我收到以下错误:
AttributeError: 'b2Body' object has no attribute 'SetAngle'
代码片段:
def update_outputs(self):
# This is necessary to prevent the angle
# from getting too large or small
self.body.SetAngle(self.body.angle % 2*pi)
最佳答案
看起来自从这些文档编写以来,该库已经被 Python 化了。角度是 Body 的一个属性:
@angle.setter
def angle(self, angle):
self._xf.angle=angle
self._transform_updated()
您应该能够简单地设置它,例如:
def update_outputs(self):
# This is necessary to prevent the angle
# from getting too large or small
self.body.angle %= 2*pi
关于python - 如何将 pybox2d 中的物体角度保持在 -pi 和 pi 之间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41419503/
我是一名优秀的程序员,十分优秀!