g'day guys!

i saw someone mention quaternions somewhere on the a6 forums, and i was getting really frustrated with some rotational stuff in my project (bloody Euler angles ) so i went on wikipedia and some other online resources and taught myself the theory behind quaternions, which is ridiculously easy if u know a little about complex numbers, and possibly even if you don't.
anyway, here is the fruit of my research! i decided anyone who wants to use quaternions would have figured it out one way or another, and considering most of these functions almost directly quote online sources i have no reason to keep this to myself. enjoy:
quaternions.c

a brief description for the contents:
QUATERNION
a quaternion (struct) containing w, x, y and z floats. there is no globally used convention but in this case "w" is the scalar part and "x,y,z" the axis.

quat_multiply(QUATERNION* end_result,QUATERNION* a,QUATERNION* b)
sets the quaternion "end_result" to the product of quaternions "a" and "b" (in that order -- remember quaternions are not commutative). this is effectively rotating "b" by "a", around the axis represented in "a". this is the main reason i am using quaternions.

quat_for_ang(QUATERNION* q,ANGLE* a)
meant to set the change the contents of "q" to represent the euler angle "a". untested, so please let me know if it doesn't work and point me in the right direction if you know what should be done. -- actually, doesn't work. everything else is tested quite reasonably i think, so they should work. i'll get back to you when i've had a look at this but i haven't found a need for quat_for_ang yet.

quaternize(var a,VECTOR* v,QUATERNION* q)
i don't know if quaternize is a real word, but this will set the contents of quaternion "q" to represent the rotation "a" degrees about the axis "v".

quat_to_unit(QUATERNION* q)
gives "q" a magnitude of "1". for a multiplication to accurately represent a quaternion rotation each quaternion needs a magnitude of 1. this does that for you.

quat_set(QUATERNION* q,QUATERNION* u)
sets quaternion "q" to equal "u".

just put #include "quaternions.c" after your default and acknex includes, and then these functions and quaternions should work beautifully

i hope at least a few of you get some use out of these they're good for rotating around any axis you want. if you find and confirm any errors, please notify me either by pm or in this thread!
i haven't been able to test it for super long but it seems to be working really well from what i can see!

back to my design & technology project.

julz


Formerly known as JulzMighty.
I made KarBOOM!