Sign in to follow this  
teslaa66

glRotate problem?

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

	rendermd2(car);	

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.

pseudo:
carMat.RotateMat(yaw,carMat.up);
carMat.RotateMat(pitch,carMat.left);
carMat.RotateMat(roll,carMat.at);

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;
normalize(at);
normalize(left);
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)

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this