#### Archived

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

# Finding a quaternion rotation angle ?

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

## 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 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

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009836
• ### Who's Online (See full list)

There are no registered users currently online

×