Hi,
I am getting bogged down in my moving object manipulation in my app.
My camera class is working well, so i'd thought i'd extend a version of that for my moving objects, eg plane.
Here's the code i am using, I am storing the direction the plane is pointing in.
void Cobject::pitch(float rads){
//Pitch about right vector.
D3DXMATRIX R;
D3DXMatrixRotationAxis(&R, &mRight, rads);
D3DXVec3TransformCoord(&mLook, &mLook, &R);
D3DXVec3TransformCoord(&mUp, &mUp, &R);
//update object direction
m_fPitch += rads;
}
void Cobject::yaw(float rads){
//Yaw about up vector.
D3DXMATRIX R;
D3DXMatrixRotationAxis(&R, &mUp, rads );
D3DXVec3TransformCoord(&mLook, &mLook, &R);
D3DXVec3TransformCoord(&mRight, &mRight, &R);
//update object direction
m_fYaw += rads;
}
void Cobject::roll(float rads){
//Roll about look vector.
D3DXMATRIX R;
D3DXMatrixRotationAxis(&R, &mLook, rads );
D3DXVec3TransformCoord(&mRight, &mRight, &R);
D3DXVec3TransformCoord(&mUp, &mUp, &R);
//update object direction
m_fRoll += rads;
}
Then I am just using this code to render the mutha:
void Cobject::render()
{
D3DXMATRIX matObjSpin;
D3DXMATRIX matObjTrans;
D3DXMATRIX matObj;
D3DXMatrixRotationYawPitchRoll( &matObjSpin, m_fYaw, m_fPitch, m_fRoll );
D3DXMatrixTranslation( &matObjTrans, mPos.x, mPos.y, mPos.z );
D3DXMatrixMultiply( &matObj, &matObjSpin, &matObjTrans );
m_lpDevice->SetTransform( D3DTS_WORLD, &matObj );
Mobj->render();
}
My problem is that once the model has moved out of the normal XYZ alignment, further rotations are still occuring around the XYZ axes and not the models look, up and right axes. This leads to odd movement to say the least.
Am I failing to update them correctly or something?
Thanks in advance
Simon