我试图在 X 轴上旋转一个对象,但我不明白。
我有一个 Object 3D 类,它是:
class Object3D():
implements( IRenderizable )
def __init__(self, parameters={} ):
self.parameters = parameters
self.ID= Engine().addObject3D()
self.parent = None
self.childrens =[]
self.position = (parameters.get('POSITION') is None ) is True and Vector4() or parameters.get('POSITION')
self.rotation = (parameters.get('ROTATION') is None ) is True and Quaternion() or parameters.get('ROTATION')
self.direction = Vector4()
self.scale = Vector3(1,1,1)
self.matrix = Matrix4()
self.matrixLocal = Matrix4()
self.matrixWorld = Matrix4()
self.matrixRotationWorld = Matrix4()
self.up = Vector3(0,1,0 )
self.parameters =parameters
self.rotationAngle= 10.
self.currentMatrix = None
self.initCurrentMatrix()
def initCurrentMatrix(self):
glPushMatrix()
glLoadIdentity()
self.currentMatrix = glGetDoublev(GL_MODELVIEW_MATRIX)
glPopMatrix()
return
def setID(self, Id ):
self.ID = Id
def moveTo( self, x,y,z ):
v=Vector4(x,y,z)
#self.position.addSelf( self.rotation.rotateVector(v) )
self.position.addSelf( v )
glPushMatrix()
glLoadIdentity()
glTranslatef( float(self.position.x),float(self.position.y),float(self.position.z) )
self.currentMatrix = glGetDoublev(GL_MODELVIEW_MATRIX)
glPopMatrix()
return self
def render(self):
pass
在这段代码中,您将看到如何实现旋转:
def rotateX(self, angle=2 ):
glPushMatrix()
glRotated( angle, 0,1,0)
glPopMatrix()
return self
当 Vector4, Vector3 , Quaternion, Matrix4 是我自己的类时。
这是我的错吗?以及如何进行轮换?