/// <inheritdoc />
 protected override float doRotation(Vector2 oldScreenPos1, Vector2 oldScreenPos2, Vector2 newScreenPos1,
                                     Vector2 newScreenPos2, ProjectionParams projectionParams)
 {
     var oldScreenDelta = oldScreenPos2 - oldScreenPos1;
     var newScreenDelta = newScreenPos2 - newScreenPos1;
     return (Mathf.Atan2(newScreenDelta.y, newScreenDelta.x) -
             Mathf.Atan2(oldScreenDelta.y, oldScreenDelta.x)) * Mathf.Rad2Deg;
 }
Esempio n. 2
0
        /// <summary>
        /// Unity Awake callback.
        /// </summary>
        protected virtual void Awake()
        {
            if (!Application.isPlaying)
            {
                return;
            }

            layerManager          = LayerManager.Instance;
            layerProjectionParams = createProjectionParams();
            StartCoroutine(lateAwake());
        }
Esempio n. 3
0
        /// <summary>
        /// Unity Awake callback.
        /// </summary>
        protected virtual void Awake()
        {
            setName();
            if (!Application.isPlaying)
            {
                return;
            }

            layerProjectionParams = createProjectionParams();
            TouchManager.Instance.AddLayer(this, 0, false);
        }
Esempio n. 4
0
        /// <summary>
        /// Unity Awake callback.
        /// </summary>
        protected virtual void Awake()
        {
            setName();
            if (!Application.isPlaying)
            {
                return;
            }

            layerProjectionParams = createProjectionParams();
            StartCoroutine(lateAwake());
        }
        /// <inheritdoc />
        protected override Vector3 doOnePointTranslation(Vector2 oldScreenPos, Vector2 newScreenPos,
                                                         ProjectionParams projectionParams)
        {
            if (isTransforming)
            {
                return new Vector3(newScreenPos.x - oldScreenPos.x, newScreenPos.y - oldScreenPos.y, 0);
            }

            screenPixelTranslationBuffer += newScreenPos - oldScreenPos;
            if (screenPixelTranslationBuffer.sqrMagnitude > screenTransformPixelThresholdSquared)
            {
                isTransforming = true;
                return screenPixelTranslationBuffer;
            }

            return Vector3.zero;
        }
        /// <inheritdoc />
        protected override Vector3 doTwoPointTranslation(Vector2 oldScreenPos1, Vector2 oldScreenPos2,
                                                         Vector2 newScreenPos1, Vector2 newScreenPos2, float dR, float dS, ProjectionParams projectionParams)
        {
            if (isTransforming)
            {
                var transformedPoint = scaleAndRotate(oldScreenPos1, (oldScreenPos1 + oldScreenPos2) * .5f, dR, dS);
                return new Vector3(newScreenPos1.x - transformedPoint.x, newScreenPos1.y - transformedPoint.y, 0);
            }

            screenPixelTranslationBuffer += newScreenPos1 - oldScreenPos1;
            if (screenPixelTranslationBuffer.sqrMagnitude > screenTransformPixelThresholdSquared)
            {
                isTransforming = true;
                oldScreenPos1 = newScreenPos1 - screenPixelTranslationBuffer;
                var transformedPoint = scaleAndRotate(oldScreenPos1, (oldScreenPos1 + oldScreenPos2) * .5f, dR, dS);
                return new Vector3(newScreenPos1.x - transformedPoint.x, newScreenPos1.y - transformedPoint.y, 0);
            }

            return Vector3.zero;
        }
Esempio n. 7
0
 /// <inheritdoc />
 protected override float doScaling(Vector2 oldScreenPos1, Vector2 oldScreenPos2, Vector2 newScreenPos1,
                                    Vector2 newScreenPos2, ProjectionParams projectionParams)
 {
     var newVector = projectionParams.ProjectTo(newScreenPos2, TransformPlane) -
                     projectionParams.ProjectTo(newScreenPos1, TransformPlane);
     var oldVector = projectionParams.ProjectTo(oldScreenPos2, TransformPlane) -
                     projectionParams.ProjectTo(oldScreenPos1, TransformPlane);
     return newVector.magnitude / oldVector.magnitude;
 }
Esempio n. 8
0
 /// <inheritdoc />
 protected override float doRotation(Vector2 oldScreenPos1, Vector2 oldScreenPos2, Vector2 newScreenPos1,
                                     Vector2 newScreenPos2, ProjectionParams projectionParams)
 {
     var newVector = projectionParams.ProjectTo(newScreenPos2, TransformPlane) -
                     projectionParams.ProjectTo(newScreenPos1, TransformPlane);
     var oldVector = projectionParams.ProjectTo(oldScreenPos2, TransformPlane) -
                     projectionParams.ProjectTo(oldScreenPos1, TransformPlane);
     var angle = Vector3.Angle(oldVector, newVector);
     if (Vector3.Dot(Vector3.Cross(oldVector, newVector), TransformPlane.normal) < 0)
         angle = -angle;
     return angle;
 }
Esempio n. 9
0
 /// <summary>
 /// Calculated two finger translation with respect to rotation and scaling.
 /// </summary>
 /// <param name="oldScreenPos1"> Finger one old screen position. </param>
 /// <param name="oldScreenPos2"> Finger two old screen position. </param>
 /// <param name="newScreenPos1"> Finger one new screen position. </param>
 /// <param name="newScreenPos2"> Finger two new screen position. </param>
 /// <param name="dR"> Calculated delta rotation. </param>
 /// <param name="dS"> Calculated delta scaling. </param>
 /// <param name="projectionParams"> Layer projection parameters. </param>
 /// <returns> Delta translation vector. </returns>
 protected virtual Vector3 doTwoPointTranslation(Vector2 oldScreenPos1, Vector2 oldScreenPos2,
                                                 Vector2 newScreenPos1, Vector2 newScreenPos2, float dR, float dS, ProjectionParams projectionParams)
 {
     return Vector3.zero;
 }
Esempio n. 10
0
 /// <summary>
 /// Calculates single finger translation.
 /// </summary>
 /// <param name="oldScreenPos"> Finger old screen position. </param>
 /// <param name="newScreenPos"> Finger new screen position. </param>
 /// <param name="projectionParams"> Layer projection parameters. </param>
 /// <returns> Delta translation vector. </returns>
 protected virtual Vector3 doOnePointTranslation(Vector2 oldScreenPos, Vector2 newScreenPos,
                                                 ProjectionParams projectionParams)
 {
     return Vector3.zero;
 }
        /// <inheritdoc />
        protected override void touchBegan(TouchPoint touch)
        {
            base.touchBegan(touch);

            if (activeTouches.Count == 1) projectionParams = activeTouches[0].ProjectionParams;

            if (touchesNumState == TouchesNumState.PassedMaxThreshold ||
                touchesNumState == TouchesNumState.PassedMinMaxThreshold)
            {
                switch (State)
                {
                    case GestureState.Began:
                    case GestureState.Changed:
                        setState(GestureState.Ended);
                        break;
                }
            }
        }
Esempio n. 12
0
 private float doRotation(Vector3 center, Vector2 oldScreenPos, Vector2 newScreenPos,
                          ProjectionParams projectionParams)
 {
     var newVector = projectionParams.ProjectTo(newScreenPos, TransformPlane) - center;
     var oldVector = projectionParams.ProjectTo(oldScreenPos, TransformPlane) - center;
     var angle = Vector3.Angle(oldVector, newVector);
     if (Vector3.Dot(Vector3.Cross(oldVector, newVector), TransformPlane.normal) < 0)
         angle = -angle;
     return angle;
 }
Esempio n. 13
0
 /// <inheritdoc />
 private Vector3 projectScaledRotated(Vector2 point, float dR, float dS, ProjectionParams projectionParams)
 {
     var delta = projectionParams.ProjectTo(point, TransformPlane) - cachedTransform.position;
     if (dR != 0) delta = Quaternion.AngleAxis(dR, RotationAxis) * delta;
     if (dS != 0) delta = delta * dS;
     return cachedTransform.position + delta;
 }
 /// <inheritdoc />
 protected override float doScaling(Vector2 oldScreenPos1, Vector2 oldScreenPos2, Vector2 newScreenPos1,
                                    Vector2 newScreenPos2, ProjectionParams projectionParams)
 {
     return (newScreenPos2 - newScreenPos1).magnitude / (oldScreenPos2 - oldScreenPos1).magnitude;
 }
Esempio n. 15
0
        /// <summary>
        /// Unity Awake callback.
        /// </summary>
        protected virtual void Awake()
        {
            setName();
            if (!Application.isPlaying) return;

            layerProjectionParams = createProjectionParams();
            TouchManager.Instance.AddLayer(this, 0, false);
        }
Esempio n. 16
0
        /// <inheritdoc />
        protected override Vector3 doOnePointTranslation(Vector2 oldScreenPos, Vector2 newScreenPos,
                                                         ProjectionParams projectionParams)
        {
            if (isTransforming)
            {
                return projectionParams.ProjectTo(newScreenPos, TransformPlane) -
                       projectionParams.ProjectTo(oldScreenPos, TransformPlane);
            }

            screenPixelTranslationBuffer += newScreenPos - oldScreenPos;
            if (screenPixelTranslationBuffer.sqrMagnitude > screenTransformPixelThresholdSquared)
            {
                isTransforming = true;
                return projectionParams.ProjectTo(newScreenPos, TransformPlane) -
                       projectionParams.ProjectTo(newScreenPos - screenPixelTranslationBuffer, TransformPlane);
            }

            return Vector3.zero;
        }
Esempio n. 17
0
        /// <inheritdoc />
        protected override Vector3 doTwoPointTranslation(Vector2 oldScreenPos1, Vector2 oldScreenPos2,
                                                         Vector2 newScreenPos1, Vector2 newScreenPos2, float dR, float dS, ProjectionParams projectionParams)
        {
            if (isTransforming)
            {
                return projectionParams.ProjectTo(newScreenPos1, TransformPlane) - projectScaledRotated(oldScreenPos1, dR, dS, projectionParams);
            }

            screenPixelTranslationBuffer += newScreenPos1 - oldScreenPos1;
            if (screenPixelTranslationBuffer.sqrMagnitude > screenTransformPixelThresholdSquared)
            {
                isTransforming = true;
                return projectionParams.ProjectTo(newScreenPos1, TransformPlane) -
                       projectScaledRotated(newScreenPos1 - screenPixelTranslationBuffer, dR, dS, projectionParams);
            }

            return Vector3.zero;
        }
Esempio n. 18
0
        /// <inheritdoc />
        protected override void touchBegan(TouchPoint touch)
        {
            base.touchBegan(touch);

            if (NumTouches == 1) projectionParams = activeTouches[0].ProjectionParams;

            if (touchesNumState == TouchesNumState.PassedMaxThreshold ||
                touchesNumState == TouchesNumState.PassedMinMaxThreshold)
            {
                switch (State)
                {
                    case GestureState.Began:
                    case GestureState.Changed:
                        setState(GestureState.Ended);
                        break;
                }
            }
#if TOUCHSCRIPT_DEBUG
            else drawDebugDelayed(getNumPoints());
#endif
        }
Esempio n. 19
0
        /// <summary>
        /// Unity Awake callback.
        /// </summary>
        protected virtual void Awake()
        {
            setName();
            if (!Application.isPlaying) return;

            layerProjectionParams = createProjectionParams();
            StartCoroutine(lateAwake());
        }
Esempio n. 20
0
 /// <summary>
 /// Calculates rotation.
 /// </summary>
 /// <param name="oldScreenPos1"> Finger one old screen position. </param>
 /// <param name="oldScreenPos2"> Finger two old screen position. </param>
 /// <param name="newScreenPos1"> Finger one new screen position. </param>
 /// <param name="newScreenPos2"> Finger two new screen position. </param>
 /// <param name="projectionParams"> Layer projection parameters. </param>
 /// <returns> Angle in degrees. </returns>
 protected virtual float doRotation(Vector2 oldScreenPos1, Vector2 oldScreenPos2, Vector2 newScreenPos1,
                                    Vector2 newScreenPos2, ProjectionParams projectionParams)
 {
     return 0;
 }
Esempio n. 21
0
 private float doScaling(Vector3 center, Vector2 oldScreenPos, Vector2 newScreenPos,
                         ProjectionParams projectionParams)
 {
     var newVector = projectionParams.ProjectTo(newScreenPos, TransformPlane) - center;
     var oldVector = projectionParams.ProjectTo(oldScreenPos, TransformPlane) - center;
     return newVector.magnitude / oldVector.magnitude;
 }
Esempio n. 22
0
 /// <summary>
 /// Calculates scaling.
 /// </summary>
 /// <param name="oldScreenPos1"> Finger one old screen position. </param>
 /// <param name="oldScreenPos2"> Finger two old screen position. </param>
 /// <param name="newScreenPos1"> Finger one new screen position. </param>
 /// <param name="newScreenPos2"> Finger two new screen position. </param>
 /// <param name="projectionParams"> Layer projection parameters. </param>
 /// <returns> Multiplicative delta scaling. </returns>
 protected virtual float doScaling(Vector2 oldScreenPos1, Vector2 oldScreenPos2, Vector2 newScreenPos1,
                                   Vector2 newScreenPos2, ProjectionParams projectionParams)
 {
     return 1;
 }