Jump to content
  • Advertisement
Sign in to follow this  
nman2084

glmultmatrix question car model

This topic is 2832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.





Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!