IIRC, this is similar to the transforms done in the billboards. I
recently needed something similar to what you describe.
First, I'll try to refer to the "direction" and "up" vectors, either the
"old" or "new". You're seeking a transform which takes you FROM the "old
direction and up" TO the "new direction and up".
The quaternion you require is the product of two quaternions.
One quaternion, call it qD, represents a rotation FROM the "old
direction" vector to the "new direction" vector. The second quaternion
takes care of the fact that qD does NOT necessarily rotate the "up"
vector correctly.
Vec3f direc_old, direc_new; // assume these get their values in
Vec3f up_old, up_new; // your code somewhere
...
...
Quaternion qD(direc_old, direc_new);
// Now apply this transform to the "old up" vector
Vec3f up_temp;
qD.multVec(up_old, up_temp);
// Make a second quaternion which rotates up_temp into the "new up"
vector.
Quaternion qU(up_temp, up_new);
// The result is the product of these quaternions
Quaternion qResult;
qResult = qU;
qResult.mult(qD);
Can't say that this code will compile ;). I've paraphrased my own
algorithm.... which does something similar but not quite the same. I
must say that exercise really taught me how to use quaternions!
It took me a while to convince myself this was right. Think of the
qResult as the product of two transforms: first you transform the
direction/pointing vector, then you apply the "up" transformation. The
"up" transformation doesn't affect the first transform because it is
really a rotation around the direction vector!
Hope this helps!
Dan
--
Daniel J. Sperka, Ph. D.
UC Davis Center for Neuroscience
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users