private void ProcessRotationDrag() { if (m_activeAxis == EGizmoAxis.None) { return; } if (m_activeAxisList.Count <= 0) { return; } Matrix viewProj = m_frameViewInfo.ViewMatrix * m_frameViewInfo.ProjectionMatrix; SharpDX.Vector2 mouseDelta = new SharpDX.Vector2(Input.GetNativeAxisValue(EInputAxis.MouseX), -Input.GetNativeAxisValue(EInputAxis.MouseY)); SharpDX.Vector2 screenAxis = (SharpDX.Vector2)Vector3.TransformNormal(m_rotationDragAxis, viewProj); screenAxis.Normalize(); float deltaMove = -SharpDX.Vector2.Dot(mouseDelta, screenAxis) * RotationSpeed; m_totalAngleDelta += deltaMove; float snappedAngle = m_totalAngleDelta; if (AngleSnap > 0.0f) { snappedAngle = m_totalAngleDelta - m_totalAngleDelta % AngleSnap; } Quaternion deltaRotation = Quaternion.RotationAxis(m_activeAxisList[0], snappedAngle); m_controlledTransform.SetWorldRotation(deltaRotation * m_originalRotation); }
private void ProcessScaleDrag() { if (m_activeAxis == EGizmoAxis.None) { return; } if (m_activeAxisList.Count <= 0) { return; } Matrix viewProj = m_frameViewInfo.ViewMatrix * m_frameViewInfo.ProjectionMatrix; SharpDX.Vector2 mouseDelta = new SharpDX.Vector2(Input.GetNativeAxisValue(EInputAxis.MouseX), -Input.GetNativeAxisValue(EInputAxis.MouseY)); SharpDX.Vector2 screenAxis; switch (m_activeAxisList.Count) { case 1: screenAxis = (SharpDX.Vector2)Vector3.TransformNormal(m_activeAxisList[0], viewProj); break; case 2: screenAxis = (SharpDX.Vector2)Vector3.TransformNormal(m_activeAxisList[0] + m_activeAxisList[1], viewProj); break; case 3: screenAxis = new SharpDX.Vector2(0.5f, 0.5f); break; default: throw new ArgumentOutOfRangeException(); } screenAxis.Normalize(); float deltaMove = SharpDX.Vector2.Dot(mouseDelta, screenAxis) * ScaleSpeed * m_scaleSizeFactor; m_totalScaleDelta += deltaMove; float snappedDelta = m_totalScaleDelta; if (ScaleSnap > 0.0f) { snappedDelta = m_totalScaleDelta - m_totalScaleDelta % AngleSnap; } m_controlledTransform.SetWorldScale(m_originalScale + m_scaleAxis * snappedDelta); }