Jump to content
  • Advertisement
Sign in to follow this  

glRotate problem?

This topic is 3694 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

basically i have a terrain in my scene that uneven and ive imported an md2 car. To make it seem asthough the car is stuck to the ground I have taken a point at the front, back, right and left side of the car then tested their Y position against the terrain and then with a little bit of maths found the angle at which the car needs to be rotated to appear as though it is held to the floor with gravity. Problem is that i have to rotate my car's nose up and down so it looks ok when travelling up a hill (which works) annnnnnd tilt left and right if the ground slants to one side (which works) but.............. both together doesnt work as applies one rotate to the car and then with the car in different position it applies the second rotation making the car appear incorrectly.

	glRotatef(findGradient2(),1,0,0); //Rotates the car up and down
	glRotatef(findGradient(),0,1,0);  //rotates the car to the left or right


Its a simple problem and im sure im overlooking a simople solution? Many thanks James

Share this post

Link to post
Share on other sites
Instead of rotating around the global up and left axis you should rotate around your car's local axis.


But, you also have the ground you want. so you could just take your tested points, and make a new car matrix

at = front - back;
left = leftside - rightside;
up = at cross left;

Share this post

Link to post
Share on other sites
i like your first idea but i understnad how id implement it as i dont know how i can access the local coordinate system for the car?

i read in the points from the file and then use a trianglestrip polygon to draw it to the scene. At what point to i get to change the angle? sorry im fairly new to this.

As for the second i understand what you mean about creating a new matrix but wouldnt that just give me the same problem because applying a second rotation would rotate an already rotated object?

again i apologise for the n00b questions i am a beginner.

Many thanks

Share this post

Link to post
Share on other sites
Ah sorry. I kinda assumed there was atleast a little background. poor me.
OpenGL doesn't let you at the transformed state of an object. So it is easier/better to maintain the transformation you want outside of opengl (useful for other other things too like collision detection)

my second solution, using only 3d vector math, would allow you to build the final matrix after all rotations you wanted.
my first solution still involves you finding angles and such, then doing your own matrix math to make a matrix (allowing you to give some control over how angles change).
Both involve learning some basic linear algebra, or finding one of the many different vector math classes people have written(sorry i dont have any links, but you can search gamedev for many a thread on it)

lot of good links / stuff to read in this thread:
here on gamedev

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!