如何在pybox2d中将主体的角度保持在-pi和pi之间? [英] How do I keep the angle of a body in pybox2d between -pi and pi?

查看:309
本文介绍了如何在pybox2d中将主体的角度保持在-pi和pi之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pybox2d手册中指出:

pybox2d使用弧度表示角度.身体旋转存储在 弧度,并且可能会无限增长.考虑将您的角度归一化 如果角度的大小变得太大(使用 b2Body.SetAngle).

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

但是,当我尝试实现归一化"角度的操作时,出现以下错误:

However, when I try to implement something to 'normalize' the angle I get the following error:

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化.角度是身体的属性:

Looks like the library has been pythonized since those docs were written. angle is a property of Body:

@angle.setter
def angle(self, angle):
    self._xf.angle=angle
    self._transform_updated()

您应该可以通过以下类似的方式简单地对其进行设置:

You should be able to simply set it with something like:

def update_outputs(self):

    # This is necessary to prevent the angle
    # from getting too large or small
    self.body.angle %= 2*pi

这篇关于如何在pybox2d中将主体的角度保持在-pi和pi之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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