#### Archived

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

# orienting an object to terrain!?

This topic is 5879 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).

##### Share on other sites
Thanks very much!

1. 1
2. 2
3. 3
4. 4
Rutin
19
5. 5

• 14
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632927
• Total Posts
3009254
• ### Who's Online (See full list)

There are no registered users currently online

×