2nd approach :)

hi everyone,

i’m not able to solve my problem for 4 days now, i even get more confused

i’ll try to explain it as simple as i can, and i REALLY hope you can help me:

imagine a simple plane made of 4 points ( not really rectangular, but let’s say a table )
i have a toy car standing on this table.
i can drive around on it in any direction i like and to any point i like.
in code,i just have my plane on y == 0,and the car driving around, done by :

glRotatef( (currDirection*180/PI), 0.0, 1.0, 0.0);
//draw the car…

ok,very nice so far…
now, if someone would lift the table on any edge or just on one edge-point(would make not much difference i think), the car would fall off the table ( ok,this is not my problem,thats just a matter of gravity…).
assuming that there’s no gravity , the car would just stand on the table like before on the flat table, and it could drive around just like before.

And exactly this is my problem…
in my code, the “table” is tipped at start,just by taking 2 points and lift them to y == 5 for example, (BTW i cant tip just the car WITH the plane,the whole world is made of many different planes and the car should know how to stand on the planes itself,and the car can drive from table to table,and all of them are tipped different,…).

so what i tried to do:
1.for each table,i define a normal to it(cant figure that out exactly, too…dotproduct,crossproduct?) )
2.look on which table the car is at the moment( could i make this by calcualting the distance from the car to the very next normal,and then say, “aha…normal nr.xxx is next to me,so it’s got to be table nr.xxx” ??)
3.translate and rotate the car this way,that it’s really standing orthogonal to the plane,regardless on which point of the plane?

as i played around with the code,i think i somehow got the car-rotations right,but there was the problem that the car just moved “through” the plane, standing beneath it, instead of driving the plane up or down,coz the height-level of the car never changed… so maybe i have to translate the car to another height too (or will the rotation do that for me??).

for me this is an advanced problem(when i think of some 1stperson shooters,you just need to change the height-level of the player and thats it)

i’m really frustrated right now, my head is full of vectors

hope you can help me soon, coz the whole game will be frozen and i cant go on with it

Lifting one edge by changing the height of the vertices of this edge gives you an implicit rotation. The rotation angle in your case can be calculated with atan(height/baseLength). Lifting means also that the table area would increase and you wouldn’t want to do that with a real table

To get the height of the car during the translation right, translate the opposite edge into one of the base axis (let’s say the z-axis) and rotate everything around the calculated angle (watch out for radians and dregrees).
If the car gets the same translation and rotation, it will drive on top of the table.
Translate everything back to the starting position before drawing.

BUT, your questions sounded as if you need that to drive around in a game like environment with the ground defined as a height field. That’s a different story.

Let’s assume you know the orientation of your car in the world. I like to do that with quaternions. So you have to probe the height at three points (local origin, z, and x points transformed in world coordinates). These points define a plane. Do the atan() stuff for the pitch and roll axis (== x- and z- axis) and change the orientation of your local coordinate system accordingly.
(I don’t do games, so there might be more elegant solutions.)