Firstly, the code:
//capture pitch and yaw from mouse
pitch += mouseState.lY*0.005f;
yaw -= mouseState.lX*0.005f;
//clamp pitch
/*
if(pitch < D3DXToRadian(-90)){
pitch = D3DXToRadian(-90);
} else if(pitch > D3DXToRadian(90)){
pitch = D3DXToRadian(90);
}
*/
//start from identity
D3DXQuaternionIdentity(&cam);
D3DXQuaternionIdentity(&tempQ);
//apply yaw
D3DXVECTOR3 bleh(0.0f,1.0f,0.0f); //y axis
D3DXQuaternionRotationAxis(&tempQ,&bleh,yaw);
D3DXQuaternionMultiply(&cam,&tempQ,&cam);
//apply pitch
bleh.x = 1.0f; //x axis
bleh.y = 0.0f;
bleh.z = 0.0f;
D3DXQuaternionRotationAxis(&tempQ,&bleh,pitch);
D3DXQuaternionMultiply(&cam,&cam,&tempQ);
//normalise the matrix
D3DXQuaternionNormalize(&cam,&cam);
//get the quaternion axis angle
D3DXQuaternionToAxisAngle(&cam,&camTo,&roll); //this could be where I am going wrong... I don't think the roll value is accurate, but I am using 0 for roll in D3DXMatrixLookAtLH anyway
camTo = camTo + camAt; //add the axis angle vector to the current camera location to get the camera to vector
(how do I get a c++ code box in this new forum? - edit: nevermind, after posting the thread it started to highlight, client side)
Then I am using D3DXMatrixLookAtLH with my camTo and camAt vectors (0 roll for the time being).
I am using directinput to get the mouse movement which is working nicely, but I am messing up the quaternion or how I am getting the camTo vector but I can't quite see how. I have been trying other things without fully understanding what I am doing so I may have been closer to the solution than the code I have at the moment.
The pitch seems to be responding fine (apart from my failed attempt at clamping the values but I can sort that later) but when changing the yaw it feels quite off and 'curves away' from where the camera should look to - increasingly so as the pitch differs from horizontal. That might be a bad explanation of the outcome but anybody who has done this before should instantly spot what I have done wrong, I can't seem to though.
I have been using gpqiki, this example and the msdn for reference but I am still stuck.
Any pointers in the right direction? At least I have avoided the popular trap of not starting with the identity matrix each frame