I'm trying to make my car 'hug' the terrain. I figure I should use the normal vector of the car's current surface(the terrain portion it stands on) in order to determine the orientation of the car. I have tried many different methods and exhausted all of them, and now I am out of ideas. I have a full understanding of vectors, normal, cross product, dot product, so feel free to suggest any idea you may have.
Given my car standing on a surface(triangle) whose normalized normal vector is (vn1, vn2, vn3), how do I arrive at rotations(in degrees) (rx1, ry2, rz3) such that my car stands as it should(in real life) on the surface?
I rotate my car with glRotatef:
glRotatef(rx1,1.0f,0.0f,0.0f); glRotatef(ry2,0.0f,1.0f,0.0f);//not needed(I will specify this myself) glRotatef(rz3,0.0f,0.0f,1.0f);
To give you an idea of how my game is laid out:(redline=surface normal, black line=ray trace to calculate which triangle the car stands on, car=sitting at rotation(0.0f,0.0f,0.0f))
Edited by Shawn619, 18 June 2013 - 07:40 PM.