views:

61

answers:

1

Based on the answer i got for the same question earlier, i changed my code, as per the homework i had to use glmultmatrix. But this is not working. Here is the code, what i am doing is that i translate the center of tire to the center of car, rotate the tire, and then translate back. But it is not placing back the tire where it should be:

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() 
+1  A: 

I'm pretty sure that it is because this line

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)

should be

C = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -x   , -y,   -z, 1)

I'm not sure why you were using x - self.carCenterX and so forth. You translated one way (x,y,z) so just go back the opposite direction, -(x,y,z) = (-x,-y,-z)

I hope that helps.

Justin Peel