Archived

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

Dean Johnson

Problem with update code

Recommended Posts

Here is the update function for my Frame class. void CFrame::Update() { // Update position m_vPosition.x += m_vVelocity.x * m_Right.x; m_vPosition.y += m_vVelocity.x * m_Right.y; m_vPosition.z += m_vVelocity.x * m_Right.z; m_vPosition.x += m_vVelocity.y * m_Up.x; m_vPosition.y += m_vVelocity.y * m_Up.y; m_vPosition.z += m_vVelocity.y * m_Up.z; m_vPosition.x += m_vVelocity.z * m_LookAt.x; m_vPosition.y += m_vVelocity.z * m_LookAt.y; m_vPosition.z += m_vVelocity.z * m_LookAt.z; D3DXMATRIX mPitch, mRoll, mYaw; // normalize vectors D3DXVec3Normalize( &m_LookAt, &m_LookAt ); D3DXVec3Cross( &m_Right, &m_Up, &m_LookAt ); D3DXVec3Normalize( &m_Right, &m_Right ); D3DXVec3Cross( &m_Up, &m_LookAt, &m_Right ); D3DXVec3Normalize( &m_Up, &m_Up ); // Y Rotation D3DXMatrixRotationAxis( &mYaw, &m_Up, m_Yaw ); D3DXVec3TransformCoord( &m_LookAt, &m_LookAt, &mYaw ); D3DXVec3TransformCoord( &m_Right, &m_Right, &mYaw ); // X Rotation D3DXMatrixRotationAxis( &mPitch, &m_Right, m_Pitch ); D3DXVec3TransformCoord( &m_LookAt, &m_LookAt, &mPitch ); D3DXVec3TransformCoord( &m_Up, &m_Up, &mPitch ); // Z Rotation D3DXMatrixRotationAxis( &mRoll, &m_LookAt, m_Roll ); D3DXVec3TransformCoord( &m_Right, &m_Right, &mRoll ); D3DXVec3TransformCoord( &m_Up, &m_Up, &mRoll ); m_mLocal(0,0) = m_Right.x; m_mLocal(0,1) = m_Up.x; m_mLocal(0,2) = m_LookAt.x; m_mLocal(1,0) = m_Right.y; m_mLocal(1,1) = m_Up.y; m_mLocal(1,2) = m_LookAt.y; m_mLocal(2,0) = m_Right.z; m_mLocal(2,1) = m_Up.z; m_mLocal(2,2) = m_LookAt.z; m_mLocal(3,0) = - D3DXVec3Dot( &m_vPosition, &m_Right ); m_mLocal(3,1) = - D3DXVec3Dot( &m_vPosition, &m_Up ); m_mLocal(3,2) = - D3DXVec3Dot( &m_vPosition, &m_LookAt ); g_pDevice->SetTransform( D3DTS_WORLD, &m_mLocal ); } The problem I am having is that I want the axis’s to move with the ship. Right now pitch and roll don’t affect each other in that if I roll the frame 90 degrees then the pitch should be to the side now. But instead I get the same pitch direction that I started with. How would you go about fixing this issue? Thanks

Share this post


Link to post
Share on other sites