Example #1
0
        private void OnTriggerEnter(Collider other)
        {
            if ((DateTime.Now - lastObjectDestroyTime).TotalSeconds < Globals.SHELF_GESTURE_WAITING_PERIOD)
            {
                return;
            }

            var animScript = other.GetComponent <Animatable>();

            if (animScript != null && animScript.Creator != null &&
                animScript.Creator.GetInstanceID() == GetInstanceID())
            {
                animScript.Deselected();
                GestureManager.ProcessObjectDeletion(animScript);
                Destroy(animScript.gameObject);
                lastObjectDestroyTime = DateTime.Now;
                return;
            }

            PoseManager.GetJointFromGameobjectName(other.name, out OvrAvatar.HandType hand, out PoseManager.HandJoint joint);

            if (joint == PoseManager.HandJoint.IndexTip)
            {
                GestureManager.TryInstantiatingAnimatable(hand, this);
            }
        }
        void Start()
        {
            PoseManager.OnLeftHandStartPinch  += LeftHandPinchStartHandler;
            PoseManager.OnRightHandStartPinch += RightHandPinchStartHandler;

            PoseManager.OnLeftHandStopPinch  += LeftHandPinchStopHandler;
            PoseManager.OnRightHandStopPinch += RightHandPinchStopHandler;

            PoseManager.OnLeftHandStartPoint  += LeftHandPointStartHandler;
            PoseManager.OnRightHandStartPoint += RightHandPointStartHandler;

            PoseManager.OnLeftHandStopPoint  += LeftHandPointStopHandler;
            PoseManager.OnRightHandStopPoint += RightHandPointStopHandler;

            PoseManager.OnLeftHandStartAlmostPoint  += LeftHandAlmostPointStartHandler;
            PoseManager.OnRightHandStartAlmostPoint += RightHandAlmostPointStartHandler;

            PoseManager.OnLeftHandStopAlmostPoint  += LeftHandAlmostPointStopHandler;
            PoseManager.OnRightHandStopAlmostPoint += RightHandAlmostPointStopHandler;

            PoseManager.OnLeftHandStartGrab  += LeftHandGrabStartHandler;
            PoseManager.OnRightHandStartGrab += RightHandGrabStartHandler;

            PoseManager.OnLeftHandStartGrab += LeftHandGrabStopHandler;
            PoseManager.OnRightHandStopGrab += RightHandGrabStopHandler;

            PoseManager.OnIntersectionStart += IntersectionStartHandler;
            PoseManager.OnIntersectionEnd   += IntersectionEndHandler;

            poseManager = FindObjectOfType <PoseManager>();

            rotationAxisUI.GetComponent <Renderer>().enabled = false;
        }
Example #3
0
        private void OnTriggerExit(Collider other)
        {
            PoseManager.OnHandObjectCollisionEnd(this, other.gameObject);

            PoseManager.GetJointFromGameobjectName(other.name, out OvrAvatar.HandType hand, out PoseManager.HandJoint joint);
            if (joint != PoseManager.HandJoint.IndexTip)
            {
                return;
            }

            CurJointIntersectionCount--;

            if (CurJointIntersectionCount == 0)
            {
                foreach (var elem in ApproachUI)
                {
                    elem.enabled = false;
                }

                if (isSelected)
                {
                    foreach (var elem in SelectUI)
                    {
                        elem.enabled = true;
                    }
                }
            }
        }
Example #4
0
        private void Update()
        {
            if (EmissionConeDrawingInProgress)
            {
                rightPos.Add(animScript.poseManager.GetHandTransform(OvrAvatar.HandType.Right, Globals.EMISSION_GESTURE_JOINT).position);
                leftPos.Add(animScript.poseManager.GetHandTransform(OvrAvatar.HandType.Left, Globals.EMISSION_GESTURE_JOINT).position);
                times.Add((float)(DateTime.Now - coneDrawingStartTime).TotalSeconds);

                if (times.Count % 10 == 0)
                {
                    AddPointToEmissionUI(transform.InverseTransformPoint(leftPos.Last()), transform.InverseTransformPoint(rightPos.Last()));
                }
            }
            else if (ConeGestureInProgress)
            {
                var pos = animScript.poseManager.GetHandTransform(OvrAvatar.HandType.Right, PoseManager.HandJoint.IndexTip).position;
                var vel = PoseManager.GetHandVelocity(OvrAvatar.HandType.Right);
                var acc = PoseManager.GetHandAcceleration(OvrAvatar.HandType.Right);

                coneGesturePositionData.Add(transform.InverseTransformPoint(pos));
                coneGestureVelocityData.Add(transform.InverseTransformVector(vel));
                coneGestureAccelerationData.Add(transform.InverseTransformVector(acc));
                coneGestureTimeData.Add((DateTime.Now - coneGestureStartTime).TotalSeconds);

                GetComponent <LineRenderer>().positionCount++;
                GetComponent <LineRenderer>().SetPosition(
                    GetComponent <LineRenderer>().positionCount - 1,
                    transform.InverseTransformPoint(pos));
            }
        }
