HPB(heading-pitch-bank) -> matrix is usually computed with multiplication of three quaternions, then building the matrix out of the resulting quaternion. But these three quaternions represent the angles of Y,X and Z rotation around their apropriate axis... And multiplication of quaternions is far from fast.
Is there a shortcut to getting the final quaternion or matrix, that doesn't involve the creation of three quaternions and their multiplication?
Posted on 2006-07-09 12:39:36 by Ultrano
Simplified the maths: removed zeroes and unnecessary multiplication:

``quatYXZ(x,y,z){ // x,y,z are the angles	float cx,sx;	float cz,sz;	float cy,sy;		cx=cos(x); sx=sin(x); // use LUTs here instead :)	cy=cos(y); sy=sin(y);	cz=cos(z); sz=sin(z);		result.x = sx*cy*cz + sy*cx*sz;	result.y = sy*cx*cz - sx*cy*sz;	result.z = sz*cy*cx - sy*sx*cz;	result.w = cy*cx*cz + sy*sx*sz;}``

This builds a quaternion by rotating on Y,X,Z (remember that rotation order is important). Also, vectors are: up=(0,1,0) , right=(1,0,0), forward=(0,0,1); (left-handed coordinate system).

Then, we'd make a matrix out of this quaternion :) .
Now, I'm off to playing with ca meras and scene-nodes :P
Posted on 2006-07-09 13:19:06 by Ultrano
Ahh, the code actually is
``quatYXZ(x,y,z){ // x,y,z are the angles	float cx,sx;	float cz,sz;	float cy,sy;	x/=2;	y/=2;	z/=2;		cx=cos(x); sx=sin(x); // use LUTs here instead :)	cy=cos(y); sy=sin(y);	cz=cos(z); sz=sin(z);		result.x = sx*cy*cz + sy*cx*sz;	result.y = sy*cx*cz - sx*cy*sz;	result.z = sz*cy*cx - sy*sx*cz;	result.w = cy*cx*cz + sy*sx*sz;}``

(Note: D3DXMatrixRotationYawPitchRoll uses such an internal proc, you needn't rewrite it if using D3D:) )
Posted on 2006-07-12 08:44:26 by Ultrano