예제 #1
0
        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;
                }
            }
        }
        public List <IModifier> GetModifiers()
        {
            _raycast.Invalidate();

            //Debug.Log(string.Format("mag: {0}, didHit: {1}", _input.Delta.magnitude, _raycast.DidHit));
            if (_raycast.DidHit && _enabled)
            {
                Vector3        worldDelta = default(Vector3);
                Quaternion     deltaRot   = default(Quaternion);
                TransformClone t          = TransformClone.FromTransform(_targetCamera.transform);
                bool           active     = false;

                if (_raycast.Distance < _minDistance || _raycast.Distance > _maxDistance)
                {
                    float overshoot = 0f;
                    if (_raycast.Distance < _minDistance)
                    {
                        overshoot = _raycast.Distance - _minDistance;
                    }
                    else if (_raycast.Distance > _maxDistance)
                    {
                        overshoot = _raycast.Distance - _maxDistance;
                    }

                    Vector3 direction = (_raycast.HitPoint - t.Position).normalized;
                    worldDelta = direction * overshoot * Time.deltaTime * (1f / _bounceTime);


                    Quaternion newRot     = Quaternion.LookRotation(direction);
                    Quaternion currentRot = t.Rotation;
                    deltaRot = newRot * Quaternion.Inverse(currentRot);
                    active   = true;
                }

                _enabled = true;

                if (!active)
                {
                    return(new List <IModifier>());
                }

                return(new List <IModifier>()
                {
                    new PositionModifier(worldDelta),
                    new RotationModifier(deltaRot)
                });
            }


            return(new List <IModifier>());
        }
예제 #3
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;
                }
            }
        }
예제 #4
0
        public List <IModifier> GetModifiers()
        {
            if (_inputDelta.magnitude > _startThreshold)
            {
                if (!this._pendingUpdate)
                {
                    _raycast.Invalidate();
                    this._pendingUpdate = true;
                }

                TransformClone t = TransformClone.FromTransform(_targetCamera.transform);

                _aroundDegrees += _inputDelta.x;
                _pitchDegrees  += _inputDelta.y;

                _inputDelta *= _dampingFactor;

                _pitchDegrees = Mathf.Clamp(_pitchDegrees, _minAngle, _maxAngle);

                float radius = Vector3.Distance(t.Position, _raycast.HitPoint);

                Vector3 currentPos = t.Position;
                Vector3 newPos     = Quaternion.Euler(_pitchDegrees, _aroundDegrees, 0) * (radius * Vector3.forward) + _raycast.HitPoint;
                _deltaPos = newPos - currentPos;

                Quaternion currentRot = t.Rotation;
                Quaternion newRot     = Quaternion.LookRotation(_raycast.HitPoint - newPos);
                _deltaRot      = newRot * Quaternion.Inverse(currentRot);
                _pendingUpdate = true;
            }

            if (this._pendingUpdate)
            {
                _pendingUpdate = false;
                return(new List <IModifier>()
                {
                    new PositionModifier(_deltaPos),
                    new RotationModifier(_deltaRot)
                });
            }
            return(new List <IModifier>());
        }
예제 #5
0
        public List <IModifier> GetModifiers()
        {
            TransformClone t = TransformClone.FromTransform(_targetCamera.transform);

            //Position
            Vector3 posDelta = t.Position - _lastPosition;

            posDelta -= _lastPosDelta;
            Vector3 mPos = posDelta * _mass * _damper;

            _posMomentum += mPos;
            _posMomentum *= 1 / _drag;

            //Position
            Vector3 rotDelta = FlexiUtils.EulerDifference(t.Rotation.eulerAngles, _lastRotation);

            rotDelta = FlexiUtils.EulerSubtract(rotDelta, _lastRotDelta);
            Vector3 mRot = rotDelta * _mass * _damper;

            _rotMomentum += mRot;
            _rotMomentum *= 1f / _drag;

            _lastPosition = t.Position;
            _lastRotation = t.Rotation.eulerAngles;

            _lastPosDelta = (_posMomentum / _mass);
            _lastRotDelta = (_rotMomentum / _mass);

            Debug.Log(rotDelta);

            return(new List <IModifier>()
            {
                //new PositionModifier(_lastPosDelta),
                //new RotationModifier(Quaternion.Euler(_lastRotDelta))
            });
        }
예제 #6
0
        public TransformClone Modify(TransformClone input)
        {
            input.Rotation = _delta * input.Rotation;

            return(input);
        }
예제 #7
0
 public TransformClone Modify(TransformClone input)
 {
     input.Position += _delta;
     return(input);
 }
예제 #8
0
 public TransformClone Modify(TransformClone input)
 {
     input.Position += _delta;
     return input;
 }
예제 #9
0
        public void ProcessMessage(InputMessage message)
        {
            if (message.InputType != InputMessage.InputTypes.TwoFingerDrag)
            {
                return;
            }

            if (message.MessageType == InputMessage.MessageTypes.Begin)
            {
                if (_pitchDegrees < _minAngle)
                {
                    _raycast.Invalidate();

                    // TODO: Less ugly way to determine this
                    Vector3 angles = Vector3.Scale(Quaternion.LookRotation(_targetCamera.transform.forward).eulerAngles - new Vector3(0f, 180f, 0f), new Vector3(-1f, 1f, 1f));

                    _pitchDegrees  = angles.x;
                    _aroundDegrees = angles.y;
                }
            }

            Vector2 fingerDelta = message.FingerDeltas[0];

            //Debug.Log(string.Format("mag: {0}, didHit: {1}", _input.Delta.magnitude, _raycast.DidHit));
            if (fingerDelta.magnitude > _startThreshold)
            {
                _inputDelta = Vector2.ClampMagnitude(fingerDelta, _deltaClamp);
            }

            if (_inputDelta.magnitude > _startThreshold)
            {
                TransformClone t = TransformClone.FromTransform(_targetCamera.transform);

                _aroundDegrees += _inputDelta.x;
                _pitchDegrees  += _inputDelta.y;

                _inputDelta *= _dampingFactor;

                if (_pitchDegrees < _minAngle)
                {
                    return;
                }

                Vector3 pivot = _raycast.HitPoint + (Vector3.up * _tiltUpFactor * (_pitchDegrees - _minAngle));

                float radius = Vector3.Distance(t.Position, _raycast.HitPoint);


                Vector3 currentPos = t.Position;
                Vector3 newPos     = Quaternion.Euler(_minAngle, _aroundDegrees, 0) * (radius * Vector3.forward) + _raycast.HitPoint;
                _deltaPos = newPos - currentPos;

                Quaternion currentRot = t.Rotation;
                Quaternion newRot     = Quaternion.LookRotation(pivot - newPos);
                _deltaRot = newRot * Quaternion.Inverse(currentRot);

                _pendingUpdate = true;

                message.Use();
                return;
            }
        }
예제 #10
0
        public TransformClone Modify(TransformClone input)
        {
            input.Rotation = _delta * input.Rotation;

            return input;
        }