Jump to content
  • Advertisement


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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
Share on other sites

multiply the modelmatrix with

| Ux Vx Wx 0 |
| Uy Vy Wy 0 |
| Uz Vz Wz 0 |
| 0 0 0 1 |


V = surface-normal
U = [0,1,0] cross V
W = 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 this post

Link to post
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 this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!