示例#1
0
        private void OnTriggerEnter(Collider collider)
        {
            //Check if the collider represents a hand
            if (_handInTrigger == null)
            {
                HandFeature hand = collider.GetComponent <HandFeature>();

                //Check if the hand has a top point
                if (hand != null && hand is TopHandFeature)
                {
                    Vector3 localHandPosition = transform.InverseTransformPoint(hand.transform.position);
                    Vector3 localPressCenter  = transform.InverseTransformPoint(GetPressCenter());

                    if (localHandPosition.z < localPressCenter.z || hand == _handThatExitedWhileHeld)
                    {
                        _handInTrigger = hand;

                        if (_canvasCursor != null)
                        {
                            _canvasCursor.Show();
                        }
                    }
                    else if (localHandPosition.z >= localPressCenter.z)
                    {
                        //Start a check for when the hand is in a good position
                        if (_checkForAcceptableHandPositionCoroutine != null)
                        {
                            StopCoroutine(_checkForAcceptableHandPositionCoroutine);
                        }

                        _checkForAcceptableHandPositionCoroutine = StartCoroutine(CheckForAcceptableHandPosition(hand));
                    }
                }
            }
        }
示例#2
0
        private IEnumerator BackExit()
        {
            float elapsed    = 0;
            bool  handBackIn = false;

            while (elapsed < 1 && !handBackIn)
            {
                yield return(null);

                elapsed += Time.deltaTime;

                if (_handInTrigger != null && _handInTrigger == _handThatExitedWhileHeld)
                {
                    handBackIn = true;
                }
            }

            if (!handBackIn)
            {
                _pointerData.Reset();
                _pointerData.pointerCurrentRaycast = new RaycastResult();
                _pressState             = PressState.Released;
                _pointerData.IsCanceled = true;
                _raycaster.ProcessHandEvent(_pointerData, false, true);
                _handThatExitedWhileHeld = null;
            }
        }
 private void SwipeOn(HandFeature hf)
 {
     _engaged = true;
     SwipeX   = GetHandsXPosition(hf);
     DeltaX   = 0f;
     _swipePlaneEngaged.Invoke();
 }
示例#4
0
        private IEnumerator CheckForAcceptableHandPosition(HandFeature hand)
        {
            Vector3 localPressCenter = transform.InverseTransformPoint(GetPressCenter());

            while (hand != null)
            {
                Vector3 localHandPosition = transform.InverseTransformPoint(hand.transform.position);

                if (localHandPosition.z < localPressCenter.z)
                {
                    _handInTrigger = hand;

                    if (_canvasCursor != null)
                    {
                        _canvasCursor.Show();
                    }

                    break;
                }

                yield return(null);
            }

            _checkForAcceptableHandPositionCoroutine = null;
        }
 public void OnHandFeatureEnter(HandFeature handFeature)
 {
     if (handFeature is TopHandFeature && _handFeature == null)
     {
         _handFeature = handFeature;
         Engage();
     }
 }
        private void UpdateSwipeTravel(HandFeature hf)
        {
            float newHandX   = GetHandsXPosition(hf);
            float priorHandX = SwipeX;

            SwipeX = SMOOTHING * SwipeX + (1f - SMOOTHING) * newHandX;
            DeltaX = SwipeX - priorHandX;
        }
 public void OnHandFeatureExit <T>(T handFeature) where T : HandFeature
 {
     if (handFeature is TopHandFeature && _handFeature == handFeature)
     {
         _handFeature = null;
         Disengage();
     }
 }
示例#8
0
 private void SwipeOn(HandFeature hf)
 {
     _engaged = true;
     SwipeX   = GetHandsXval(hf);
     SwipeY   = GetHandsYval(hf);
     DeltaX   = 0f;
     DeltaY   = 0f;
     _swipePlaneEngaged.Invoke();
 }
示例#9
0
        protected override void Engage()
        {
            _handFeature = GrabbingHands[0];

            //rigidbody should be kinematic as to not interfere with grab translation
            SetIsKinematic(true);

            SetGrabOffset(_handFeature.Position);
        }
        protected override void Engage()
        {
            _handFeature = GrabbingHands[0];

            PrepareRigidbodyForInteraction();

            // Store the offset of the object local to the hand feature.  This will be used to keep the object at the same distance from the hand when being moved.

            SetHandOffsets();
        }
示例#11
0
        protected override void Engage()
        {
            _handFeature = GrabbingHands[0];

            //rigidbody should be kinematic as to not interfere with grab translation
            SetIsKinematic(true);

            // Store the offset of the object local to the hand feature.  This will be used to keep the object at the same distance from the hand when being moved.
            _localOffset = _handFeature.transform.InverseTransformDirection(TargetTransform.position - _handFeature.Position);
            SetGrabOffset(TransformedHandPos());
        }
        protected override void Disengage()
        {
            //Enable Quad Video to change position
            GameObject quad = GameObject.Find("Quad");

            metaContext.Get <HudLock>().RemoveHudLockedObject(quad.GetComponent <MetaLocking>());
            metaContext.Get <HudLock>().AddHudLockedObject(quad.GetComponent <MetaLocking>());

            SetIsKinematic(false);
            _handFeature = null;
        }
    protected override void Engage()
    {
        _handFeature = GrabbingHands[0];

        if (_heldGameObject == null)
        {
            _heldGameObject = Instantiate(_prefab);
        }

        _heldGameObject.transform.position = _handFeature.transform.position;
        _heldGameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;
    }
