Hi all;
I have an object (a projectile) that has only a vector as its orientation (no euller angles or quaternions). How can i get the eullers angles to rotate it (i think the Z axis could be 0)? Is there any way to draw it without having to convert that vector? (sorry about my english)
Thanx
i dunno if my compute is good but you can
try this to rotate your vector
you should use a quaternion and transform it into a 4x4 matrix.
After multiply the vector by the matrix and the job is done (probably)
i have posted a stuff about vector*matrix
have a look on this forum
if something is wrong correct me.
see y
to convert a quaternion into a 4x4 matrix use this
typedef struct
{
GLfloat qx,qy,qz,qw;
}
QUAT ;
//euler to quaternion
void qAxisToQuat(QUAT *q,float _x,float _y,float _z,float _angle);
STD void qNormalize(QUAT q)
{
double norm = sqrt((q->qxq->qx) + (q->qyq->qy) + (q->qzq->qz) + (q->qw*q->qw) );
if (norm==0) return;
q->qx = (float)q->qx / norm;
q->qy = (float)q->qy / norm;
q->qz = (float)q->qz / norm;
q->qw = (float)q->qw / norm;
}
//
void qAxisToQuat(QUAT *q,float _x,float _y,float _z,float _angle) {
double rad, scale;
if (_x==0 && _y==0 && _z==0)
{
q->qw= 1.0f;
q->qx = 0.0f;
q->qy = 0.0f;
q->qz = 0.0f;
return;
}
_angle=DEGTORAD(_angle);
rad = _angle / 2;
q->qw = (float)cos(rad);
scale = sin(rad);
q->qx = (float)_x * scale;
q->qy = (float)_y * scale;
q->qz = (float)_z * scale;
qNormalize(q);
}
//quaternion to 4x4 OpenGL matrix
void qGetMatrix(QUAT *q,float _m[16]) ;
void qGetMatrix(QUAT *q,float _m[16])
{
int i;
double w2,x2, y2, z2, xy, xz, yz, wx, wy, wz;
for (i=0;i<16;i++)
_m[i]=0.0;
_m[15] = 1;
x2 = q->qx* q->qx;
y2 = q->qy*q->qy;
z2 = q->qz* q->qz;
w2 = q->qw* q->qw;
xy = q->qx * q->qy;
xz = q->qx * q->qz;
yz = q->qy * q->qz;
wx = q->qw * q->qx;
wy = q->qw * q->qy;
wz = q->qw * q->qz;
_m[0] = (float)1 - 2*(y2 + z2);
_m[1] = (float)2 * (xy + wz);
_m[2] = (float)2 * (xz - wy);
_m[4] = (float)2 * (xy - wz);
_m[5] = (float)1 - 2*(x2 + z2);
_m[6] = (float)2 * (yz + wx);
_m[8] = (float)2 * (xz + wy);
_m[9] = (float)2 * (yz - wx);
_m[10] =(float)1 - 2*(x2 + y2);
}
from the orientation X, you can compute two orthogonal vectors Y,Z.
X^Y=Z, Y^Z=X, Z^X=Y
from X, Y, Z, you can create a rotation matrix (like glu does in gluLookAt) and concatenate it to the modelview matrix.
to compute Y and Z you can do:
- choose a temporary vector A (non colinear with X)
- Z = X ^ A
- Y = Z ^ X
- normalize Y and Z
if X=(x0,x1,x2), Y=(y0,y1,y2), Z=(z0,z1,z2) then the rotation matrix is:
x0 y0 z0
x1 y1 z1
x2 y2 z2
Thanx … it solved my problem…