Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
        // Pointers pressed this frame
        protected override void pointersPressed(IList <Pointer> pointers)
        {
            if (State == GestureState.Idle)
            {
                primaryPointer = pointers[0];
                projection     = primaryPointer.GetPressData().Layer.GetProjectionParams(primaryPointer);
                plane          = new Plane(Vector3.up, transform.position);
                startPosition  = projection.ProjectTo(primaryPointer.Position, plane);

                // Start the gesture
                setState(GestureState.Began);
            }
        }
Ejemplo n.º 8
0
        protected 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);
        }