Example #5
0
        private void OnTriggerExit(Collider other)
        {
            PoseManager.GetJointFromGameobjectName(other.name, out OvrAvatar.HandType hand, out PoseManager.HandJoint joint);

            if (joint == PoseManager.HandJoint.IndexTip)
            {
                isOn = false;
                SwitchState();
            }
        }
Example #6
0
        private void OnTriggerEnter(Collider other)
        {
            PoseManager.GetJointFromGameobjectName(other.name, out OvrAvatar.HandType hand, out PoseManager.HandJoint joint);

            if (joint == PoseManager.HandJoint.IndexTip &&
                (DateTime.Now - stateSwitchTime).TotalSeconds >= Globals.UI_BUTTON_WAIT_TIME)
            {
                SwitchState();
                callback?.Invoke();
            }
        }
Example #7
0
        void Start()
        {
            poseManager = FindObjectOfType <PoseManager>();

            initialObjectPose = new GameObject();
            initialObjectPose.SetActive(false);

            foreach (var obj in PreRegisteredObjects)
            {
                obj.Init(null);
            }
        }
Example #8
0
 private void OnTriggerExit(Collider other)
 {
     PoseManager.GetJointFromGameobjectName(other.name, out OvrAvatar.HandType hand, out PoseManager.HandJoint joint);
     if (hand == OvrAvatar.HandType.Right && joint == PoseManager.HandJoint.IndexTip)
     {
         activeIntersections = Mathf.Max(activeIntersections - 1, 0);
         if (activeIntersections == 0)
         {
             emitter.EnableEmissionConeGestures = false;
             //Debug.Log("Disabling interactions with emission cone!");
         }
     }
     PoseManager.OnHandObjectCollisionEnd(animScript, other.gameObject);
 }
Example #9
0
        private void OnTriggerStay(Collider other)
        {
            if ((DateTime.Now - lastObjectDestroyTime).TotalSeconds < Globals.SHELF_GESTURE_WAITING_PERIOD)
            {
                return;
            }

            PoseManager.GetJointFromGameobjectName(other.name, out OvrAvatar.HandType hand, out PoseManager.HandJoint joint);

            if (joint == PoseManager.HandJoint.IndexTip)
            {
                GestureManager.TryInstantiatingAnimatable(hand, this);
            }
        }
Example #10
0
        private void OnTriggerStay(Collider other)
        {
            if (DisallowMultiple)
            {
                return;
            }

            PoseManager.GetJointFromGameobjectName(other.name, out OvrAvatar.HandType hand, out PoseManager.HandJoint joint);

            if (joint == PoseManager.HandJoint.IndexTip &&
                (DateTime.Now - lastActionTime).TotalSeconds >= 0.1f)
            {
                callback?.Invoke();
                lastActionTime = DateTime.Now;
            }
        }
Example #11
0
        private void OnTriggerEnter(Collider other)
        {
            PoseManager.OnHandObjectCollisionStart(this, other.gameObject);

            PoseManager.GetJointFromGameobjectName(other.name, out OvrAvatar.HandType hand, out PoseManager.HandJoint joint);
            if (joint != PoseManager.HandJoint.IndexTip)
            {
                return;
            }

            foreach (var elem in ApproachUI)
            {
                elem.enabled = true;
            }

            CurJointIntersectionCount++;
        }
