void ElCamera::setDirection(const D3DXVECTOR3& vec) { // Do nothing if given a zero vector if (vec == D3DXVECTOR3(0.0f, 0.0f, 0.0f)) return; D3DXVECTOR3 adjustVec = vec; if (mYawFixed) adjustVec.y = 0.0f; D3DXVec3Normalize(&adjustVec, &adjustVec); D3DXMATRIX m; if (D3DXVec3LengthSq(&(D3DXVECTOR3(0.0f, 0.0f, 1.0f) + adjustVec)) < 0.00005f) { // Oops, a 180 degree turn (infinite possible rotation axes) // Default to yaw i.e. use current DOWN D3DXMatrixRotationAxis(&m, &D3DXVECTOR3(0.0f, -1.0f, 0.0f), D3DX_PI); } else { D3DXVECTOR3 axe; D3DXVec3Cross(&axe, &D3DXVECTOR3(0.0f, 0.0f, 1.0f), &adjustVec); float dot = D3DXVec3Dot(&D3DXVECTOR3(0.0f, 0.0f, 1.0f), &adjustVec); D3DXMatrixRotationAxis(&m, &axe, acos(dot)); } mLook = vec; D3DXVec3TransformCoord(&mUp, &D3DXVECTOR3(0.0f, 1.0f, 0.0f), &m); D3DXVec3TransformCoord(&mRight, &D3DXVECTOR3(1.0f, 0.0f, 0.0f), &m); calcViewOrientation(); invalidateView(); }

void RotateCameraHorizontally(float radian) { /* 常规变换 */ //将eyePoint绕lookAt点旋转 D3DXMATRIX rotation; //D3DXMatrixRotationAxis: // D3DXMATRIX * D3DXMatrixRotationAxis( //__inout D3DXMATRIX *pOut, // __in const D3DXVECTOR3 *pV, // __in FLOAT Angle // ); //其功能是生成绕原点处的方向向量为pV的轴旋转角度Angle的旋转变换矩阵 //所以在绕非原点旋转时需要先将目标点的旋转变换为绕原点旋转 D3DXMatrixRotationAxis(&rotation, &up, radian); D3DXVECTOR4 tmp; D3DXVec3Transform(&tmp, &(eyePoint-lookAt), &rotation); eyePoint = lookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z); /* fixed 变换 */ { //将eyePoint绕lookAt点旋转 D3DXMATRIX rotation; D3DXMatrixRotationAxis(&rotation, &fixedUp, radian); D3DXVECTOR4 tmp; D3DXVec3Transform(&tmp, &(fixedEyePoint-fixedLookAt), &rotation); fixedEyePoint = fixedLookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z); } }

//------------------------------------------------------------------------------- // handle mouse input for the light rotation // // Axes: global x/y axis //------------------------------------------------------------------------------- void HandleMouseInputLightRotate( void ) { POINT mousePos; GetCursorPos( &mousePos ); ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos ); g_mousePos.x = mousePos.x; g_mousePos.y = mousePos.y; if (g_bMousePressedR) { int nXDiff = -(g_mousePos.x - g_LastmousePos.x); int nYDiff = -(g_mousePos.y - g_LastmousePos.y); aiVector3D v = aiVector3D(1.0f,0.0f,0.0f); aiMatrix4x4 mTemp; D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f)); D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0], (const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp); v = aiVector3D(0.0f,1.0f,0.0f); D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f)); D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0], (const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp); } return; }

/* * * @author Michael McQuarrie * @param _pParticle The particle that needs to be reset * @return void */ void CFlagParticleEmitter::Resetparticle(TParticle *_pParticle) { //Initalise origin _pParticle->vec3Position = m_vec3Origin += m_pFlag->GetUp() * 4.18f; float32 fAngleHor = D3DXToRadian(rand() % 360); float32 fAngleVer = -D3DXToRadian((rand() % 61) + 60); D3DXMATRIX yawMat; D3DXMATRIX pitchMat; D3DXMatrixRotationAxis(&yawMat, &m_pFlag->GetUp(), fAngleHor); D3DXMatrixRotationAxis(&pitchMat, &m_pFlag->GetRight(), fAngleVer); _pParticle->vec3Velocity = m_pFlag->GetDirection(); D3DXVec3TransformCoord(&_pParticle->vec3Velocity, &_pParticle->vec3Velocity, &pitchMat); D3DXVec3TransformCoord(&_pParticle->vec3Velocity, &_pParticle->vec3Velocity, &yawMat); //Setting it D3DXVec3Normalize(&_pParticle->vec3Velocity, &_pParticle->vec3Velocity); _pParticle->vec3Velocity += m_pFlag->GetUp(); //Setting the life timer _pParticle->fAge = 1.0f; _pParticle->fLifeTime = 0.0f; _pParticle->colour = (m_pFlag->GetTeam() == TEAM_GREEN)?(KCOLTEAM_GREEN):(KCOLTEAM_PURPLE); _pParticle->bAlive = true; }

//------------------------------------------------------------------------------- // Handle mouse input for the FPS input behaviour // // Movement in x and y axis is possible //------------------------------------------------------------------------------- void HandleMouseInputFPS( void ) { POINT mousePos; GetCursorPos( &mousePos ); ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos ); g_mousePos.x = mousePos.x; g_mousePos.y = mousePos.y; D3DXMATRIX matRotation; if (g_bMousePressed) { int nXDiff = (g_mousePos.x - g_LastmousePos.x); int nYDiff = (g_mousePos.y - g_LastmousePos.y); if( 0 != nYDiff) { D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)& g_sCamera.vRight, D3DXToRadian((float)nYDiff / 6.0f)); D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)& g_sCamera.vLookAt, &matRotation ); D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vUp, &matRotation ); } if( 0 != nXDiff ) { D3DXVECTOR3 v(0,1,0); D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)&g_sCamera.vUp, D3DXToRadian((float)nXDiff / 6.0f) ); D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vLookAt, &matRotation ); D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vRight,(D3DXVECTOR3*) &g_sCamera.vRight, &matRotation ); } } g_LastmousePos.x = g_mousePos.x; g_LastmousePos.y = g_mousePos.y; }

void FreeCameraController::recompute_rotation() { D3DXVECTOR3 view_temp; D3DXVECTOR3 view_temp2; D3DXVECTOR3 right_temp; D3DXVECTOR3 up_temp; D3DXVECTOR3 right_vector_v3 = right_vector_; D3DXVECTOR3 up_vector_v3 = up_vector_; D3DXVECTOR3 view_vector_v3 = view_vector_; D3DXVECTOR3 default_right_v3 = default_right_; D3DXVECTOR3 default_forward_v3 = default_forward_; D3DXVECTOR3 default_up_v3 = default_up_; D3DXMATRIX m_1; D3DXMATRIX m_2; D3DXMatrixRotationAxis(&m_2, &default_up_v3, yaw_); D3DXVec3TransformCoord(&view_temp2, &default_forward_v3, &m_2); D3DXVec3TransformCoord(&right_temp, &default_right_v3, &m_2); D3DXMatrixRotationAxis(&m_1, &right_temp, -pitch_); D3DXVec3TransformCoord(&view_temp, &view_temp2, &m_1); D3DXVec3TransformCoord(&up_temp, &default_up_v3, &m_1); D3DXVec3Normalize(&up_vector_v3, &up_temp); D3DXVec3Normalize(&view_vector_v3, &view_temp); D3DXVec3Normalize(&right_vector_v3, &right_temp); right_vector_ = D3DXVECTOR4(right_vector_v3.x, right_vector_v3.y, right_vector_v3.z, 1); up_vector_ = D3DXVECTOR4(up_vector_v3.x, up_vector_v3.y, up_vector_v3.z, 1); view_vector_ = D3DXVECTOR4(view_vector_v3.x, view_vector_v3.y, view_vector_v3.z, 1); }

void Camera::Update() { static D3DXVECTOR2 lastMousePosition = theInput->GetMousePosition(); // Rotate the camera if (theInput->GetKey(VK_LBUTTON)) { D3DXVECTOR2 curMousePosition = theInput->GetMousePosition(); float xDiff = curMousePosition.x - lastMousePosition.x; float yDiff = curMousePosition.y - lastMousePosition.y; lastMousePosition = curMousePosition; D3DXMATRIX matRotation; if (yDiff != 0) { D3DXMatrixRotationAxis(&matRotation, &m_right, D3DXToRadian(yDiff / 3.0f)); D3DXVec3TransformCoord(&m_look, &m_look, &matRotation); D3DXVec3TransformCoord(&m_up, &m_up, &matRotation); } if (xDiff != 0) { D3DXMatrixRotationAxis(&matRotation, &D3DXVECTOR3(0, 1, 0), D3DXToRadian(xDiff / 3.0f)); D3DXVec3TransformCoord(&m_look, &m_look, &matRotation); D3DXVec3TransformCoord(&m_up, &m_up, &matRotation); D3DXVec3TransformCoord(&m_right, &m_right, &matRotation); } } else { lastMousePosition = theInput->GetMousePosition(); } // Move the Camera float moveX = 0.0f, moveY = 0.0f, moveZ = 0.0f; if (theInput->GetKey(VK_UP) || theInput->GetKey('W')) moveZ += 1.0f; if (theInput->GetKey(VK_DOWN) || theInput->GetKey('S')) moveZ -= 1.0f; if (theInput->GetKey(VK_LEFT) || theInput->GetKey('A')) moveX -= 1.0f; if (theInput->GetKey(VK_RIGHT) || theInput->GetKey('D')) moveX += 1.0f; if (theInput->GetKey(VK_HOME) || theInput->GetKey('Q')) moveY += 1.0f; if (theInput->GetKey(VK_END) || theInput->GetKey('E')) moveY -= 1.0f; D3DXVECTOR3 move = moveX * m_right + moveY * m_up + moveZ * m_look; D3DXVec3Normalize(&move, &move); m_position += move * m_moveSpeed * theTime->GetDeltaTime(); UpdateViewMatrix(); }

void Camera::CalculateViewMatrix(D3DXMATRIX *viewMatrix) { /* Start with our camera axis pointing down z An alternative method is to just keep adjusting our axis but if we do that the axis can start to lose its orthogonal shape (due to floating point innacuracies). This could be solved by rebuilding the orthogonal shape each time with the following: 1. normalising the look vector 2. creating the up vector from the cross product of the look and the right 3. normalising up 4. creating the right vector from the cross product of the look and the up 5. normalising right */ m_up=D3DXVECTOR3(0.0f,1.0f,0.0f); m_look=D3DXVECTOR3(0.0f,0.0f,1.0f); m_right=D3DXVECTOR3(1.0f,0.0f,0.0f); // Yaw is rotation around the y axis (m_up) // Create a matrix that can carry out this rotation D3DXMATRIX yawMatrix; D3DXMatrixRotationAxis(&yawMatrix, &m_up, m_yaw); // To apply yaw we rotate the m_look & m_right vectors about the m_up vector (using our yaw matrix) D3DXVec3TransformCoord(&m_look, &m_look, &yawMatrix); D3DXVec3TransformCoord(&m_right, &m_right, &yawMatrix); // Pitch is rotation around the x axis (m_right) // Create a matrix that can carry out this rotation D3DXMATRIX pitchMatrix; D3DXMatrixRotationAxis(&pitchMatrix, &m_right, m_pitch); // To apply pitch we rotate the m_look and m_up vectors about the m_right vector (using our pitch matrix) D3DXVec3TransformCoord(&m_look, &m_look, &pitchMatrix); D3DXVec3TransformCoord(&m_up, &m_up, &pitchMatrix); // Roll is rotation around the z axis (m_look) // Create a matrix that can carry out this rotation D3DXMATRIX rollMatrix; D3DXMatrixRotationAxis(&rollMatrix, &m_look, m_roll); // To apply roll we rotate up and right about the look vector (using our roll matrix) // Note: roll only really applies for things like aircraft unless you are implementing lean D3DXVec3TransformCoord(&m_right, &m_right, &rollMatrix); D3DXVec3TransformCoord(&m_up, &m_up, &rollMatrix); // Build the view matrix from the transformed camera axis D3DXMatrixIdentity(viewMatrix); viewMatrix->_11 = m_right.x; viewMatrix->_12 = m_up.x; viewMatrix->_13 = m_look.x; viewMatrix->_21 = m_right.y; viewMatrix->_22 = m_up.y; viewMatrix->_23 = m_look.y; viewMatrix->_31 = m_right.z; viewMatrix->_32 = m_up.z; viewMatrix->_33 = m_look.z; viewMatrix->_41 = - D3DXVec3Dot( &m_position,&m_right); viewMatrix->_42 = - D3DXVec3Dot( &m_position,&m_up); viewMatrix->_43 = - D3DXVec3Dot( &m_position,&m_look); }

void camera::angleUp(float a) { //THIS IS FOR TURNING D3DXMATRIX rot; D3DXMatrixRotationAxis(&rot,&right,a); D3DXMatrixRotationAxis(&rot,&up,a); D3DXVec3TransformCoord(&right,&right,&rot); D3DXVec3TransformCoord(&look,&look,&rot); }

void RotateCameraVertically(float radian) { /* 常规变换 */ { D3DXVECTOR3 vForward = lookAt - eyePoint; D3DXVec3Normalize(&vForward, &vForward); D3DXVECTOR3 vLeft; D3DXVec3Cross(&vLeft, &up, &vForward); D3DXVec3Normalize(&vLeft, &vLeft); D3DXMATRIX rotation; D3DXMatrixRotationAxis(&rotation, &vLeft, radian); D3DXVECTOR4 tmp; D3DXVec3Transform(&tmp, &(eyePoint-lookAt), &rotation); eyePoint = lookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z); //竖直方向旋转时，up方向随之变化，需要更新 vForward = lookAt - eyePoint; D3DXVec3Normalize(&vForward, &vForward); D3DXVec3Cross(&up, &vForward, &vLeft); D3DXVec3Normalize(&up, &up); } /* fixed 变换 */ { D3DXVECTOR3 vForward = fixedLookAt - fixedEyePoint; D3DXVec3Normalize(&vForward, &vForward); D3DXVECTOR3 vLeft; D3DXVec3Cross(&vLeft, &fixedUp, &vForward); D3DXVec3Normalize(&vLeft, &vLeft); D3DXMATRIX rotation; D3DXMatrixRotationAxis(&rotation, &vLeft, radian); D3DXVECTOR4 tmp; D3DXVec3Transform(&tmp, &(fixedEyePoint-fixedLookAt), &rotation); fixedEyePoint = fixedLookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z); //竖直方向旋转时，up方向随之变化，需要更新 vForward = fixedLookAt - fixedEyePoint; D3DXVec3Normalize(&vForward, &vForward); D3DXVec3Cross(&fixedUp, &vForward, &vLeft); D3DXVec3Normalize(&fixedUp, &fixedUp); } }

void MANIPULATEACTIVE::Rotation(float x,float y,float z) { D3DXMATRIX tmp; D3DXMatrixRotationAxis(&tmp,&right,x/180.0f*D3DX_PI); D3DXVec3TransformCoord(&up,&up,&tmp); D3DXVec3TransformCoord(&look,&look,&tmp); D3DXMatrixRotationAxis(&tmp,&up,y/180.0f*D3DX_PI); D3DXVec3TransformCoord(&right,&right,&tmp); D3DXVec3TransformCoord(&look,&look,&tmp); D3DXMatrixRotationAxis(&tmp,&look,z/180.0f*D3DX_PI); D3DXVec3TransformCoord(&right,&right,&tmp); D3DXVec3TransformCoord(&up,&up,&tmp); }

void Camera::Yaw(float angle) { D3DXMATRIX mYaw; if (m_Type==LANDOBJECT) { D3DXMatrixRotationAxis(&mYaw, &D3DXVECTOR3(0.0f,1.0f,0.0f), angle); } else { D3DXMatrixRotationAxis(&mYaw, &m_Up, angle); } D3DXVec3TransformCoord(&m_Look, &m_Look, &mYaw); D3DXVec3TransformCoord(&m_Right, &m_Right, &mYaw); }

void Camera::Pitch( float angle ) { D3DXMATRIX R; D3DXMatrixRotationAxis(&R, &mRight, angle); D3DXVec3TransformNormal(&mUp, &mUp, &R); D3DXVec3TransformNormal(&mLook, &mLook, &R); }

void cCamera::roll (float angle) { D3DXMATRIX T; D3DXMatrixRotationAxis (&T, &look, angle); D3DXVec3TransformCoord (&right, &right, &T); D3DXVec3TransformCoord (&up, &up, &T); }

/* * rotates the turret towards the inputed angle * * author Cameron MacIntosh * param _fRadian the desired angle to rotate to * param _fDeltaTick the amount of time available to turn */ void CTower::RotateTurret(float32 _fRadian, float32 _fDeltaTick) { //if the turret angle is not equal to the desired angle if(_fRadian!=m_turretAngle.GetAngle()) { //turn the turret towards the desired angle, given possible turn amount CAngle targetAngle; targetAngle.SetAngle(_fRadian); m_turretAngle.TurnTowardsAngle(targetAngle, m_fTurnSpeed * _fDeltaTick); D3DXMATRIX mat; D3DXMatrixRotationAxis(&mat, &m_vec3Up, m_turretAngle.GetAngle()); D3DXVec3TransformCoord(&m_vec3ShootDir, &g_atUpRightDirectionVecs[m_eFace].vec3Direction, &mat); D3DXVec3TransformCoord(&m_vec3ShootRight, &g_atUpRightDirectionVecs[m_eFace].vec3Right, &mat); //set the world matrix of the turret model // Set the up, right and direction vectors into the world matirx. m_matTurretWorld._11 = m_vec3ShootRight.x; m_matTurretWorld._21 = m_vec3Up.x; m_matTurretWorld._31 = m_vec3ShootDir.x; m_matTurretWorld._12 = m_vec3ShootRight.y; m_matTurretWorld._22 = m_vec3Up.y; m_matTurretWorld._32 = m_vec3ShootDir.y; m_matTurretWorld._13 = m_vec3ShootRight.z; m_matTurretWorld._23 = m_vec3Up.z; m_matTurretWorld._33 = m_vec3ShootDir.z; m_matTurretWorld._41 = m_vec3Position.x; m_matTurretWorld._42 = m_vec3Position.y; m_matTurretWorld._43 = m_vec3Position.z; } }

void CameraController::RotateSide( float angle ) { // 회전축 D3DXVECTOR3 axis = { 0, 1, 0 }; D3DXVECTOR3 pickedPointOfCenter = Renderer::GetInstance()->GetPickedPointOfCenter(); D3DXVECTOR3 view = m_LookAtPoint - m_EyePoint; D3DXMATRIXA16 transMatrix; D3DXMATRIXA16 rotateMatrix; D3DXMatrixTranslation( &transMatrix, -pickedPointOfCenter.x, 0, -pickedPointOfCenter.z ); D3DXMatrixRotationAxis( &rotateMatrix, &axis, angle ); D3DXMATRIXA16 resultMatrix = transMatrix * rotateMatrix; D3DXMatrixTranslation( &transMatrix, pickedPointOfCenter.x, 0, pickedPointOfCenter.z ); resultMatrix = resultMatrix * transMatrix; D3DXVec3TransformCoord( &m_LookAtPoint, &m_LookAtPoint, &resultMatrix ); D3DXVec3TransformCoord( &m_EyePoint, &m_EyePoint, &resultMatrix ); // m_LookAtPoint = m_EyePoint + view; m_ViewMatrix; D3DXMatrixLookAtLH( &m_ViewMatrix, &m_EyePoint, &m_LookAtPoint, &m_UpVector ); D3DXMATRIXA16 heightMatrix; D3DXMatrixTranslation( &heightMatrix, 0, -MapManager::GetInstance()->GetHeightByPosition( m_EyePoint.x, m_EyePoint.z ) - 5.0f, 0 ); m_ViewMatrix = m_ViewMatrix * heightMatrix; Renderer::GetInstance()->SetViewMatrix( m_ViewMatrix ); }

void Camera::Pitch(float angle) { D3DXMATRIX mPitch; D3DXMatrixRotationAxis(&mPitch, &m_Right, angle); D3DXVec3TransformCoord(&m_Look, &m_Look, &mPitch); D3DXVec3TransformCoord(&m_Up, &m_Up, &mPitch); }

void Mesh::rotate(float degree, D3DXVECTOR3 axis) { D3DXMATRIX rot_frame; D3DXMatrixRotationAxis(&rot_frame, &axis, degree / 180.0f * PI); frame_ = rot_frame * frame_; }

void CCamera::pitch(float angle){ D3DXMATRIX T; D3DXMatrixRotationAxis(&T,&g_vRight,angle); D3DXVec3TransformCoord(&g_vLook,&g_vLook,&T); D3DXVec3TransformCoord(&g_vUp,&g_vUp,&T); }

Matrix3& Matrix3::RotateAxis( const Vector3& vAxis, const Real fTheta ) { #ifdef __USE_D3DX__ D3DXMatrixRotationAxis( (D3DXMATRIX*)this, (D3DXVECTOR3*)&vAxis, fTheta ); Transpose(); #else Real fCosTheta = COS( fTheta ); Real fSinTheta = SIN( fTheta ); Real fInvCT = 1.0f - fCosTheta; Vector3 vAST = vAxis * fSinTheta; Real xy = vAxis.x * vAxis.y * fInvCT; Real xz = vAxis.x * vAxis.z * fInvCT; Real yz = vAxis.y * vAxis.z * fInvCT; e[15] = 1.0f; e[3] = e[7] = e[11] = e[12] = e[13] = e[14] = 0.0f; e[0] = fCosTheta + vAxis.x * vAxis.x * fInvCT; e[5] = fCosTheta + vAxis.y * vAxis.y * fInvCT; e[10] = fCosTheta + vAxis.z * vAxis.z * fInvCT; e[1] = xy - vAST.z; e[2] = vAST.y + xz; e[6] = yz - vAST.x; e[4] = vAST.z + xy; e[8] = xz - vAST.y; e[9] = vAST.x + yz; #endif return *this; }

void CGameObject::Rotate(D3DXVECTOR3 *pd3dxvAxis, float fAngle) { //게임 객체를 주어진 회전축을 중심으로 회전한다. D3DXMATRIX mtxRotate; D3DXMatrixRotationAxis(&mtxRotate, pd3dxvAxis, (float)D3DXToRadian(fAngle)); m_d3dxmtxWorld = mtxRotate * m_d3dxmtxWorld; }

Matrix Matrix::CreateRotation(const Vector3& axis, float f) { Matrix m; D3DXVECTOR3 pV = axis.ToD3DVector3(); D3DXMatrixRotationAxis(&m.m_Matrix, &pV, f); return m; }

void cCamera::ThirdPersonYawPitch() { D3DXVECTOR2 mousePos = g_pEngine->input->mouse->GetChangeMousePos() * m_deskCamera.accelerationMouse; if( mousePos == D3DXVECTOR2( 0, 0 ) ) return; float yaw = mousePos.x; float pitch = mousePos.y; D3DXMATRIX mRotate; if( yaw != 0.f ) { D3DXMatrixRotationY( &mRotate, D3DXToRadian( yaw ) ); D3DXVec3TransformCoord( &m_deskCamera.frontAxis, &m_deskCamera.frontAxis, &mRotate ); D3DXVec3TransformCoord( &m_deskCamera.rightAxis, &m_deskCamera.rightAxis, &mRotate ); D3DXVec3Normalize( &m_deskCamera.frontAxis, &m_deskCamera.frontAxis ); D3DXVec3Normalize( &m_deskCamera.rightAxis, &m_deskCamera.rightAxis ); } if( pitch != 0.f ) { D3DXMatrixRotationAxis( &mRotate, &m_deskCamera.rightAxis, D3DXToRadian( pitch ) ); D3DXVec3TransformCoord( &m_deskCamera.frontAxis, &m_deskCamera.frontAxis, &mRotate ); D3DXVec3Normalize( &m_deskCamera.frontAxis, &m_deskCamera.frontAxis ); } m_deskCamera.position = m_deskCamera.look - ( m_deskCamera.frontAxis * m_deskCamera.TPSCameraDistance ); UpdateView(); }

////////////////////////////////////////////////////////////////////////// // Rotate Up과 Rotate Side는 Picking Ray 쏴서 // 피킹 된 점을 기준으로 회전해야 함 // // 수정해야 됨 ////////////////////////////////////////////////////////////////////////// void CameraController::RotateUp( float angle ) { // 회전각 제한 1 if ( m_LookAtPoint.y >= m_EyePoint.y && angle < 0 ) { return; } D3DXVECTOR3 preView = m_LookAtPoint - m_EyePoint; D3DXVECTOR3 view = { 0, 0, 0 }; D3DXVECTOR3 axis = { 0, 0, 0 }; D3DXVec3Cross( &axis, &m_UpVector, &preView ); D3DXMATRIXA16 rotateMatrix; D3DXMatrixRotationAxis( &rotateMatrix, &axis, angle ); D3DXVec3TransformCoord( &view, &preView, &rotateMatrix ); // 회전각 제한 2 if ( preView.x * view.x < 0 || preView.y * view.y < 0 || preView.z * view.z < 0 ) { return; } m_LookAtPoint = m_EyePoint + view; m_ViewMatrix; D3DXMatrixLookAtLH( &m_ViewMatrix, &m_EyePoint, &m_LookAtPoint, &m_UpVector ); D3DXMATRIXA16 heightMatrix; D3DXMatrixTranslation( &heightMatrix, 0, -MapManager::GetInstance()->GetHeightByPosition( m_EyePoint.x, m_EyePoint.z ) - 5.0f, 0 ); m_ViewMatrix = m_ViewMatrix * heightMatrix; Renderer::GetInstance()->SetViewMatrix( m_ViewMatrix ); }

void Camera::Pitch(float angle) { D3DXMATRIX T; D3DXMatrixRotationAxis(&T, &m_Right, angle); // rotate m_Up and m_Look around m_Right vector D3DXVec3TransformCoord(&m_Up,&m_Up, &T); D3DXVec3TransformCoord(&m_Look,&m_Look, &T); }

VOID CameraClass::RotationLookVec(FLOAT fAngle) { D3DXMATRIX R; D3DXMatrixRotationAxis(&R, &m_vLookVector, fAngle); D3DXVec3TransformCoord(&m_vRightVector, &m_vRightVector, &R); D3DXVec3TransformCoord(&m_vUpVector, &m_vUpVector, &R); m_vTargetPosition = m_vLookVector * D3DXVec3Length(&m_vCameraPosition) + m_vCameraPosition; }

void Camera::Pitch(float _angle) { D3DXMATRIX p; D3DXMatrixRotationAxis(&p, &right, _angle); D3DXVec3TransformNormal(&up, &up, &p); D3DXVec3TransformNormal(&look, &look, &p); }

void Camera::pitch( float angle ) { D3DXMATRIX m; D3DXMatrixRotationAxis(&m, &_right, angle); // D3DXVec3TransformCoord(&_up, &_up, &m); D3DXVec3TransformCoord(&_lookAt, &_lookAt, &m); }

void Transform::RotateAroundAxis(float radians, D3DXVECTOR3 axis) { D3DXMATRIX rotation; D3DXVec3Normalize(&axis, &axis); D3DXMatrixRotationAxis(&rotation, &axis, radians); m_rotation *= rotation; Update(true); }

void AVCamera::pitch(float angle) { D3DXMATRIX T; D3DXMatrixRotationAxis(&T, &m_right, angle); D3DXVec3TransformCoord(&m_up, &m_up, &T); D3DXVec3TransformCoord(&m_look, &m_look, &T); }