• ### Popular Now

• 13
• 18
• 19
• 27
• 10

#### Archived

This topic is now archived and is closed to further replies.

# orienting an object to terrain!?

This topic is 5667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi I hope this is an easy one. I couldn''t find any documentation on it, so i guess it must be too easy. Anyway, what is the equation to convert a normal vector to a rotation vector? For example, I want to orient a character to a terrain poly so it is perpendicular to the poly normal. Can someone help please? thanks ryan

##### Share on other sites
multiply the modelmatrix with| Ux Vx Wx 0 || Uy Vy Wy 0 || Uz Vz Wz 0 || 0  0  0  1 |whereV = surface-normalU = [0,1,0] cross VW = V cross U|U| = |V| = |W| = 1

now the xz-plane is the plane of your triangle
and the y-axis is parallel to the triangles' normal

don't forget to do a glTranslatef(0,Triangle.Plane.D,0)

[edited by - diego_rodriguez on September 9, 2002 4:19:55 PM]

##### Share on other sites
what diego said works fine, except that the object oriented to terrain ends up with a random orientation on the terrain. i.e. it can pick any vector as forward direction on the plane that uses the surface normals.

so what do we do?

let n=surface normal
then, we let
angle= acos(n dotproduct (0,1,0)/|n|)..which is basically acos(n.y/|n|)..
then we take v=normalized(n crossproduct (0,1,0))...this will be our rotation axis.

Now the trick is to get an axis/angle matrix that will rotate around v by angle. and this is what you transform your model by to get a predictable orientation (an orientation where not only normals are aligned but also forward direction is correct). Oh, and dont forget to translate.

forgive me for any mistakes i might have made..i am making this as i go along (although i have written working code for this before).