如何将 pybox2d 中的主体角度保持在 -pi 和 pi 之间?
How do I keep the angle of a body in pybox2d between -pi and pi?
在 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).
但是,当我尝试将某些东西实现到 'normalize' 角度时,出现以下错误:
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 化。 angle 是 属性 的 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
在 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).
但是,当我尝试将某些东西实现到 'normalize' 角度时,出现以下错误:
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 化。 angle 是 属性 的 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