示例#14
0
 protected override bool CanDisengage(Hand handProxy)
 {
     if (_handFeature != null && handProxy.Palm == _handFeature)
     {
         foreach (var hand in GrabbingHands)
         {
             if (hand != _handFeature)
             {
                 _handFeature = hand;
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
示例#15
0
    public float GetFeature(HandFeature feature)
    {
        switch (feature)
        {
        case HandFeature.RingMiddlePinkyClosed:

            break;

        case HandFeature.Openness:
            return(HandOpenness());

            break;

        case HandFeature.Spread:
            // TODO
            break;
        }
        return(0f);
    }
示例#16
0
        private void OnTriggerExit(Collider collider)
        {
            //Check if the collider represents a hand
            HandFeature hand = collider.GetComponent <HandFeature>();

            //Check if the first hand exited, in case multiple hands are in the EventVolume
            if (hand != null && _handInTrigger == hand)
            {
                _handInTrigger = null;

                if (_canvasCursor != null)
                {
                    _canvasCursor.Hide();
                }

                //ReleaseToSeat on EventVolume exit if being held
                if (_pressState == PressState.Held)
                {
                    Vector3 localHandPosition = transform.InverseTransformPoint(hand.transform.position);
                    Vector3 localBack         = transform.InverseTransformPoint(_collider.bounds.max);

                    if (localHandPosition.z < localBack.z)
                    {
                        _handThatExitedWhileHeld = hand;

                        _pointerData.Reset();
                        _pointerData.pointerCurrentRaycast = new RaycastResult();
                        _pressState = PressState.Released;
                        _raycaster.ProcessHandEvent(_pointerData, false, true);
                    }
                    else
                    {
                        StopCoroutine(BackExit());
                        StartCoroutine(BackExit());
                    }
                }
            }
        }
示例#17
0
 protected override void Engage()
 {
     _handFeature = GrabbingHands[0];
 }
示例#18
0
    // Update is called once per frame
    void Update()
    {
        leftScore  = Mathf.Max(0, leftScore - .016f);
        rightScore = Mathf.Max(0, rightScore - .032f);

        // left right should be no more than 30 deg
        // Check if both hands are tracked
        Locked = leftHand.IsTracked && rightHand.IsTracked;

        // Up/down should be no more than 15 deg
        // Check up down angle
        if (leftHand.Handedness == Chirality.Left && leftHand.IsTracked && leftHand.GetLeapHand() != null)
        {
            //leftHand;
            Leap.Hand hand      = leftHand.GetLeapHand();
            var       arm       = hand.Arm;
            Vector3   right     = arm.Basis.xBasis.ToVector3() * arm.Width * 0.7f * 0.5f;
            Vector3   wrist     = arm.WristPosition.ToVector3();
            Vector3   elbow     = arm.ElbowPosition.ToVector3();
            float     armLength = Vector3.Distance(wrist, elbow);
            wrist -= arm.Direction.ToVector3() * armLength * 0.05f;
            Vector3 thumbBase         = leftHand.getThumbBase();
            Vector3 mockThumbBase     = leftHand.getMockThumbBase();
            Vector3 leftArmFrontRight = wrist + right;
            Vector3 leftArmFrontLeft  = wrist - right;
            leftLeft  = Vector3.Distance(leftArmFrontRight, mockThumbBase);
            leftRight = Vector3.Distance(leftArmFrontLeft, thumbBase);


            leftOrientation = Mathf.Rad2Deg * (hand.Direction.AngleTo(arm.Direction));



            // Get up/down
            Vector3 leftPalmNorm = -hand.PalmNormal.ToVector3();
            Vector3 leftArm      = hand.Arm.Direction.ToVector3();
            angleL = Vector3.Angle(leftArm, leftPalmNorm);
        }
        if (rightHand.Handedness == Chirality.Right && rightHand.IsTracked && rightHand.GetLeapHand() != null)
        {
            //leftHand;
            Leap.Hand hand      = rightHand.GetLeapHand();
            var       arm       = hand.Arm;
            Vector3   right     = arm.Basis.xBasis.ToVector3() * arm.Width * 0.7f * 0.5f;
            Vector3   wrist     = arm.WristPosition.ToVector3();
            Vector3   elbow     = arm.ElbowPosition.ToVector3();
            float     armLength = Vector3.Distance(wrist, elbow);
            wrist -= arm.Direction.ToVector3() * armLength * 0.05f;
            Vector3 thumbBase          = rightHand.getThumbBase();
            Vector3 mockThumbBase      = rightHand.getMockThumbBase();
            Vector3 rightArmFrontRight = wrist + right;
            Vector3 rightArmFrontLeft  = wrist - right;
            rightLeft  = Vector3.Distance(rightArmFrontRight, mockThumbBase);
            rightRight = Vector3.Distance(rightArmFrontLeft, thumbBase);
            // Get up/down
            Vector3 leftPalmNorm = -hand.PalmNormal.ToVector3();
            Vector3 leftArm      = hand.Arm.Direction.ToVector3();
            angleR = Vector3.Angle(leftArm, leftPalmNorm);

            rightOrientation = Mathf.Rad2Deg * (hand.Direction.AngleTo(arm.Direction));
        }
        if (Locked)
        {
            //Debug.Log(leftLeft + " " + leftRight + "::" + rightLeft+" " + rightRight);
            badL = 0;
            badR = 0;
            if (useServer)
            {
                if (sent)
                {
                    HandFeature data = _connector.getData();
                    if (data != null)
                    {
                        badL = data.badL;
                        badR = data.badR;
                        sent = false;
                    }
                }
                else
                {
                    _connector.sendData(angleL, angleR, leftLeft, leftRight, rightLeft, rightRight, leftOrientation, rightOrientation, Locked, badL, badR);
                    sent = true;
                }
            }
            else
            {
                if ((Mathf.Abs(angleL - target) > tolerance || (leftOrientation >= 35)))
                {
                    //Debug.Log(leftOrientation + " " + rightOrientation + " bad");
                    badL = 1;
                    //Debug.Log("Bad");
                }
                if ((Mathf.Abs(angleR - target) > tolerance || (rightOrientation >= 35)))
                {
                    //Debug.Log(leftOrientation + " " + rightOrientation + " bad");
                    badR = 1;
                    //Debug.Log("Bad");
                }
            }



            leftScore  = Mathf.Min(100, leftScore + ((float)badL) / 20);
            rightScore = Mathf.Min(100, rightScore + ((float)badR) / 25);
            try
            {
                leftHand.updateMatColor(colorScale.Evaluate(leftScore));
                rightHand.updateMatColor(colorScale.Evaluate(rightScore));
            }
            catch (MissingComponentException)
            {
            }
        }
        else
        {
            badL = 0;
            badR = 0;
        }
        if (badL == 1 || badR == 1)
        {
            // Some visual
            if (Time.time - lastErr >= timeout)
            {
                lastErr = Time.time;
                if (badStuff != null)
                {
                    badStuff.Play();
                }
            }
        }
        //Debug.Log(badL + " " + badR);
        rowDataLeft[0] = "" + angleL;
        rowDataLeft[1] = "" + leftLeft;
        rowDataLeft[2] = "" + leftRight;
        rowDataLeft[3] = "" + leftOrientation;
        rowDataLeft[4] = "" + badL;
        rowDataLeft[5] = "" + Locked;

        rowDataRight[0] = "" + angleR;
        rowDataRight[1] = "" + rightLeft;
        rowDataRight[2] = "" + rightRight;
        rowDataRight[3] = "" + rightOrientation;
        rowDataRight[4] = "" + badR;
        rowDataRight[5] = "" + Locked;

        string        delimiter = ",";
        StringBuilder sbL       = new StringBuilder();
        StringBuilder sbR       = new StringBuilder();

        for (int index = 0; index < rowDataLeft.Length; index++)
        {
            sbL.AppendLine(string.Join(delimiter, rowDataLeft[index]));
            sbR.AppendLine(string.Join(delimiter, rowDataRight[index]));
        }
        string filePathL = "C:\\Users\\Vinay\\Documents\\WristWatcher\\Assets\\WristWatcher\\Left.csv";
        string filePathR = "C:\\Users\\Vinay\\Documents\\WristWatcher\\Assets\\WristWatcher\\Right.csv";

        // Create a file to write to.
        System.IO.File.AppendAllText(filePathL, sbL.ToString() + "\n");
        System.IO.File.AppendAllText(filePathR, sbR.ToString() + "\n");


        //Debug.Log(filePath);

        //Debug.Log("Left Angle:" + angleL + " Right Angle:" + angleR);
    }
示例#19
0
 protected override void Disengage()
 {
     SetIsKinematic(false);
     _handFeature = null;
 }
示例#20
0
 private float GetHandsYval(HandFeature hf)
 {
     return(Mathf.Clamp(_swipePlaneTransform.InverseTransformPoint(hf.Position).y, -MAX_TRAVEL, MAX_TRAVEL));
 }
示例#21
0
 private void SwipeOff(HandFeature hf)
 {
     _engaged = false;
     _swipePlaneDisengaged.Invoke();
 }
示例#22
0
 public void Disengage()
 {
     _inertia     = 1f;
     _handFeature = null;
 }
 public MetaInteractionData(PointerEventData pointerEventData, HandFeature motionHandFeature)
 {
     PointerEventData  = pointerEventData;
     MotionHandFeature = motionHandFeature;
 }
示例#24
0
 protected override void Disengage()
 {
     Manipulate();
     RestoreRigidbodySettingsAfterInteraction();
     _handFeature = null;
 }