Created
January 15, 2019 14:09
-
-
Save kkabdol/dad4d4e3461e45974be9380f347fa328 to your computer and use it in GitHub Desktop.
Calculate look at vector after mouse scrolled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| D3DXVECTOR3 CPR_Player::GetNewDirFromInput() | |
| { | |
| D3DXVECTOR3 newDir; | |
| D3DXVECTOR2 deltaMousePos = ( GetMousePosition() - m_startMousePos ); | |
| deltaMousePos.x *= MOUSE_SENSITIVITY; | |
| deltaMousePos.y *= MOUSE_SENSITIVITY; | |
| deltaMousePos.x = ( abs( deltaMousePos.x ) > MOUSE_THRESHOLD ) ? deltaMousePos.x : 0.0f; | |
| deltaMousePos.y = ( abs( deltaMousePos.y ) > MOUSE_THRESHOLD ) ? deltaMousePos.y : 0.0f; | |
| deltaMousePos.y = CLAMP( deltaMousePos.y, D3DXToRadian( -89.9f ), D3DXToRadian( 89.9f ) ); | |
| D3DXMATRIX rotmatYaw; | |
| D3DXMatrixRotationY( &rotmatYaw, deltaMousePos.x ); | |
| D3DXVec3TransformCoord( &newDir, &m_startDir, &rotmatYaw ); | |
| D3DXMATRIX rotmatPitch; | |
| D3DXVECTOR3 pitchVector; | |
| D3DXVECTOR3 up( 0.0f, 1.0f, 0.0f ); | |
| D3DXVec3Cross( &pitchVector, &up, &newDir ); | |
| D3DXMatrixRotationAxis( &rotmatPitch, &pitchVector, deltaMousePos.y ); | |
| D3DXVec3TransformCoord( &newDir, &newDir, &rotmatPitch ); | |
| return newDir; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment