예제 #1
0
    private void OnTwoHandManipulationUpdated()
    {
#if UNITY_2017_2_OR_NEWER
        var targetRotation = hostTransform.rotation;
        var targetPosition = hostTransform.position;
        var targetScale    = hostTransform.localScale;

        if ((currentState & ManipulationMode.Move) > 0)
        {
            targetPosition = moveLogic.Update(GetHandsCentroid(), targetPosition);
        }

        if ((currentState & ManipulationMode.Rotate) > 0)
        {
            targetRotation = rotateLogic.Update(handsPressedLocationsMap, hostTransform, targetRotation);
        }

        if ((currentState & ManipulationMode.Scale) > 0)
        {
            targetScale = scaleLogic.UpdateMap(handsPressedLocationsMap);
        }

        hostTransform.position   = targetPosition;
        hostTransform.rotation   = targetRotation;
        hostTransform.localScale = targetScale;
#endif // UNITY_2017_2_OR_NEWER
    }
예제 #2
0
        private void HandleTwoHandManipulationUpdated()
        {
            var targetPosition = hostTransform.position;
            var targetScale    = hostTransform.localScale;

            if ((currentState & State.Moving) > 0)
            {
                targetPosition = m_moveLogic.Update(GetPointersCentroid(), IsNearManipulation());
            }

            var handPositionMap = GetHandPositionMap();

            if ((currentState & State.Rotating) > 0)
            {
                targetRotationTwoHands = m_rotateLogic.Update(handPositionMap, targetRotationTwoHands, constraintOnRotation);
            }
            if ((currentState & State.Scaling) > 0)
            {
                targetScale = m_scaleLogic.UpdateMap(handPositionMap);
            }

            float lerpAmount = GetLerpAmount();

            hostTransform.position = Vector3.Lerp(hostTransform.position, targetPosition, lerpAmount);
            // Currently the two hand rotation algorithm doesn't allow for lerping, but it should. Fix this.
            hostTransform.rotation   = Quaternion.Lerp(hostTransform.rotation, targetRotationTwoHands, lerpAmount);
            hostTransform.localScale = Vector3.Lerp(hostTransform.localScale, targetScale, lerpAmount);
        }
예제 #3
0
        private void OnTwoHandManipulationUpdated()
        {
            var targetRotation = HostTransform.rotation;
            var targetPosition = HostTransform.position;

            if ((currentState & State.Moving) > 0)
            {
                targetPosition = m_moveLogic.Update(GetHandsCentroid(), targetPosition);
            }
            if ((currentState & State.Rotating) > 0)
            {
                targetRotation = m_rotateLogic.Update(m_handsPressedLocationsMap, HostTransform, targetRotation);
            }

            HostTransform.position = targetPosition;
            HostTransform.rotation = targetRotation;
        }
예제 #4
0
        private void OnTwoHandManipulationUpdated()
        {
            var targetRotation = hostTransform.rotation;
            var targetPosition = hostTransform.position;
            var targetScale    = hostTransform.localScale;

            if ((currentState & State.Moving) > 0)
            {
                targetPosition = m_moveLogic.Update(gazeHandHelper.GetHandsCentroid(), targetPosition);
            }
            if ((currentState & State.Rotating) > 0)
            {
                targetRotation = m_rotateLogic.Update(gazeHandHelper.GetHandPositionsDictionary(), targetRotation);
            }
            if ((currentState & State.Scaling) > 0)
            {
                targetScale = m_scaleLogic.UpdateMap(gazeHandHelper.GetHandPositionsDictionary());
            }

            hostTransform.position   = targetPosition;
            hostTransform.rotation   = targetRotation;
            hostTransform.localScale = targetScale;
        }
예제 #5
0
        void ProcessInputs()
        {
            int numberOfInputs = m_InputSource.NumberOfActiveInputs;

            if (numberOfInputs == 1 && m_CurrentGestureType == GestureType.Single)
            {
                MixedRealityPose inputCentroid     = new MixedRealityPose(ComputeInputCentroid());
                Vector3          displacementDelta = inputCentroid.Position - m_TwoFingerTouchStartCentroid.Position;

                //displacementDelta = Quaternion.Inverse(m_TargetTransform.rotation) * displacementDelta;

                /*
                 * float xAngle = Mathf.Repeat(-displacementDelta.x * m_Sensitivity, 360f);
                 * float yAngle = Mathf.Repeat(-displacementDelta.y * m_Sensitivity, 360f);
                 *
                 * Quaternion deltaRot = Quaternion.Euler(yAngle, xAngle, 0f);
                 * Quaternion newRotTarget = m_ObjectStartPose.Rotation * deltaRot;
                 *
                 *
                 *
                 * m_CurrentTransformDecayTime = m_TransformDecayTime;
                 */

                Vector3 newMoveTarget = moveLogic.Update(inputCentroid, m_TargetTransform.rotation, m_TargetTransform.localScale, false);
                Vector3 panDelta      = (newMoveTarget - m_ObjectStartPose.Position) * m_PanTransformSpeed;

                m_DeltaPosition             = panDelta;
                m_DeltaRotation             = Quaternion.identity;
                m_CurrentTransformDecayTime = m_TransformDecayTime;
            }
            if (numberOfInputs == 2 && m_CurrentGestureType == GestureType.Multi)
            {
                Vector3    f1           = new Vector3(InputArray[0].x, 0f, InputArray[0].y);
                Vector3    f2           = new Vector3(InputArray[1].x, 0f, InputArray[1].y);
                Quaternion newRotTarget = rotationLogic.Update(new Vector3[] { f1, f2 });

                float newScaleRatio = scaleLogic.GetScaleRatioMultiplier(InputArray);
                if (newScaleRatio < 1)
                {
                    // Invert scale factor and make it negative to move in reverse
                    newScaleRatio = Mathf.Clamp(-((1 / newScaleRatio) - 1), -5f, 0f);
                }
                else
                {
                    newScaleRatio = Mathf.Clamp(newScaleRatio - 1, 0f, 5f);
                }

                float   newScaleDistance = newScaleRatio * m_ScaleGestureDistance;
                Vector3 scaleDirection   = m_ObjectStartPose.Rotation * Vector3.forward * newScaleDistance;
                Vector3 targetPosition   = m_ObjectStartPose.Position + scaleDirection;

                m_DeltaPosition = targetPosition - m_ObjectStartPose.Position;
                m_DeltaRotation = newRotTarget * Quaternion.Inverse(m_ObjectStartPose.Rotation);

                //ComputeInertialParameters(targetPosition, newRotTarget);
                m_CurrentTransformDecayTime = m_TransformDecayTime;
            }

            if (numberOfInputs == 0)
            {
                m_CurrentGestureType = GestureType.None;
            }

            DegradeInertialParameters();
            m_TargetPosition = m_TargetTransform.position + m_DeltaPosition;
            m_TargetRotation = m_ObjectStartPose.Rotation * m_DeltaRotation;
        }