Example #12
0
        // Update is called once per frame
        void Update()
        {
            if (Input.GetKeyUp(KeyCode.P))
            {
                TimeManager.SwitchAnimationPlayState();
            }

            if (Input.GetKeyUp(KeyCode.R))
            {
                TimeManager.SwitchRecordingState();
            }

            switch (RecognitionState)
            {
            case GestureRecognizerState.Default:
                if (rightInteracting.Count > 0)
                {
                    SetRecognitionState(GestureRecognizerState.Recognizing);
                }
                else if (leftInteracting.Count > 0)
                {
                    SetRecognitionState(GestureRecognizerState.Recognizing);
                }
                else if (TimeManager.SelectedObject != null)
                {
                    SetRecognitionState(GestureRecognizerState.Recognizing);
                }
                break;

            case GestureRecognizerState.Recognizing:
                if (rightInteracting.Count == 0 && leftInteracting.Count == 0 && TimeManager.SelectedObject == null)
                {
                    SetRecognitionState(GestureRecognizerState.Default);
                }
                // Wait for a bit before we infer which gesture to execute
                // when the right hand is in pinched position
                else if (rightInteracting.Count > 0 &&
                         rightPinchOn &&
                         (DateTime.Now - rightPinchOnTime).TotalSeconds > Globals.GESTURE_WAIT_TIME)
                {
                    // if left hand is also pinched onto an object, then execute scaling gesture
                    if (leftInteracting.Count > 0 && leftPinchOn)
                    {
                        SetRecognitionState(GestureRecognizerState.Scaling);
                        ProcessScalingGesture();
                    }
                    // otherwise, translate
                    else
                    {
                        SetRecognitionState(GestureRecognizerState.Translating);
                        ProcessTranslationGesture();
                    }
                }
                //show rotating axis
                else if (rightInteracting.Count > 0 &&
                         rightPointOn &&
                         (DateTime.Now - rightPointOnTime).TotalSeconds > Globals.GESTURE_WAIT_TIME)
                {
                    SetRecognitionState(GestureRecognizerState.ReadyToRotate);
                    TimeManager.KeepOldRotationAxis = false;
                    ProcessRotationAxisGesture();
                }
                // Can try to recognize an emission cone gesture if
                // 1. an emitter is selected,
                // 2. both hands have the same pose, and
                // 3. some constraints on their positions w.r.t emitter and each other??
                else if (TimeManager.SelectedObject != null &&
                         TimeManager.SelectedObject.GetComponent <ParticleEmitter>() != null &&
                         PoseManager.GetHandShape(OvrAvatar.HandType.Right) == PoseManager.GetHandShape(OvrAvatar.HandType.Left) &&
                         PoseManager.GetHandShape(OvrAvatar.HandType.Right).HasFlag(PoseManager.HandShape.Fist))
                {
                    var selected = TimeManager.SelectedObject;
                    var leftPos  = poseManager.GetHandTransform(OvrAvatar.HandType.Left, Globals.EMISSION_GESTURE_JOINT).position;
                    var rightPos = poseManager.GetHandTransform(OvrAvatar.HandType.Right, Globals.EMISSION_GESTURE_JOINT).position;
                    leftPos  = selected.transform.InverseTransformPoint(leftPos);
                    rightPos = selected.transform.InverseTransformPoint(rightPos);
                    var leftPosProj  = new Vector2(leftPos.x, leftPos.y);
                    var rightPosProj = new Vector2(rightPos.x, rightPos.y);

                    if (Vector2.Dot(-leftPosProj.normalized, rightPosProj.normalized) > 0.6f &&
                        leftPos.sqrMagnitude / rightPos.sqrMagnitude <= 2.0f &&
                        rightPos.sqrMagnitude / leftPos.sqrMagnitude <= 2.0f &&
                        Mathf.Max(Mathf.Abs(leftPos.z), Mathf.Abs(rightPos.z)) <= 0.2f / selected.transform.lossyScale.z)
                    {
                        SetRecognitionState(GestureRecognizerState.DrawingEmissionCone);
                        ProcessEmissionConeGestureStart();
                    }
                }
                else if (rightInteracting.Count == 0 && rightAlmostPointOn)
                {
                    tapGestureStartTime = DateTime.Now;
                    SetRecognitionState(GestureRecognizerState.ReadyToSelect);
                }
                break;

            case GestureRecognizerState.Scaling:
                if (rightInteracting.Count == 0)
                {
                    TimeManager.StopTransforming(RecognitionState);
                    SetRecognitionState(GestureRecognizerState.Default);
                }
                else if (leftInteracting.Count == 0)
                {
                    TimeManager.StopTransforming(RecognitionState);
                    SetRecognitionState(GestureRecognizerState.Recognizing);
                }
                break;

            case GestureRecognizerState.Translating:
                if (rightInteracting.Count == 0)
                {
                    TimeManager.StopTransforming(RecognitionState);
                    SetRecognitionState(GestureRecognizerState.Default);
                }
                break;

            case GestureRecognizerState.Rotating:
                // Interaction ended: Go back to default state
                if (rightInteracting.Count == 0)
                {
                    TimeManager.StopTransforming(RecognitionState);
                    SetRecognitionState(GestureRecognizerState.Default);
                    ProcessRotationEnd();
                }
                // Current rotation ended, but user might be taking a break
                // Keep showing the axis of rotation
                else if (!(leftPinchOn || leftPointOn))
                {
                    TimeManager.StopTransforming(RecognitionState);
                    SetRecognitionState(GestureRecognizerState.ReadyToRotate);
                    TimeManager.KeepOldRotationAxis = true;
                }
                break;

            case GestureRecognizerState.ReadyToRotate:
                // Interaction ended: Go back to default state
                if (rightInteracting.Count == 0)
                {
                    SetRecognitionState(GestureRecognizerState.Default);
                    ProcessRotationCancellation();
                }
                // Starte computing the rotation deltas
                else if (leftPointOn || leftPinchOn)
                {
                    SetRecognitionState(GestureRecognizerState.Rotating);
                    ProcessRotationGesture();
                }
                // Try to recognize "Tap" gesture
                else if (!rightPointOn && rightAlmostPointOn)
                {
                    tapGestureStartTime = DateTime.Now;
                    SetRecognitionState(GestureRecognizerState.ReadyToSelect);
                    ProcessRotationCancellation();
                }
                // Otherwise, just recompute the selected object and the rotation axis
                else
                {
                    ProcessRotationAxisGesture();
                }
                break;

            case GestureRecognizerState.ReadyToSelect:
                // Pointing right finger again
                if (rightPointOn)
                {
                    // If the amount of time spent "almost-pointing" was small, execute selection command
                    if ((DateTime.Now - tapGestureStartTime).TotalSeconds < Globals.TAP_GESTURE_MAX_TIME)
                    {
                        Debug.Log("Selecting...");
                        ProcessTapGesture();
                        tapGestureStartTime = DateTime.MinValue;
                    }
                    // Else, ignore and try to go back to "Ready-to-rotate" state
                    else
                    {
                        if (rightInteracting.Count > 0)
                        {
                            SetRecognitionState(GestureRecognizerState.ReadyToRotate);
                            TimeManager.KeepOldRotationAxis = false;
                            ProcessRotationAxisGesture();
                        }
                        else
                        {
                            SetRecognitionState(GestureRecognizerState.Default);
                        }
                    }
                }
                break;

            case GestureRecognizerState.AfterSelectGesture:
                // Ignore all other hand pose changes until an object is selected
                if (rightInteracting.Count == 0)
                {
                    SetRecognitionState(GestureRecognizerState.Default);
                }
                break;

            case GestureRecognizerState.ReadyForConeGesture:
                // hand exited cone
                if (emitterReceivingConeGestures.EnableEmissionConeGestures == false)
                {
                    SetRecognitionState(GestureRecognizerState.Default);
                }
                // If right hand is in an active pose, start recording
                else if (rightPointOn || rightPinchOn || rightGrabOn)
                {
                    SetRecognitionState(GestureRecognizerState.RecognizingConeGesture);
                    emitterReceivingConeGestures.ConeGestureStarted();
                }
                break;

            case GestureRecognizerState.RecognizingConeGesture:
                if (!(rightPointOn || rightPinchOn || rightGrabOn))
                {
                    SetRecognitionState(GestureRecognizerState.ReadyForConeGesture);
                    emitterReceivingConeGestures.ConeGestureFinished();
                }
                break;

            case GestureRecognizerState.Instantiating:
                if (
                    (HandInstantiatingObject == OvrAvatar.HandType.Right &&
                     (rightAlmostPointOn || rightPointOn || rightGrabOn || rightPinchOn)) ||
                    (HandInstantiatingObject == OvrAvatar.HandType.Left &&
                     (leftAlmostPointOn || leftPointOn || leftGrabOn || leftPinchOn))
                    )
                {
                    var fingerPos = poseManager.GetHandTransform(HandInstantiatingObject, PoseManager.HandJoint.IndexTip).position;
                    ObjectBeingInstantiated.transform.position = fingerPos;
                }
                else
                {
                    // If the object is within the bounds of an emitter
                    // then set it to be the particle mesh
                    var             colliders     = Physics.OverlapSphere(poseManager.GetHandTransform(HandInstantiatingObject, PoseManager.HandJoint.IndexTip).position, 0.01f);
                    ParticleEmitter targetEmitter = null;
                    foreach (var collider in colliders)
                    {
                        if (collider.gameObject.GetInstanceID() != ObjectBeingInstantiated.gameObject.GetInstanceID() &&
                            collider.GetComponent <ParticleEmitter>() != null)
                        {
                            targetEmitter = collider.GetComponent <ParticleEmitter>();
                            break;
                        }
                    }

                    if (targetEmitter != null && ObjectInstantiator.ParticlePrefab != null)
                    {
                        targetEmitter.TryChangeParticleShapeFromDroppedObject(ObjectInstantiator);
                        Destroy(ObjectBeingInstantiated.gameObject);
                        SetRecognitionState(GestureRecognizerState.Default);
                    }
                    // Otherwise, instatiate as an Animatable
                    else
                    {
                        ObjectBeingInstantiated.Init(ObjectInstantiator);
                        SetRecognitionState(GestureRecognizerState.Default);
                    }
                }
                break;
            }
        }
Example #13
0
 private void OnTriggerStay(Collider other)
 {
     PoseManager.OnHandObjectCollisionStay(this, other.gameObject);
 }
Example #14
0
 private void OnDestroy()
 {
     TimeManager.DeregisterObject(this);
     PoseManager.DeleteReferencesToObject(this);
 }