예제 #1
0
        public void ProcessMessage(InputMessage message)
        {
            if (message.InputType != InputMessage.InputTypes.OneFingerDrag)
            {
                return;
            }
            if (message.MessageType == InputMessage.MessageTypes.Update ||
                message.MessageType == InputMessage.MessageTypes.Begin)
            {
                _raycast.Invalidate();

                Vector2 delta = message.FingerDeltas[0];



                //Debug.Log(string.Format("mag: {0}, didHit: {1}", _input.Delta.magnitude, _raycast.DidHit));
                if (delta.magnitude > _startThreshold && _raycast.DidHit)
                {
                    float angle = AngleMath.AngleSigned(Vector3.forward, _targetCamera.transform.forward, Vector3.up);
                    _worldDelta = Quaternion.AngleAxis(angle, Vector3.up) * FlexiUtils.SwapYZ(message.NormalisedFingerDeltas[0]) * (_panFactor * _raycast.Distance) * (_invert ? -1f : 1f);
                    _worldDelta = Vector3.ClampMagnitude(_worldDelta, _deltaClamp);


                    float distance = Vector3.Distance(_center, _raycast.HitPoint);
                    if (_limited && distance > _limitStart)
                    {
                        float overshoot = (distance - _limitStart);

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

                        float a = Vector3.Angle(_worldDelta.normalized, -_raycast.HitPoint.normalized);

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

                    _deltaPos      = _worldDelta;
                    _pendingUpdate = true;

                    message.Use();
                }
            }
            else
            {
                if (_worldDelta.magnitude > _startThreshold)
                {
                    Vector3 mod = _worldDelta;
                    _worldDelta   *= _dampingFactor;
                    _deltaPos      = mod;
                    _pendingUpdate = true;

                    return;
                }
            }
        }
예제 #2
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))
            });
        }