i'm thinking too complicated....

hello,
im confused about mathematics right now,and im sorry this is a bit off-topic…
i guess im just thinking too complicated…

ok,let me explain:

i need to move my object around on a simple terrain. the object is ALWAYS on ground, i.e. the center of the object is like a normal to the ground ( == 90° angle ,hope you understand me )
if i moved the object upwards on a hill, it wouldnt just translate in height and look forward, it should rotate about the “ground-angle” , standing normal to the current terrain-part again…

this means i have to do the following ( i think) :

1.) get the current height-level of the terrain ( exactly the point where the center of my object should be after a glTranslate )

2.) translate the object to this point

3.) somehow rotate the object, so that it’s standing in a 90° angle again…

i know there’s some easy way to do that, else i have to dust off my math-book and calculate some trigonometry and stuff…

so maybe some of you landscapers and terrain builders can help me…

You can use the terrain data for the area around your object to build two vectors. (dX, dY, dZ) north to south, and (dX, dY, dZ) for east to west. If you take the cross-product of these you will get a perpendicular vector that will tell you what direction your object’s “up” should be.
From there you’ll need some trigonometry to find the proper angles for rotation.

hope that helps

-Marrcke

sorry, not really…
i’m very confused

first of all, the planes of the terrain are quite big relative to the object: does this mean if i define a normal to each of the ~100 planes (at program-start,coz they wont change),directly in the middle of the plane,i can use this normal for rotations regardless where my object is sitting on the plane ?
( i read somewhere that 2 vectors are equal when the directions and magnitudes are the same)

and how do i rotate then?
glRotatef( dontknowDegree, v.x, v.y,v.z); ???

if that worked,it would be a bit easier for me,since all i need is finding out on which plane the object is, ~100 vectors and a rotation.

ps: im sorry for posting such a non-OpenGL related question here

Yes, you should be able to define a normal for each of your planes and then just refer to that.

To find the angle you’ll need to use the arc-tangent function (atan() in unix). You feed it the ratio of the legs of a triangle, and it spits out the angle of the hypotenuse.

You’ll need to do two rotates, one around the x axis and one around the z axis (assuming y is “up” )
So… if your normal vector is n[0] (delta-X), n[1] (delta-Y), n[2] (delta-Z), you can do:
atan( n[1]/n[0] )
to get the angle of rotation for the Z axis. and:
atan( n[1]/n[2] )
for the X rotate.

atan returns the angle in radians, so you’ll have to convert to degrees ( * 180/PI ).
Also, you may have to subtract 90 degrees for it to come out right, but that should be apparent if it’s necessary.

> ps: im sorry for posting such a non-OpenGL related question here

The question is really about 3D geometry, which really is related to OpenGL. And besides, you’ve got to get info somewhere.

Maybe I helped this time?

-Marrcke

You should really get out your math book, the math is really useful. It’s easy for me to say because i’m a student and get the this math stuffed down my troat. But you should know all of the vector math at least. How to do crossproducts and dotproducts and so on. It’ll help you a lot.