void ArcBall::OnMove(int nX, int nY) { if(m_bDrag) { m_vCurrentPt = ScreenToVector((float)nX, (float)nY) ; m_increament = QuatFromBallPoints( m_oldPt, m_vCurrentPt ) ; m_qNow = m_qDown * QuatFromBallPoints( m_vDownPt, m_vCurrentPt ) ; m_oldPt = m_vCurrentPt ; } }
void ArcBall::OnMove(int mouse_x, int mouse_y) { if(is_dragged_) { current_point_ = ScreenToVector(mouse_x, mouse_y) ; rotation_increament_ = QuatFromBallPoints( old_point_, current_point_ ) ; current_quaternion_ = previous_quaternion_ * QuatFromBallPoints( previous_point_, current_point_ ) ; old_point_ = current_point_ ; } }
void ArcBall::OnMove(float nX, float nY) { if(m_bDrag) { m_vCurrentPt = ScreenToVector(nX, nY); m_increament = QuatFromBallPoints( m_oldPt, m_vCurrentPt ); m_qNow = XMQuaternionMultiply(m_qDown, QuatFromBallPoints( m_vDownPt, m_vCurrentPt)); m_oldPt = m_vCurrentPt ; } }
void Sun::HandleMessage(const D3DXMATRIX *pViewMatrix) { render::Interface *pInterface = render::Interface::GetInstance(); int iW = pInterface->GetWndWidth(); int iH = pInterface->GetWndHeight(); ui::Manager::_tagINPUTINFO *pInputInfo = ui::Manager::GetInstance()->GetInputInfoBuffer(); switch(pInputInfo->eType) { case UIMT_MS_BTNDOWN: if (pInputInfo->dwData == MK_RBUTTON && (pInputInfo->byKeyBuffer[DIK_LALT] & 0x80)) { m_bDrag = TRUE; m_qOld = m_qNow; ScreenToVector(pInputInfo->ptMouse.x,pInputInfo->ptMouse.y,iW,iH,1.0f,&m_vOldVector); } break; case UIMT_MS_MOVE: if (m_bDrag) { ScreenToVector(pInputInfo->ptMouse.x,pInputInfo->ptMouse.y,iW,iH,1.0f,&m_vCurVector); m_qNow = m_qOld * QuatFromBallPoints( m_vOldVector, m_vCurVector ); D3DXMATRIX mInvView; D3DXMatrixInverse(&mInvView, NULL, pViewMatrix); mInvView._41 = mInvView._42 = mInvView._43 = 0; D3DXMATRIX mLastRotInv; D3DXMatrixInverse(&mLastRotInv, NULL, &m_mRotSnapshot); D3DXMATRIX mRot; D3DXMatrixRotationQuaternion(&mRot, &m_qNow); m_mRotSnapshot = mRot; // Accumulate the delta of the arcball's rotation in view space. // Note that per-frame delta rotations could be problematic over long periods of time. m_mRot *= *pViewMatrix * mLastRotInv * mRot * mInvView; // Since we're accumulating delta rotations, we need to orthonormalize // the matrix to prevent eventual matrix skew D3DXVECTOR3* pXBasis = (D3DXVECTOR3*) &m_mRot._11; D3DXVECTOR3* pYBasis = (D3DXVECTOR3*) &m_mRot._21; D3DXVECTOR3* pZBasis = (D3DXVECTOR3*) &m_mRot._31; D3DXVec3Normalize( pXBasis, pXBasis ); D3DXVec3Cross( pYBasis, pZBasis, pXBasis ); D3DXVec3Normalize( pYBasis, pYBasis ); D3DXVec3Cross( pZBasis, pXBasis, pYBasis ); //Transform the default direction vector by the light's rotation matrix D3DXVec3TransformNormal( &m_vCurDirection, &m_vDefDirection , &m_mRot ); } break; } if (!(pInputInfo->dwMouseButtonState & MK_RBUTTON)) { m_bDrag = FALSE; } }
void EdGizmo::OnMouseMove( const EdSceneViewport& viewport, const SMouseMoveEvent& args ) { AHitProxy* pHitProxy = viewport.objAtCursor; const bool bHighlightObjects = true; if( bHighlightObjects ) { if( pHitProxy != nil ) { APlaceable* pPlaceable = pHitProxy->IsPlaceable(); m_hightlighted = pPlaceable; HGizmoAxis* pHGizmoAxis = SafeCast<HGizmoAxis>( pHitProxy ); if( pHGizmoAxis != nil ) { m_highlightedAxes = pHGizmoAxis->axis; } else { m_highlightedAxes = EGizmoAxis::GizmoAxis_None; } } else { m_hightlighted = nil; } } if( viewport.IsDraggingMouse() && m_selected != nil ) { // gizmo pick point, in screen space Vec2D pickPosNDC; PointToNDC( viewport, viewport.dragStartPosition.x(), viewport.dragStartPosition.y(), pickPosNDC ); //DBGOUT("pickPosNDC: %f, %f\n",pickPosNDC.x,pickPosNDC.y); Vec2D currPosNDC; PointToNDC( viewport, args.mouseX, args.mouseY, currPosNDC ); //DBGOUT("currPosNDC: %f, %f\n",currPosNDC.x,currPosNDC.y); // we need to convert screen space delta to world space movement Vec2D deltaNDC = currPosNDC - pickPosNDC; //dbgout << "delta=" << deltaNDC << dbgout.NewLine(); switch( m_currentMode ) { case EGizmoMode::Gizmo_Translate : if( m_currentAxis == GizmoAxis_None ) { return; } if( m_currentAxis == GizmoAxis_All ) { L_TranslateAll: const rxView& eye = viewport.GetView(); Ray3D pickRay = GetEyeRay( viewport, currPosNDC ); FLOAT prevDist = (m_oldState.translation - eye.origin).LengthSqr(); if( prevDist < VECTOR_EPSILON ) { return; } prevDist = mxSqrt(prevDist); Vec3D newEntityPos = eye.origin + pickRay.direction * prevDist; m_selected->SetOrigin( newEntityPos ); } else { Vec3D gizmoPickPos = F_Get_Translation_Gizmo_Pick_Point_In_World_Space( viewport, pickPosNDC, m_selected, m_currentAxis ); //Vec3D centerOfGizmo = m_selected->GetOrigin(); Vec3D pointOnGizmo = F_Get_Translation_Gizmo_Pick_Point_In_World_Space( viewport, currPosNDC, m_selected, m_currentAxis ); Vec3D translationDelta = pointOnGizmo - gizmoPickPos; const FLOAT MAX_TRANSLATION_DIST = 100.0f; translationDelta.Clamp(Vec3D(-MAX_TRANSLATION_DIST),Vec3D(MAX_TRANSLATION_DIST)); Vec3D newEntityPos = m_oldState.translation + translationDelta; m_selected->SetOrigin( newEntityPos ); } break; case EGizmoMode::Gizmo_Scale : if( m_currentAxis == GizmoAxis_All ) { goto L_TranslateAll; } else { //dbgout << "Scaling\n"; FLOAT mag = deltaNDC.LengthFast(); FLOAT newEntityScale = m_oldState.scaleFactor + mag * signf(deltaNDC.x); newEntityScale = maxf(newEntityScale,0.01f); m_selected->SetScale( newEntityScale ); } break; case EGizmoMode::Gizmo_Rotate : //if( m_currentAxis == GizmoAxis_None ) //{ // return false; //} if( m_currentAxis == GizmoAxis_All ) { goto L_TranslateAll; } else { //dbgout << "Rotating\n"; mxUNDONE; static FLOAT ROT_ARC_RADIUS = 1.0f; HOT_FLOAT(ROT_ARC_RADIUS); // starting point of rotation arc Vec3D vDownPt = ConvertScreenPointToVector( viewport, viewport.dragStartPosition.x(), viewport.dragStartPosition.y(), ROT_ARC_RADIUS ); // current point of rotation arc Vec3D vCurrPt = ConvertScreenPointToVector( viewport, args.mouseX, args.mouseY, ROT_ARC_RADIUS ); #if 0 Quat qRot = QuatFromBallPoints( vDownPt, vCurrPt ); qRot.Normalize(); #else Vec3D axis = Cross( vDownPt, vCurrPt ); axis.Normalize(); F4 angle = AngleBetween( vDownPt, vCurrPt ); Quat qRot( axis, angle ); qRot.Normalize(); #endif Quat q = qRot * m_oldState.orientation; q.Normalize(); m_selected->SetOrientation(q); } break; mxNO_SWITCH_DEFAULT; } } }