public override void OnInspectorGUI()
        {
            GUILayout.Label("Advanced Gesture States", EditorStyles.boldLabel);
            // do not draw the control variables
            AdvancedGesture advTarget = (AdvancedGesture)target;

            advTarget.gestureCooldown            = EditorGUILayout.FloatField("Cooldown (seconds)", advTarget.gestureCooldown);
            advTarget.allowedWhileHoldingObjects = EditorGUILayout.Toggle("Allow While Holding", advTarget.allowedWhileHoldingObjects);

            foreach (AdvancedGestureState advState in advTarget.advancedGestureStateList)
            {
                DrawAdvancedGestureState(advState);
            }

            if (GUILayout.Button("Add Gesture State"))
            {
                advTarget.advancedGestureStateList.Add(new AdvancedGestureState());
            }

            if (stateToDelete != null)
            {
                advTarget.advancedGestureStateList.Remove(stateToDelete);
                stateToDelete = null;
            }
            // set dirty to ensure the object is saved
            EditorUtility.SetDirty(target);
        }
Ejemplo n.º 2
0
 public override bool IsConditionOccuring(SDK_BaseGestureLibrary.Hand specificHand, AdvancedGesture advancedGestureInfo)
 {
     SDK_BaseGestureLibrary.Hand otherHand = specificHand == SDK_BaseGestureLibrary.Hand.Left ? SDK_BaseGestureLibrary.Hand.Right : SDK_BaseGestureLibrary.Hand.Left;
     return(simultaneousGesture.IsGestureOccuring(otherHand));
 }
Ejemplo n.º 3
0
 public override bool IsConditionOccuring(SDK_BaseGestureLibrary.Hand specificHand, AdvancedGesture advancedGestureInfo)
 {
     return(Time.time >= advancedGestureInfo.gestureStartTime + gestureHoldTime);
 }
Ejemplo n.º 4
0
        public override bool IsConditionOccuring(SDK_BaseGestureLibrary.Hand specificHand, AdvancedGesture advancedGestureInfo)
        {
            SDK_BaseGestureLibrary currentLibrary = VRTK.VRTK_SDK_Bridge.GetHandSDK().GetGestureLibrary();

            if (currentLibrary == null)
            {
                Debug.LogWarning("No gesture library detected for the current Hand SDK");
                return(false);
            }
            Vector3 palmNormal = currentLibrary.GetHandNormal(specificHand);

            if (palmNormal == Vector3.zero)
            {
                // hand tracking lost
                return(false);
            }
            // otherVec is a normal vector that will be compared to the palm vector
            Vector3    otherVec;
            Quaternion rotationToUse = Quaternion.Euler(eulerRotationFromOtherVector);

            if (otherVectorToUse == OtherVector.World)
            {
                switch (otherVectorDirection)
                {
                case VectorType.Forward:
                {
                    otherVec = rotationToUse * Vector3.forward;
                    break;
                }

                case VectorType.Up:
                {
                    otherVec = rotationToUse * Vector3.up;
                    break;
                }

                default:
                {
                    otherVec = rotationToUse * Vector3.up;
                    break;
                }
                }
            }
            else if (otherVectorToUse == OtherVector.Hmd)
            {
                Transform hmd = VRTK_SDK_Bridge.GetHeadset();
                switch (otherVectorDirection)
                {
                case VectorType.Forward:
                {
                    otherVec = hmd.TransformDirection(rotationToUse * Vector3.forward);
                    break;
                }

                case VectorType.Up:
                {
                    otherVec = hmd.TransformDirection(rotationToUse * Vector3.up);
                    break;
                }

                default:
                {
                    otherVec = hmd.TransformDirection(rotationToUse * Vector3.up);
                    break;
                }
                }
            }
            else
            {
                // for whatever reason, otherVec is undefined. return false
                return(false);
            }

            float dotProduct = Vector3.Dot(otherVec, palmNormal);

            // close to 1 -> similar direction
            if (dotProduct >= 1 - tolerance)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        public override bool IsConditionOccuring(SDK_BaseGestureLibrary.Hand specificHand, AdvancedGesture advancedGestureInfo)
        {
            Vector3 palmPosition;
            Vector3 previousPalmPosition;

            if (specificHand == SDK_BaseGestureLibrary.Hand.Left)
            {
                previousPalmPosition = advancedGestureInfo.prevLeftPalmPosition;
                palmPosition         = advancedGestureInfo.GetLeftHandPosition();
            }
            else
            {
                previousPalmPosition = advancedGestureInfo.prevRightPalmPosition;
                palmPosition         = advancedGestureInfo.GetRightHandPosition();
            }

            if (palmPosition == Vector3.zero)
            {
                // vector3 zero is the 'null' for vectors
                return(false);
            }

            float palmMovementDistance = Vector3.Distance(palmPosition, previousPalmPosition);

            // switch statement effectively controls which operator is used when comparing the actual palm movement amount to the desired palm movement amount
            switch (distanceOperator)
            {
            case MovementOperator.LessThan:
            {
                if (palmMovementDistance < distanceFromPreviousGesture)
                {
                    return(true);
                }
                break;
            }

            case MovementOperator.GreaterThan:
            {
                if (palmMovementDistance > distanceFromPreviousGesture)
                {
                    return(true);
                }
                break;
            }

            case MovementOperator.EqualTo:
            {
                if ((distanceFromPreviousGesture - distanceTolerance <= palmMovementDistance && palmMovementDistance <= distanceFromPreviousGesture + distanceTolerance))
                {
                    return(true);
                }
                break;
            }
            }
            return(false);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns true if the condition is occuring and false otherwise, except in the base version which will always return false.
 /// This method is not marked as abstract because Unity cannot serialize classes that have abstract base classes. New Advanced Gesture Conditions
 /// should implement this method.
 /// </summary>
 public virtual bool IsConditionOccuring(SDK_BaseGestureLibrary.Hand specificHand, AdvancedGesture advancedGestureInfo)
 {
     return(false);
 }