//---------------------------------------------------------------------- // //---------------------------------------------------------------------- void CylinderMouseMoveCameraOperator::_doMouseMoveM( lnFloat dx, lnFloat dy ) { LVector3 pos = getTargetCamera()->getPosition(); LVector3 look_at = getTargetCamera()->getLookAt(); lnFloat s = 0.00175f * ( pos - look_at ).GetLength(); LVector3 view; LMatrix mat = LMatrix::Inverse(getTargetCamera()->getViewMatrix()); mat.M[3][0] = mat.M[3][1] = mat.M[3][2] = 0.0f; view.X = -dx * s; view.Y = dy * s; view.Z = 0.f; view.TransformCoord( mat ); getTargetCamera()->setPosition( pos + view ); getTargetCamera()->setLookAt( look_at + view ); }
//---------------------------------------------------------------------- // //---------------------------------------------------------------------- void CylinderMouseMoveCameraOperator::_doMouseMoveR( lnFloat dx, lnFloat dy, lnFloat width, lnFloat height ) { LVector3 view; LVector3 vup = getTargetCamera()->getUpDirection(); LVector3 pos = getTargetCamera()->getPosition(); LVector3 look_at = getTargetCamera()->getLookAt(); vup.Normalize(); // 注視点中心回転 if ( 1 ) { view = pos - look_at; } // 視点中心回転 else { view = look_at - pos; } LMatrix m; lnFloat d; if ( dx != 0 ) { d = LMath::PI * dx / width; // Y 軸周りの回転を逆にする場合 (右手系) if ( 0 ) // CAMTYPE_REV_ROT_Y { d = -d; } // vup を軸にする場合 //if ( m_type & CAMTYPE_AROUND_UP ) // D3DXMatrixRotationAxis( &m, &vup, D3DXToRadian(d) ); //else // D3DXMatrixRotationY( &m, D3DXToRadian(d) ); m.RotationY( d ); view.TransformCoord( m ); } if ( dy != 0 ) { // 球タイプ if ( 1 ) { LVector3 vaxis = LVector3::Cross(vup, view); vaxis.Normalize(); d = -( LMath::PI * dy / height ); m = LMatrix::RotationAxis(vaxis, d ); view.TransformCoord( m ); //D3DXVec3Cross( &vaxis, &vup, &view ); //D3DXVec3Normalize( &vaxis, &vaxis ); //d = (float)180.0 * (float)dy / (float)prc->bottom; //D3DXMatrixRotationAxis( &m, &vaxis, D3DXToRadian(d) ); //D3DXVec3TransformNormal( &view, &view, &m ); } else { //if( m_type & CAMTYPE_AROUND_UP ) // view += ( vup * (float)dy ); //else // view.y += (float)dy; } } // 注視点中心回転 if ( 1 ) { LVector3 old = pos; pos = look_at + view; // 上または下にドラッグし続けた場合、中天を通り過ぎたところで // XZ上の反対側の象限にカメラが移動して画面がちらちらするのを防ぐ処理 if ( ( ( old.X < 0 && pos.X > 0 ) || ( old.X > 0 && pos.X < 0 ) ) && ( ( old.Z < 0 && pos.Z > 0 ) || ( old.Z > 0 && pos.Z < 0 ) ) ) { pos = old; } } // 視点中心回転 else { pos += view; } getTargetCamera()->setPosition( pos ); }