Archived

This topic is now archived and is closed to further replies.

Finding a quaternion rotation angle ?

This topic is 5148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites