Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I don't have any code for this since I don't know how I am meant to do this.

I have a car and I am able to move it around on a flat plane and I have that working correctly. However, I want it to also be able to move up hills accurately. So that when I drive up a hill the front wheels start going up first and then the back wheels follow like a normal car would. So far all I have managed to be able to do is when one point of the car reaches an incline the whole car moves to that new y value instead of just the section of the car that is supposed to. Does it require some kind of translation and rotation applying to it so that it reacts correctly?

share|improve this question

closed as unclear what you're asking by MichaelT, durron597, Snowman, Kilian Foth, Ixrec Oct 7 '15 at 20:43

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

When you go up a hill, does your car rotate? To do this realistically you will need to calculate separate positions of the front and rear tires and draw the car according to those positions. – kevin cline Nov 27 '12 at 17:03
it rotates about the axis when I use the arrow keys. Like when I press forward it moves forward and when I press left it turns left. Is there a simple kind of way to look at the bottom of the 4 wheels and the car then translate itself so that all 4 wheels stay touching the ground when they would be at different heights? – user1324894 Nov 27 '12 at 17:09
It's simple to some, not as simple to others. If you can do basic geometric calculations and understand the GL transformation matrix, it's simple. – kevin cline Nov 27 '12 at 17:37
I have managed to do it so that the car moves forward in the direction it's facing is that some kind of start to understanding it? Would it be a rotation of the car with respect to the height of the incline that it is on? – user1324894 Nov 27 '12 at 17:46
In an arbitrary landscape, the position of the car is fixed when there are three wheels on the ground. So you cannot guarantee or expect that the is the fourth wheel is on the ground, too (at least, when the four wheels have a fixed position relative to your car object and you model does not contain something like dampers). – Doc Brown Nov 27 '12 at 22:12

You will need to keep track of the position of the front and rear of the car separately based on the terrain under the car. Then calculate the transformation matrix directly from the position of the center front and center rear of the car. Compute orthonormal vectors where one is aligned with the direction of the car, a second is horizontal, and the third is the cross product of the others. These vectors will form the GL transformation matrix.

Calculating rotation and pitch angles is an unnecessary excursion into spherical coordinates.

It may be even simpler to use a physics library.

share|improve this answer
I still don't understand fully. What are orthonormal vectors and how do I calculate them so that they will become a transformation matrix so the car can move across the bumpy terrain? – user1324894 Nov 27 '12 at 18:24
You will also need to check if the plane of the bottom of the car is intersecting the hill. A car which drives into the center of a cone a 5 foot tall cone with a 1 foot diameter will crash, rather than climbing it. – Brian Nov 27 '12 at 21:13
@user1324894: I'm afraid in that case you will need to do some reading on 3D graphics. Or find a library that is higher-level than GL. – kevin cline Nov 27 '12 at 23:55
@Brian: physically that's true, but collision detection may not be needed. – kevin cline Nov 27 '12 at 23:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.