Hmmmm..how about just doing this? At least that's why our new AI guy, Scott
Martin, added to our math libraries today:
euler.x = 0; // roll
euler.y = acosf(normal.z); // pitch
euler.z = atanf(normal.y, normal.x); // yaw
???
If you are going to be working in euler coordinates as a generalized
representation that is. And going from euler to quat is easy enough.
John
Original Message
From: Chris Butcher (BUNGIE) [mailto:cbutcher@...]
Sent: Wednesday, February 27, 2002 6:00 PM
To: gdalgorithmslist@...
Subject: RE: [Algorithms] Oriention from Normal
> Original Message
> From: Ratcliff, John [mailto:jratcliff@...]
>
> What I need to be able to do is take the result of an impact event and
then
> create a generic orientation, either quaternion or euler, I don't care
> which, that can be passed on to other routines like for generating decals
or
> oriented effects.
>
If I understand you correctly, you're looking for a quaternion that will
rotate a Zaxisaligned object to face along a given vector.
Take the cross product of this vector with +Z to get a rotation axis, and
the dot product of this vector with +Z (i.e. the Z component of the vector)
to give the cosine of the angle of the rotation.
That gives you an axis a and a rotation magnitude cos(theta). Use
trigonometric identities to generate cos(theta/2) and sin(theta/2). You can
build the quaternion directly as:
q.w = cos(theta/2)
q.v = sin(theta/2)*normalize(a)
The only real problem with this is that there's no control over the 'roll'
component of the rotation. If you wanted to modify that (e.g. by randomizing
it) you could premultiply by a random quaternion that is a rotation about
+Z.

Chris Butcher
AI Engineer  Halo
Bungie Studios
butcher@...
_______________________________________________
GDAlgorithmslist mailing list
GDAlgorithmslist@...
https://lists.sourceforge.net/lists/listinfo/gdalgorithmslist
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_ida88
