Jump to content
  • Advertisement
Sign in to follow this  
sansured

D3DXMatrixRotationYawPitchRoll

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using D3DXMatrixRotationYawPitchRoll function for camera movement by mouse.

D3DXMATRIX mCameraRot;

D3DXMatrixRotationYawPitchRoll( &mCameraRot, m_fCameraPitchAngle, 0, m_fCameraYawAngle );


But i have a problem.Camera's up and down movement doesn't work normal.Camera rolls around x axis for up and down movement. In the beginning when i look up cam. rolls around x axis normally and looks up but when i turn to left 90 degrees and try to look up again, the cam. can't move up and down just rolls around it self. My axis is stable(dosen't move with me) this is the reason but i can't update the axis(x,y,z) with me. Do you know any good way to move camera with mouse?

Share this post


Link to post
Share on other sites
Advertisement
Thanks for the order (YAW PITCH ROLL).
I am trying to open a bsp map in my engine and i am using CFirstPersonCamera class in SDK Update August 2005 "dxutmisc.cpp, dxutmisc.h".When i opend the map in first time i saw my axis are not match with the map so my player camera looks down in the map(i am walking in the wall :) )

Here is the mouse movement code from CFirstPersonCamera class:



VOID CFirstPersonCamera::FrameMove( FLOAT fElapsedTime, IDirect3DDevice9* pd3dDevice )
{
if( DXUTGetGlobalTimer()->IsStopped() )
fElapsedTime = 1.0f / DXUTGetFPS();

if( IsKeyDown(m_aKeys[CAM_RESET]) )
Reset();

// Get the mouse movement (if any) if the mouse button are down
if( (m_nActiveButtonMask & m_nCurrentButtonMask) || m_bRotateWithoutButtonDown )
UpdateMouseDelta( fElapsedTime );

// Get amount of velocity based on the keyboard input and drag (if any)
UpdateVelocity( fElapsedTime );

// Simple euler method to calculate position delta
D3DXVECTOR3 vPosDelta = m_vVelocity * fElapsedTime * 10;

// If rotating the camera
if( (m_nActiveButtonMask & m_nCurrentButtonMask) || m_bRotateWithoutButtonDown )
{
// Update the pitch & yaw angle based on mouse movement
float fYawDelta = m_vRotVelocity.x;
float fPitchDelta = m_vRotVelocity.y;

// Invert pitch if requested
if( m_bInvertPitch )
fPitchDelta = -fPitchDelta;

m_fCameraPitchAngle += fPitchDelta;
m_fCameraYawAngle += fYawDelta;

// Limit pitch to straight up or straight down
m_fCameraPitchAngle = __max( -D3DX_PI/2.0f, m_fCameraPitchAngle );
m_fCameraPitchAngle = __min( +D3DX_PI/2.0f, m_fCameraPitchAngle );
}

// Make a rotation matrix based on the camera's yaw & pitch
D3DXMATRIX mCameraRot;

D3DXMatrixRotationYawPitchRoll( &mCameraRot, m_fCameraYawAngle, m_fCameraPitchAngle, 0 );

// Transform vectors based on camera's rotation matrix
D3DXVECTOR3 vWorldUp, vWorldAhead;
D3DXVECTOR3 vLocalUp = D3DXVECTOR3(0,1,0);
D3DXVECTOR3 vLocalAhead = D3DXVECTOR3(0,0,1);
D3DXVec3TransformCoord( &vWorldUp, &vLocalUp, &mCameraRot );
D3DXVec3TransformCoord( &vWorldAhead, &vLocalAhead, &mCameraRot );

// Transform the position delta by the camera's rotation
D3DXVECTOR3 vPosDeltaWorld;
if( !m_bEnableYAxisMovement )
{
// If restricting Y movement, do not include pitch
// when transforming position delta vector.
D3DXMatrixRotationYawPitchRoll( &mCameraRot, m_fCameraYawAngle, 0.0f, 0.0f );
}
D3DXVec3TransformCoord( &vPosDeltaWorld, &vPosDelta, &mCameraRot );

// Move the eye position
m_vEye += vPosDeltaWorld;
if( m_bClipToBoundary )
ConstrainToBoundary( &m_vEye );

// Update the lookAt position based on the eye position
m_vLookAt = m_vEye + vWorldAhead;

pd3dDevice->SetTransform( D3DTS_VIEW, &m_mView );


// Update the view matrix
D3DXMatrixLookAtLH( &m_mView, &m_vEye, &m_vLookAt, &vWorldUp );

D3DXMatrixInverse( &m_mCameraWorld, NULL, &m_mView );

}




For fixing my look and upvec. way i changed


// This
D3DXVECTOR3 vLocalUp = D3DXVECTOR3(0,1,0);
D3DXVECTOR3 vLocalAhead = D3DXVECTOR3(0,0,1);

// To This
D3DXVECTOR3 vLocalUp = D3DXVECTOR3(0,0,1);
D3DXVECTOR3 vLocalAhead = D3DXVECTOR3(0,1,0);





This fix the look way and upvec. but this time my mouse movement doesn't work good.
Do you have any idea about fixing the problem? or do i need to make my own camera class my self.
Which one looks much better to you?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!