Ok, I have been going round in circles trying to gain control of my ingame objects..
I have been using vectors like a camera, to control movement, simple and works!
I have moved into quaternions for the direction of the object, but its all up the wrong, and I am feeling lost!
Here's a synopsis of my code, firstly to change direction:
void Cobject::pitch( float rads, float timeDelta ){
rads *= timeDelta;
//Pitch about right vector.
D3DXMATRIX R;
D3DXMatrixRotationAxis(&R, &mRight, rads);
D3DXVec3TransformCoord(&mLook, &mLook, &R);
D3DXVec3TransformCoord(&mUp, &mUp, &R);
//Set quaternion for direction change
D3DXQuaternionRotationAxis( &qDelta, &mRight, rads );
D3DXQuaternionMultiply( &qRotation, &qDelta, &qRotation );
}
and here's how I render the object:
void Cobject::render()
{
D3DXMATRIX matX;
D3DXMATRIX matY;
D3DXMATRIX matZ;
D3DXMATRIX matObjSpin;
D3DXMATRIX matObjTrans;
D3DXMATRIX matObj;
D3DXMatrixRotationQuaternion( &matObjSpin, &qRotation );
D3DXMatrixTranslation( &matObjTrans, mPos.x, mPos.y, mPos.z );
matObj = matObjTrans * matObjSpin;
m_lpDevice->SetTransform( D3DTS_WORLD, &matObj );
Mobj->render();
}
The result is that the camera appears in be inside the object ( brief flashes of poly appear across the screen!). If I change
D3DXMatrixRotationQuaternion( &matObjSpin, &qRotation );
to
D3DXMatrixRotationQuaternion( &matObjSpin, &qDelta );
(where qDelta is the quaternion representing this frames' rotation), I can see the object trying to rotate, but reset each frame. Only when I try to multiply that with the qRotation varial do things go very weird!!!!!
Any advice really gratefullt received!!!
Thank you
Simon