This the way i took in trying to make the front tire rotate when the car moves forward. I first calculated the center of the car:
Then center of car tire:
in Draw function, i am trying to do multmatrix:
glPushMatrix()
A = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, self.carCenterX - self.xtireCenter, self.carCenterY - self.ytireCenter, self.carCenterZ - self.ztireCenter, 1)
glMultMatrixd(cast(A, POINTER(c_double)))
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)))
draw the tire
C = self.matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, self.xtireCenter - self.carCenterX , self.ytireCenter - self.carCenterY, self.ztireCenter - self.carCenterZ, 1)
glMultMatrixd(cast(C, POINTER(c_double)))
glPopMatrix()
Basically i am translating the center of tire to center of the car, rotate the tire and then translating back where tire was originally.
But this seems to be not working.
glmultmatrix question car model
Sorry cant help you :) hehe I usually just cheat and use the rotation and translation matrices d3d comes with, and I actually suggest to you to use the matrix library in open gl, it would solve a lot of these problems unless you really want to do it the hard way...
The solution is to ensure that the center of the tire is at zero 0 at the moment when the rotational matrix is applied; after rotation the center is to be moved back to its local position. If e.g. the center is located at p with the corresponding translation matrix L, then the effective rotation looks like
L * R * L-1
for column vectors as used by OpenGL. (You may have to consider early rotations, too, dependent on the car model transformations.)
L * R * L-1
for column vectors as used by OpenGL. (You may have to consider early rotations, too, dependent on the car model transformations.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement