Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在汽车中旋转轮胎(打开gl)_Python_Opengl - Fatal编程技术网

Python 在汽车中旋转轮胎(打开gl)

Python 在汽车中旋转轮胎(打开gl),python,opengl,Python,Opengl,根据我之前得到的同一个问题的答案,我修改了我的代码,因为我必须使用glmultmatrix。但这是行不通的。这是代码,我要做的是把轮胎的中心翻译成汽车的中心,旋转轮胎,然后翻译回来。但它不会将轮胎放回其应放的位置: if (name == 'Front Driver tire' ) & (self.fFlag == "true"): self.getCenterTireRim() bodyFace = self.mini.group(n

根据我之前得到的同一个问题的答案,我修改了我的代码,因为我必须使用glmultmatrix。但这是行不通的。这是代码,我要做的是把轮胎的中心翻译成汽车的中心,旋转轮胎,然后翻译回来。但它不会将轮胎放回其应放的位置:

if (name == 'Front Driver tire' ) & (self.fFlag == "true"):

            self.getCenterTireRim()

            bodyFace = self.mini.group(name)

            glPushMatrix()

            x = self.carCenterX - self.xtFront
            y = self.carCenterY - self.ytFront
            z = self.carCenterZ - self.ztFront

            A = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1)
            glMultMatrixd(cast(A, POINTER(c_double)))

            #print self.carCenterX, self.carCenterY, self.carCenterZ
            #print self.xtFront, self.ytFront, self.ztFront

            B = self.matrix(1,0,0,0,0, math.cos(math.radians(self.angle1 + 45)), math.sin(math.radians(self.angle1 + 45)), 0, 0, -math.sin(math.radians(self.angle1 + 45)), math.cos(math.radians(self.angle1 + 45)), 0, 0,0,0, 1)
            glMultMatrixd(cast(B, POINTER(c_double)))


            for face in bodyFace:
                if len(face) == 3:
                    glBegin(GL_TRIANGLES) 
                elif len(face) == 4:
                    glBegin(GL_QUADS) 
                else: 
                    glBegin(GL_POLYGON)
                for i in face:
                    glNormal3f(*self.mini.normal(i))
                    glVertex3f(*self.mini.vertex(i))
                glEnd()

            C = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x - self.carCenterX   , y - self.carCenterY,   z - self.carCenterZ, 1)
            glMultMatrixd(cast(C, POINTER(c_double)))


            glPopMatrix()







        elif (name == 'Front Driver tire rim') & (self.fFlag == "true"):
            bodyFace = self.mini.group(name)

            glPushMatrix()

            self.getCenterTireRim()

            bodyFace = self.mini.group(name)


            A1 = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, self.carCenterX - self.xrFront, self.carCenterY - self.yrFront, self.carCenterZ - self.zrFront, 1)
            glMultMatrixd(cast(A1, POINTER(c_double)))

            #print self.carCenterX, self.carCenterY, self.carCenterZ
            #print self.xrFront, self.yrFront, self.zrFront

            B1 = self.matrix(1,0,0,0,0, math.cos(math.radians(self.angle1 + 45)), math.sin(math.radians(self.angle1 + 45)), 0, 0, -math.sin(math.radians(self.angle1 + 45)), math.cos(math.radians(self.angle1 + 45)), 0, 0, 0, 0, 1)
            glMultMatrixd(cast(B1, POINTER(c_double)))


            for face in bodyFace:
                if len(face) == 3:
                    glBegin(GL_TRIANGLES) 
                elif len(face) == 4:
                    glBegin(GL_QUADS) 
                else: 
                    glBegin(GL_POLYGON)
                for i in face:
                    glNormal3f(*self.mini.normal(i))
                    glVertex3f(*self.mini.vertex(i))
                glEnd()

            C1 = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, self.xrFront - self.carCenterX   , self.yrFront - self.carCenterY,   self.zrFront - self.carCenterZ, 1)
            glMultMatrixd(cast(C1, POINTER(c_double)))

            glPopMatrix() 

我很确定这是因为这条线

C = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x - self.carCenterX   , y - self.carCenterY,   z - self.carCenterZ, 1)
应该是

C = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -x   , -y,   -z, 1)
我不知道你为什么要使用
x-self.carCenterX
等等。你翻译了一个方向(x,y,z),所以只需返回相反的方向,
-(x,y,z)=(-x,-y,-z)


我希望这会有帮助。

我很确定这是因为这条线

C = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x - self.carCenterX   , y - self.carCenterY,   z - self.carCenterZ, 1)
应该是

C = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -x   , -y,   -z, 1)
我不知道你为什么要使用
x-self.carCenterX
等等。你翻译了一个方向(x,y,z),所以只需返回相反的方向,
-(x,y,z)=(-x,-y,-z)

我希望这有帮助