Finding a quaternion rotation angle ?

Started by
0 comments, last by Jase_S 20 years, 5 months ago
Hi, I am trying to rotate a model to always face towards a point in world space, no matter where about it is positioned itself. To do this, I need to work out the axis vector and angle values to use with the D3DXQuaternionRotationAxis function. This is the part i'm really struggling on, can anyone help ? Jase [edited by - Jase_S on November 9, 2003 10:14:19 AM]
Advertisement
I finally managed to sort it, I don''t fully understand what i''ve done, but it works, so will leave it at that for now.

If anyone else struggles with the same problem, the solution that worked for me is below :

void q_rot_to(D3DXVECTOR3 *p1,D3DXVECTOR3 *p2,D3DXQUATERNION *q)
{
D3DXVECTOR3 dif,v,axis;
float angle;

dif=*p2-*p1;
v=D3DXVECTOR3(0,-1,0);
D3DXVec3Normalize(&dif,&dif);
D3DXVec3Cross(&axis,&v,&dif);
q->x=axis.x;
q->y=axis.y;
q->z=axis.z;
angle=D3DXVec3Dot(&v,&dif);
q->w=acos(angle);
}

Jase

This topic is closed to new replies.

Advertisement