2017-01-01 102 views
1

pybox2d manual它規定了以下內容:如何保持pybox2d中的身體角度在-pi和pi之間?

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) 
+1

爲什麼這個問題標記C++?它與這種語言有關嗎? –

+0

pybox2d實際上是一個名爲Box2D的C++庫的綁定。 – Bill

+0

我使用pybox2d 2.3.1版本,但2.1.0手冊,所以我不知道它是否過時。 – Bill

回答

2

看起來像自從這些文檔被寫入以後,庫已經被python化了。角度是身體的一個屬性:

@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 
+0

非常感謝! (我嘗試過'self.body.angle = self.body.angle%2 * pi',但這樣做會降低運營商優先級陷阱...)。 – Bill