orienting an object to terrain!?
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
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]
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement