# Drawing object with orientation vector

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->qx
q->qx) + (q->qyq->qy) + (q->qzq->qz) + (q->qw*q->qw) );

``````if (norm==0) return;

q-&gt;qx = (float)q-&gt;qx / norm;
q-&gt;qy = (float)q-&gt;qy / norm;
q-&gt;qz = (float)q-&gt;qz / norm;
q-&gt;qw = (float)q-&gt;qw / norm;
``````

}
//
void qAxisToQuat(QUAT *q,float _x,float _y,float _z,float _angle) {

``````if (_x==0 && _y==0 && _z==0)
{
q-&gt;qw= 1.0f;
q-&gt;qx	= 0.0f;
q-&gt;qy	= 0.0f;
q-&gt;qz	= 0.0f;
return;
}
``````

``````q-&gt;qw		= (float)cos(rad);

q-&gt;qx = (float)_x * scale;
q-&gt;qy = (float)_y * scale;
q-&gt;qz = (float)_z * scale;

qNormalize(q);
``````

}
//quaternion to 4x4 OpenGL matrix
void qGetMatrix(QUAT *q,float _m) ;

void qGetMatrix(QUAT *q,float _m)
{
int i;
double w2,x2, y2, z2, xy, xz, yz, wx, wy, wz;

``````for (i=0;i&lt;16;i++)
_m[i]=0.0;
_m = 1;

x2	= q-&gt;qx* q-&gt;qx;
y2	=  q-&gt;qy*q-&gt;qy;
z2	=  q-&gt;qz* q-&gt;qz;
w2	=  q-&gt;qw* q-&gt;qw;

xy	=  q-&gt;qx *  q-&gt;qy;
xz	=  q-&gt;qx *  q-&gt;qz;
yz	=  q-&gt;qy *  q-&gt;qz;
wx	=  q-&gt;qw *  q-&gt;qx;
wy	=  q-&gt;qw *  q-&gt;qy;
wz	=  q-&gt;qw *  q-&gt;qz;

_m =	(float)1 - 2*(y2 + z2);
_m =	(float)2 * (xy + wz);
_m =	(float)2 * (xz - wy);

_m =	(float)2 * (xy - wz);
_m =	(float)1 - 2*(x2 + z2);
_m =	(float)2 * (yz + wx);

_m =	(float)2 * (xz + wy);
_m =	(float)2 * (yz - wx);
_m =(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…