public void ProcessMessage(InputMessage message)
        {
            if (message.InputType != InputMessage.InputTypes.TwoFingerPinch)
            {
                return;
            }

            if (message.MessageType == InputMessage.MessageTypes.Update)
            {
                _raycast.CastPoint = (message.FingerPositions[0] + message.FingerPositions[1]) / 2.0f;
                _raycast.Invalidate();

                //Debug.Log(string.Format("mag: {0}, didHit: {1}", _input.Delta.magnitude, _raycast.DidHit));
                if (Mathf.Abs(message.GestureData[0]) > _startThreshold && _raycast.DidHit)
                {
                    TransformClone t = TransformClone.FromTransform(_targetCamera.transform);
                    _worldDelta = (_raycast.HitPoint - t.Position).normalized * Mathf.Clamp(message.GestureData[0], -_deltaClamp, _deltaClamp) * _zoomFactor;
                }

                float distance = Vector3.Distance(_targetCamera.transform.position, _raycast.HitPoint);
                if (_limited && (distance < _minHeight || distance > _maxHeight))
                {
                    float overshoot;
                    float a;
                    if (distance < _minHeight)
                    {
                        overshoot = _minHeight - distance;
                        a         = Vector3.Angle(_worldDelta.normalized, -_targetCamera.transform.forward);
                    }
                    else
                    {
                        overshoot = distance - _maxHeight;
                        a         = Vector3.Angle(_worldDelta.normalized, _targetCamera.transform.forward);
                    }

                    float factor = 1f - Mathf.Clamp((overshoot / _tolerance), 0f, 1f);

                    if (a > 90f)
                    {
                        _worldDelta *= factor;
                    }
                }

                if (_worldDelta.magnitude > 0.01f)
                {
                    Vector3 mod = _worldDelta;
                    _worldDelta *= 0.85f;

                    _deltaPos      = mod;
                    _pendingUpdate = true;

                    message.Use();
                    return;
                }
            }
        }
Esempio n. 2
0
        public void ProcessMessage(InputMessage message)
        {
            if (message.InputType != InputMessage.InputTypes.TwoFingerTwist)
            {
                return;
            }

            if (message.MessageType == InputMessage.MessageTypes.Update)
            {
                _raycast.CastPoint = (message.FingerPositions[0] + message.FingerPositions[1]) / 2.0f;
                _raycast.Invalidate();

                //Debug.Log(string.Format("mag: {0}, didHit: {1}", _input.Delta.magnitude, _raycast.DidHit));
                if (Mathf.Abs(message.GestureData[0]) > _startThreshold && _raycast.DidHit)
                {
                    _rotateDelta = message.GestureData[0];
                }

                if (Math.Abs(_rotateDelta) > _startThreshold)
                {
                    float          delta = _rotateDelta * _rotateFactor;
                    TransformClone t     = TransformClone.FromTransform(_targetCamera.transform);
                    //Debug.Log("Delta: " + delta);

                    _deltaRot = Quaternion.AngleAxis(delta, Vector3.up);

                    Vector3 currentPos = t.Position;
                    Vector3 newPos     = currentPos;
                    newPos  = newPos - _raycast.HitPoint;
                    newPos  = _deltaRot * newPos;
                    newPos += _raycast.HitPoint;


                    _deltaPos = newPos - currentPos;

                    _rotateDelta  *= _dampingFactor;
                    _pendingUpdate = true;

                    message.Use();
                    return;
                }
            }
        }