I'm not at home, so here's a quick answer off the top of my head. (In other words, it probably doesn't work so verify it)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public final Vect3f rot(Vect3f v) { float k0 = w*w - 0.5f; float k1; float rx,ry,rz;
k1 = v.x*x; k1 += v.y*y; k1 += v.z*z;
rx = v.x*k0 + x*k1; ry = v.y*k0 + y*k1; rz = v.z*k0 + z*k1;
rx += w*(y*v.z-z*v.y); ry += w*(z*v.x-x*v.z); rz += w*(x*v.y-y*v.x);
rx += rx; ry += ry; rz += rz;
return new Vect3f(rx,ry,rz); } |
I want to rotate my position vector by the orientation quaternion. What do you mean by multiple formulations?
There are three main ways to have a quaternion represent a rotation. Each of these can be "reversed" yielding six formulations with different properties (they are all related). Given a specific mathematical formulation, each of may be used directly as if one was performing the operation in quaternions or it can be converted to some other mathematical type (almost always a matrix). The above (assuming I didn't screw up) is a direct formulation where the quaternion is assume to be of unit length (otherwise it will yield a scaled rotation, where the scaling factor is the magnitude of the quaternion squared). This question and your previous are really the same "in wolves clothing". If you were to pug the vectors (1,0,0), (0,1,0), & (0,0,1) into the above it will yield three vectors (really every where we're saying vectors should be bivectors, but that's a different story). Shove these three vectors into either a row or column of a matrix and you have the (misnamed) quaternion to matrix conversion. Make it a 4x4 matrix and you can shove the translation vector in the appropriate spot and bingo...you're done.
LWJGL's Quaternion class is ... well it just isn't very good.
It doesn't really do anything and was obviously thrown together by someone with no understanding of quaternions (no offense intended if said person is reading this...you're far from alone.)