Exemplo n.º 1
0
        public static NumSnapSteps CalculateNumSnapSteps(float snapStep, float total)
        {
            NumSnapSteps numSteps = new NumSnapSteps();

            numSteps.FltNumSteps    = total / snapStep;
            numSteps.AbsFltNumSteps = Mathf.Abs(numSteps.FltNumSteps);
            numSteps.IntNumSteps    = (int)numSteps.FltNumSteps;
            numSteps.AbsIntNumSteps = Mathf.Abs(numSteps.IntNumSteps);
            numSteps.AbsFracSteps   = numSteps.AbsFltNumSteps - numSteps.AbsIntNumSteps;

            return(numSteps);
        }
        protected override void CalculateDragValues()
        {
            IInputDevice inputDevice      = RTInputDevice.Get.Device;
            Vector2      inputDeviceDelta = inputDevice.GetFrameDelta();

            _relativeRotation0 = Vector2.Dot(inputDeviceDelta, _workData.ScreenAxis0) * Sensitivity;
            _relativeRotation1 = Vector2.Dot(inputDeviceDelta, _workData.ScreenAxis1) * Sensitivity;

            if (_relativeRotation0 == 0.0f && _relativeRotation1 == 0.0f)
            {
                _relativeDragRotation = Quaternion.identity;
                return;
            }

            if (CanSnap())
            {
                _accumSnapDrag0 += _relativeRotation0;
                _accumSnapDrag0 %= 360.0f;

                _accumSnapDrag1 += _relativeRotation1;
                _accumSnapDrag1 %= 360.0f;

                if (_workData.SnapMode == GizmoSnapMode.Absolute && _adjustRotationForAbsSnap)
                {
                    NumSnapSteps numSnapSteps = SnapMath.CalculateNumSnapSteps(_workData.SnapStep0, _totalRotation0);
                    float        oldRotation  = _totalRotation0;
                    if (numSnapSteps.AbsFracSteps < 0.5f)
                    {
                        _totalRotation0 = numSnapSteps.AbsIntNumSteps * _workData.SnapStep0 * Mathf.Sign(_totalRotation0);
                    }
                    else
                    {
                        _totalRotation0 = (numSnapSteps.AbsIntNumSteps + 1) * _workData.SnapStep0 * Mathf.Sign(_totalRotation0);
                    }

                    _accumSnapDrag0    = 0.0f;
                    _relativeRotation0 = _totalRotation0 - oldRotation;

                    numSnapSteps = SnapMath.CalculateNumSnapSteps(_workData.SnapStep1, _totalRotation1);
                    oldRotation  = _totalRotation1;
                    if (numSnapSteps.AbsFracSteps < 0.5f)
                    {
                        _totalRotation1 = numSnapSteps.AbsIntNumSteps * _workData.SnapStep1 * Mathf.Sign(_totalRotation1);
                    }
                    else
                    {
                        _totalRotation1 = (numSnapSteps.AbsIntNumSteps + 1) * _workData.SnapStep1 * Mathf.Sign(_totalRotation1);
                    }

                    _accumSnapDrag1       = 0.0f;
                    _relativeRotation1    = _totalRotation1 - oldRotation;
                    _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation1, _workData.Axis1) * Quaternion.AngleAxis(_relativeRotation0, _workData.Axis0);

                    _adjustRotationForAbsSnap = false;
                }
                else
                {
                    _relativeDragRotation = Quaternion.identity;

                    if (SnapMath.CanExtractSnap(_workData.SnapStep0, _accumSnapDrag0))
                    {
                        _relativeRotation0 = SnapMath.ExtractSnap(_workData.SnapStep0, ref _accumSnapDrag0);
                        _totalRotation0   += _relativeRotation0;
                        _totalRotation0   %= 360.0f;

                        _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation0, _workData.Axis0);
                    }

                    if (SnapMath.CanExtractSnap(_workData.SnapStep1, _accumSnapDrag1))
                    {
                        _relativeRotation1 = SnapMath.ExtractSnap(_workData.SnapStep1, ref _accumSnapDrag1);
                        _totalRotation1   += _relativeRotation1;
                        _totalRotation1   %= 360.0f;

                        _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation1, _workData.Axis1) * _relativeDragRotation;
                    }
                }
            }
            else
            {
                _adjustRotationForAbsSnap = true;
                _accumSnapDrag0           = _accumSnapDrag1 = 0.0f;

                _totalRotation0 += _relativeRotation0;
                _totalRotation1 += _relativeRotation1;

                _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation1, _workData.Axis1) * Quaternion.AngleAxis(_relativeRotation0, _workData.Axis0);
            }

            _totalDragRotation = _relativeDragRotation * _totalDragRotation;
        }
        protected override void CalculateDragValues()
        {
            IInputDevice inputDevice = RTInputDevice.Get.Device;

            _relativeRotation = Vector2.Dot(_screenDragCircleTangent, inputDevice.GetFrameDelta()) * Sensitivity;

            if (_relativeRotation == 0.0f)
            {
                _relativeDragRotation = Quaternion.identity;
                return;
            }

            if (CanSnap())
            {
                _accumSnapDrag += _relativeRotation;
                _accumSnapDrag %= 360.0f;

                if (_workData.SnapMode == GizmoSnapMode.Absolute && _adjustRotationForAbsSnap)
                {
                    NumSnapSteps numSnapSteps = SnapMath.CalculateNumSnapSteps(_workData.SnapStep, _totalRotation);

                    float oldRotation = _totalRotation;
                    if (numSnapSteps.AbsFracSteps < 0.5f)
                    {
                        _totalRotation = numSnapSteps.AbsIntNumSteps * _workData.SnapStep * Mathf.Sign(_totalRotation);
                    }
                    else
                    {
                        _totalRotation = (numSnapSteps.AbsIntNumSteps + 1) * _workData.SnapStep * Mathf.Sign(_totalRotation);
                    }

                    _relativeRotation = _totalRotation - oldRotation;
                    _accumSnapDrag    = 0.0f;

                    _relativeDragRotation     = Quaternion.AngleAxis(_relativeRotation, _workData.Axis);
                    _adjustRotationForAbsSnap = false;
                }
                else
                if (SnapMath.CanExtractSnap(_workData.SnapStep, _accumSnapDrag))
                {
                    _relativeRotation = SnapMath.ExtractSnap(_workData.SnapStep, ref _accumSnapDrag);
                    _totalRotation   += _relativeRotation;
                    _totalRotation   %= 360.0f;

                    _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation, _workData.Axis);
                }
                else
                {
                    _relativeDragRotation = Quaternion.identity;
                }
            }
            else
            {
                _accumSnapDrag            = 0.0f;
                _adjustRotationForAbsSnap = true;

                _totalRotation += _relativeRotation;
                _totalRotation %= 360.0f;

                _relativeDragRotation = Quaternion.AngleAxis(_relativeRotation, _workData.Axis);
            }

            _totalDragRotation = Quaternion.AngleAxis(_totalRotation, _workData.Axis);
        }