Dvoid Camera::Yaw() { if (m_MouseMoveInterval.x == 0) return; m_bMove = true; Matrix44 matRot; Vector3 vUp(0, 1, 0); float fAngle = m_MouseMoveInterval.x * m_fMouseSens * m_fTimeDelta; matRot.Rotation(vUp, fAngle); for (Duint i = 0; i < CD_MAX; ++i) { m_vDir[i] = Vec4ToVec3(matRot * Vector4(m_vDir[i], 0), Vector4::W_IGNORE); m_vDir[i].Normalize(); } }
Dvoid Camera::Pitch() { if ( m_MouseMoveInterval.y == 0) return; m_bMove = true; Matrix44 matRot; float fAngle = m_MouseMoveInterval.y * m_fMouseSens * m_fTimeDelta; matRot.Rotation( m_vDir[CD_RIGHT], fAngle ); // Right축을 제외한 축을 변환한다. for ( Duint i = 0; i < CD_MAX; ++i ) { if (i == CD_RIGHT) continue; m_vDir[i] = Vec4ToVec3(matRot * Vector4(m_vDir[i], 0), Vector4::W_IGNORE); m_vDir[i].Normalize(); } }
//world -> view Matrix44 TransformHelper::CreateView(const Vector3& eye, const Vector3& lookAt, const Vector3& up) { // compute view vectors Vector3 view = lookAt - eye; Vector3 right; Vector3 viewUp; view.Normalize(); right = view.Cross(up); right.Normalize(); viewUp = right.Cross(view); viewUp.Normalize(); // now set up matrices // base rotation matrix Matrix33 rotate; rotate.SetColumns(right, viewUp, -view); // view->world transform // set rotation //Matrix44 mViewToWorldMatrix; //mViewToWorldMatrix.Rotation(rotate); //// set translation (eye position) //mViewToWorldMatrix(0, 3) = eye.x; //mViewToWorldMatrix(1, 3) = eye.y; //mViewToWorldMatrix(2, 3) = eye.z; // world->view transform // set rotation Matrix44 mWorldToViewMatrix; rotate.Transpose(); mWorldToViewMatrix.Rotation(rotate); // set translation (rotate into view space) Vector3 invEye = -(rotate*eye); mWorldToViewMatrix(0, 3) = invEye.x; mWorldToViewMatrix(1, 3) = invEye.y; mWorldToViewMatrix(2, 3) = invEye.z; return mWorldToViewMatrix; }