Example #1
0
    public static HandModel GetHandModel(HandController controller, HandModelType type)
    {
        HandModel[] allHands;

        switch (type)
        {
            case HandModelType.Graphic:
                allHands = controller.GetAllGraphicsHands();
                break;

            case HandModelType.Physics:
                allHands = controller.GetAllPhysicsHands();
                break;

            default:
                allHands = controller.GetAllGraphicsHands();
                break;
        }

        if (allHands.Length == 0)
        {
            return null;
        }

        return allHands[0];
    }
Example #2
0
    float DistanceIndexs()
    {
        graphicsHands = hand_controller.GetAllGraphicsHands();
        physicsHands  = hand_controller.GetAllPhysicsHands();

        if (graphicsHands.Length == 2)
        {
            Vector3 indexPositionLeft;
            Vector3 indexPositionRight;

            for (int i = 0; i < graphicsHands.Length; i++)
            {
                if (graphicsHands [i].IsLeft())
                {
                    indexPositionLeft = graphicsHands [i].fingers [1].GetTipPosition();
                }
                if (graphicsHands [i].IsRight())
                {
                    indexPositionRight = graphicsHands [i].fingers [1].GetTipPosition();
                }
            }

            float distance           = (indexPositionLeft - indexPositionRight).magnitude;
            float normalizedDistance = (distance - 0.5f) / (1.7f - 0.5f);
            normalizedDistance = Mathf.Clamp01(normalizedDistance);
            Debug.Log("NormalizedDistance: " + normalizedDistance);
            return(normalizedDistance);
        }

        return(-1.0f);
    }
Example #3
0
    float getFingerDistance(string type, int finger_1, int finger_2, float min, float max)
    {
        graphicsHands = hand_controller.GetAllGraphicsHands();
        physicsHands  = hand_controller.GetAllPhysicsHands();

        if (graphicsHands.Length >= 1)
        {
            Vector3 firstFinger  = new Vector3(0f, 0f, 0f);
            Vector3 secondFinger = new Vector3(0f, 0f, 0f);

            for (int i = 0; i < graphicsHands.Length; i++)
            {
                if (graphicsHands [i].IsLeft() && type.Equals(left))
                {
                    firstFinger  = graphicsHands [i].fingers [finger_1].GetTipPosition();
                    secondFinger = graphicsHands [i].fingers [finger_2].GetTipPosition();
                }
                else if (graphicsHands [i].IsRight() && type.Equals(right))
                {
                    firstFinger  = graphicsHands [i].fingers [finger_1].GetTipPosition();
                    secondFinger = graphicsHands [i].fingers [finger_2].GetTipPosition();
                }
            }

            return(normalized(firstFinger, secondFinger, min, max));
        }
        return(-5.0f);
    }
    protected void UpdateTracker()
    {
        //get the 1st hand in the frame
        if (handController.GetAllGraphicsHands().Length != 0)
        {
            handModel = handController.GetAllGraphicsHands()[0];
            handModel.transform.GetComponentInChildren <SkinnedMeshRenderer>().enabled = visibleHand;
            hand     = handModel.GetLeapHand();
            Position = handModel.GetPalmPosition();
            Rotation = handModel.GetPalmRotation();
            float grabStrength = handModel.GetLeapHand().GrabStrength;
            if (grabStrength >= 0.9)
            {
                Grab = true;
            }
            else if (grabStrength <= 0.75)
            {
                Grab = false;
            }
        }

        //mask/display the graphical hand on key down
        if (Input.GetKeyDown(visibleHandKey))
        {
            var smr = handModel.transform.GetComponentInChildren <SkinnedMeshRenderer>();
            visibleHand = !visibleHand;
        }
    }
Example #5
0
    private void TakeInput()
    {
        horizontalInput = Input.GetAxis("Horizontal");
        verticalInput   = Input.GetAxis("Vertical");
        brakeInput      = System.Convert.ToSingle(Input.GetButton("Brake"));

        // handle leap input
        if (handController == null)
        {
            return;
        }
        // Move forward if both palms are facing outwards! Whoot!
        HandModel[] hands = handController.GetAllGraphicsHands();
        if (hands.Length > 1)
        {
            Vector3 direction0 = (hands [0].GetPalmPosition() - handController.transform.position).normalized;
            Vector3 normal0    = hands [0].GetPalmNormal().normalized;

            Vector3 direction1 = (hands [1].GetPalmPosition() - handController.transform.position).normalized;
            Vector3 normal1    = hands [1].GetPalmNormal().normalized;

            if (Vector3.Dot(direction0, normal0) > direction0.sqrMagnitude * 0.5f && Vector3.Dot(direction1, normal1) > direction1.sqrMagnitude * 0.5f)
            {
                // this means the player should move forward
                verticalInput = 1f;
                Debug.Log("Move forward");
            }
        }
    }
Example #6
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (leapMotionOVRController == null || handController == null)
        {
            return;
        }

        // Move forward if both palms are facing outwards! Whoot!
        HandModel[] hands = handController.GetAllGraphicsHands();
        if (hands.Length > 1)
        {
            Vector3 direction0 = (hands[0].GetPalmPosition() - handController.transform.position).normalized;
            Vector3 normal0    = hands[0].GetPalmNormal().normalized;

            Vector3 direction1 = (hands[1].GetPalmPosition() - handController.transform.position).normalized;
            Vector3 normal1    = hands[1].GetPalmNormal().normalized;

            if (Vector3.Dot(direction0, normal0) > direction0.sqrMagnitude * 0.5f && Vector3.Dot(direction1, normal1) > direction1.sqrMagnitude * 0.5f)
            {
                Vector3 target = (hands[0].GetPalmPosition() + hands[1].GetPalmPosition()) / 2.0f;
                target.y = startingHeight;
                leapMotionOVRController.transform.position = Vector3.Lerp(leapMotionOVRController.transform.position, target, 0.1f);
            }
        }
    }
Example #7
0
    void Update()
    {
        HandModel[]    models = null;
        HandController hand   = (HandController)controllerObject.GetComponent <HandController>();

        models = hand.GetAllGraphicsHands();

        if (models.Length == 1)
        {
            Vector3 handRotation = (models[0].GetPalmRotation().ToEulerAngles() * Rad2Deg);
            //Debug.Log(handRotation.z);
            if (handRotation.x > 30 && handRotation.x < 330)
            {
                handRotation.x = (tiltMaze.transform.rotation.ToEulerAngles() * Rad2Deg).x;
            }
            if (handRotation.z > 30 && handRotation.z < 330)
            {
                handRotation.z = (tiltMaze.transform.rotation.ToEulerAngles() * Rad2Deg).z;
            }
            tiltMaze.transform.rotation = Quaternion.Euler(new Vector3(handRotation.x, 0f, handRotation.z));

            //Debug.Log(tiltMaze.transform.rotation.ToEulerAngles() * Rad2Deg);
            FingerModel[] fingers = models[0].fingers;
            for (int x = 0; x < fingers.Length; x++)
            {
                Debug.DrawRay(fingers[x].GetRay().origin, fingers[x].GetRay().direction, Color.green);
            }
        }
    }
Example #8
0
    // Update is called once per frame
    void Update()
    {
        HandModel[] allGraphicHands = LeapHandController.GetAllGraphicsHands();

        if (allGraphicHands.Length <= 0)
        {
            return;
        }
        HandModel handModel = allGraphicHands[0];

        finger = handModel.fingers[(int)Finger.FingerType.TYPE_INDEX];

        fingerTipPos = finger.GetTipPosition();

        fingerdetect = (Input.GetKey(KeyCode.Space));

        if (fingerdetect)
        {
            // Using named temp variables like this helps me think more clearly about the code
            Vector3 previousPoint = (linePoints.Count > 0) ? linePoints[linePoints.Count - 1] : new Vector3(-1000, -1000, -1000); // If you've never seen this before, it's called a ternary expression.
            // It's just an if/else collapsed into a single line of code.
            // Also, the crazy out of bounds initial value here ensures the starting point will always draw.

            if (Vector3.Distance(fingerTipPos, previousPoint) > newPointDelta)
            {
                linePoints.Add(fingerTipPos);
                lineRenderer.SetVertexCount(linePoints.Count);
                lineRenderer.SetPosition(linePoints.Count - 1, (Vector3)linePoints[linePoints.Count - 1]);
                Debug.Log(string.Format("Added point at: {0}!", fingerTipPos));
            }
        }
    }
Example #9
0
    void cutFigure()
    {
        graphicsHands = hand_controller.GetAllGraphicsHands();
        physicsHands  = hand_controller.GetAllPhysicsHands();

        if (graphicsHands.Length >= 1)
        {
            for (int i = 0; i < graphicsHands.Length; i++)
            {
                if (graphicsHands [i].IsLeft())
                {
                    transform.position = graphicsHands [i].fingers [middle].GetTipPosition();
                    transform.rotation = graphicsHands [i].GetPalmRotation();

                    distance = getFingerDistance(left, middle, ring, min_Cut, max_Cut);

                    cutting(distance);
                }
            }
        }
    }
Example #10
0
    // Create a marker from de position of the hand
    void Marcar()
    {
        HandController controller = GetComponent <HandController> ();

        HandModel[] hands = controller.GetAllGraphicsHands();

        if (hands.Length != 0 && DistanciaEntreVetores(posicaoAnterior, hands[0].GetPalmPosition()) > distancia)
        {
            posicaoAnterior = hands[0].GetPalmPosition();
            Transform forma = Instantiate(objeto, posicaoAnterior, Quaternion.identity) as Transform;
            forma.rotation = hands[0].GetPalmRotation();
        }
    }
Example #11
0
    // Update is called once per frame
    void Update()
    {
        HandController handController = GameObject.Find("HandController").GetComponent <HandController> ();

        HandModel[] hands = handController.GetAllGraphicsHands();
        foreach (HandModel hand in hands)
        {
            foreach (FingerModel finger in hand.fingers)
            {
                Ray        fingerRay = finger.GetRay();
                RaycastHit hit       = new RaycastHit();
                if (Physics.Raycast(fingerRay, out hit))
                {
                    if (hit.collider.gameObject.CompareTag("Scaleable"))
                    {
                        switch (hit.collider.gameObject.name)
                        {
                        case "Ward 1":

                            break;

                        case "Ward 2":
                            break;

                        case "Ward 3":
                            break;

                        case "Ward 4":
                            break;

                        case "Ward 5":
                            break;

                        case "Ward 6":
                            break;

                        case "Ward 7":
                            break;

                        case "Ward 8":
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
    }
Example #12
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (handController.GetAllGraphicsHands().Length != 0)
        {
            handModel = handController.GetAllGraphicsHands()[0];
            hand      = handModel.GetLeapHand();
            finger0   = hand.Fingers[0]; //thumb
            finger1   = hand.Fingers[1]; //index
            finger2   = hand.Fingers[2]; //middle finger
            finger3   = hand.Fingers[3]; //ring finger
            pos       = hand.PalmPosition;
            camRot    = this.transform.rotation;
            //movement and rotation speed
            velocity = hand.PalmVelocity;
            speed    = velocity.Magnitude / 50f;

            /* The transformations are based on the palm position and movement.
             * The fingers are used to create new commands */

            Debug.DrawRay(this.GetComponentInChildren <Camera>().transform.position, Vector3.forward);

            //Extend index to activate camera movement
            if (finger1.IsExtended && !finger2.IsExtended && !finger0.IsExtended)
            {
                moveCamera();
            }

            //Extend index and middle finger to activate camera rotation
            if (finger1.IsExtended && finger2.IsExtended && !finger3.IsExtended && !finger0.IsExtended)
            {
                rotateCamera();
            }
            oldPos    = pos;
            oldCamRot = camRot;
        }
    }
Example #13
0
        void handFromFrame()
        {
            if ((FoundState.state == FOUND_STATE_NO_ID) || (FoundState.state == FOUND_STATE_HAND_INVALID))
            {
                return;
            }
            else if (NoHandId)
            {
                FoundState.Change(FOUND_STATE_NO_ID);
                return;
            }

            Frame f = Controller.GetFrame();

            if (f.Id == lastFrameId)
            {
                return;
            }

            if (!f.Hand(handId).IsValid)
            {
                FoundState.Change(FOUND_STATE_HAND_INVALID);
                return;
            }

            lastFrameId = f.Id;

            HandModel[] handsInScene = Controller.GetAllGraphicsHands();

            HandModel oldFound = null;

            foreach (HandModel handInScene in handsInScene)
            {
                if ((!oldFound) && (handInScene.GetLeapHand().Id == handId))
                {
                    oldFound = handInScene;
                    FoundState.Change(FOUND_STATE_FOUND);
                    break;
                }
            }

            if (!oldFound)
            {
                FoundState.Change(FOUND_STATE_NOT_FOUND);
            }

            CurrentHand = oldFound;
        }
Example #14
0
 public HandModel getRightGraphicHand()
 {
     if (currentFrame == null)
     {
         return(null);
     }
     HandModel[] hands = rightHandController.GetAllGraphicsHands();
     foreach (HandModel hand in hands)
     {
         if (hand.GetLeapHand().IsRight)
         {
             return(hand);
         }
     }
     return(null);
 }
Example #15
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.H))
     {
         show_hand_ = !show_hand_;
     }
     HandModel[] models = hand_controller_.GetAllGraphicsHands();
     foreach (HandModel model in models)
     {
         Renderer[] renderers = model.GetComponentsInChildren <Renderer>();
         foreach (Renderer renderer in renderers)
         {
             renderer.enabled = show_hand_;
         }
     }
 }
Example #16
0
    void Update()
    {
        HandModel[]    models = null;
        HandController hand   = (HandController)controllerObject.GetComponent <HandController>();

        models = hand.GetAllGraphicsHands();

        if (models.Length > 0)
        {
            cubey.transform.position = models[0].GetPalmPosition();
            cubey.transform.rotation = models[0].GetPalmRotation();
            FingerModel[] fingers = models[0].fingers;
            for (int x = 0; x < fingers.Length; x++)
            {
                Debug.DrawRay(fingers[x].GetRay().origin, fingers[x].GetRay().direction, Color.green);
            }
        }
    }
Example #17
0
        HandModel RightmostHand()
        {
            HandModel rightHand = null;

            foreach (HandModel hand in HandController.GetAllGraphicsHands())
            {
                if (rightHand != null)
                {
                    if (hand.GetLeapHand().IsRight)
                    {
                        rightHand = hand;
                    }
                }
                else
                {
                    rightHand = hand;
                }
            }
            return(rightHand);
        }
Example #18
0
    void OnTriggerEnter(Collider other)
    {
        HandModel hand_model = GetHand(other);

        if (hand_model != null)
        {
            int         handID      = hand_model.GetLeapHand().Id;
            HandModel[] hand_models = leap_controller_.GetAllGraphicsHands();
            for (int i = 0; i < hand_models.Length; ++i)
            {
                if (hand_models[i].GetLeapHand().Id == handID)
                {
                    GameObject part      = hand_models[i].transform.Find(other.transform.parent.name).Find(other.name).gameObject;
                    Renderer[] renderers = part.GetComponentsInChildren <Renderer>();
                    foreach (Renderer renderer in renderers)
                    {
                        renderer.material.color = Color.red;
                    }
                }
            }
        }
    }
Example #19
0
    void OnTriggerEnter(Collider other)
    {
        HandModel hand_model = GetHand(other);

        if (hand_model != null)
        {
            int         handID      = hand_model.GetLeapHand().Id;
            HandModel[] hand_models = leap_controller_.GetAllGraphicsHands();
            for (int i = 0; i < hand_models.Length; ++i)
            {
                if (hand_models[i].GetLeapHand().Id == handID)
                {
                    Transform part = null;
                    if (other.transform.parent.GetComponent <HandModel>() != null)
                    {
                        // Palm or Forearm components
                        part = FindPart(hand_models[i].transform, other.name);
                    }
                    else if (other.transform.parent.GetComponent <FingerModel>() != null)
                    {
                        // Bone in a finger
                        part = FindPart(FindPart(hand_models[i].transform, other.transform.parent.name), other.name);
                    }
                    //Debug.Log ("Detected: " + other.transform.parent.name + "/" + other.gameObject.name);
                    if (part != null)
                    {
                        Renderer[] renderers = part.GetComponentsInChildren <Renderer>();
                        foreach (Renderer renderer in renderers)
                        {
                            //Debug.Log ("Marked: " + renderer.gameObject.transform.parent.name + "/" + renderer.gameObject.name);
                            renderer.material.color = Color.red;
                        }
                    }
                }
            }
        }
    }
Example #20
0
        // Update is called once per frame
        void Update()
        {
            HandModel model0;
            HandModel model1;
            bool      wasAligned = false;

            if (handController.GetAllGraphicsHands().Length == 1)
            {
                model0 = handController.GetAllGraphicsHands()[0];
                if (model0.GetLeapHand().IsLeft == true)
                {
                    AlignArmHUD(model0);
                    wasAligned = true;
                }
                else if (ArmHUDState.state == ARMHUDSTATE_PANELVISIBLE)
                {
                }
                else
                {
                    if (ArmHUDisOpen == true)
                    {
                        ArmHUDState.Change(ARMHUDSTATE_DROPPED);
                    }
                }
            }
            else if (handController.GetAllGraphicsHands().Length > 1)
            {
                // FIXME: This should either persist based on ID
                // or should require a single left hand.
                model0 = handController.GetAllGraphicsHands()[0];
                model1 = handController.GetAllGraphicsHands()[1];
                if (model0.GetLeapHand().IsLeft&&
                    model1.GetLeapHand().IsRight)
                {
                    AlignArmHUD(model0);
                    wasAligned = true;
                }
                else if (model0.GetLeapHand().IsRight&&
                         model1.GetLeapHand().IsLeft)
                {
                    AlignArmHUD(model1);
                    wasAligned = true;
                }
                else
                {
                    if (ArmHUDisOpen == true)
                    {
                        ArmHUDState.Change(ARMHUDSTATE_DROPPED);
                    }
                }
            }
            else
            {
                if (ArmHUDisOpen == true)
                {
                    ArmHUDState.Change(ARMHUDSTATE_DROPPED);
                }
            }

            if (ArmHUDState.state == ARMHUDSTATE_PANELVISIBLE)
            {
                UpdateArmHUDGUIvalues();
            }

            if (!wasAligned)
            {
                targetHandID = -1;
            }
        }
    void Update()
    {
        if (Time.timeSinceLevelLoad < startTime)
        {
            return;
        }

        HandController controller = GetComponent <HandController>();

        if (!played_ && controller.IsConnected())
        {
            controller.enabled = true;
            controller.StopRecording();
            controller.PlayRecording();
            played_ = true;
        }

        float progress = controller.GetRecordingProgress();

        if (live_controller_ != null &&
            live_controller_.GetAllGraphicsHands().Length > 0 &&
            onlyPlayIfNoHands)
        {
            force_fade_ *= forceFadeDecay;
        }
        else if (exiting_)
        {
            force_fade_ *= forceFadeDecay;
        }
        else
        {
            force_fade_ = 1.0f - forceFadeDecay * (1.0f - force_fade_);
        }

        if (force_fade_ < 0.01f)
        {
            progress = 1.0f;
        }

        if (progress >= 1.0f)
        {
            controller.DestroyAllHands();
            for (int i = 0; i < additionalObjects.Length; ++i)
            {
                Destroy(additionalObjects[i].gameObject);
            }
            gameObject.SetActive(false);
            return;
        }

        float alpha = force_fade_ * maxTransparency;

        if (progress < fadeInLength)
        {
            alpha *= progress / fadeInLength;
        }
        else if (1.0f - progress < fadeOutLength)
        {
            alpha *= (1.0f - progress) / fadeOutLength;
        }

        HandModel[] hands = controller.GetAllGraphicsHands();
        foreach (HandModel hand in hands)
        {
            Renderer[] renderers = hand.GetComponentsInChildren <Renderer>();
            for (int i = 0; i < renderers.Length; ++i)
            {
                SetAlphaOfRenderer(renderers[i], alpha);
            }
            for (int i = 0; i < additionalObjects.Length; ++i)
            {
                SetAlphaOfRenderer(additionalObjects[i], alpha);
            }
        }
    }
 bool ShouldShowText()
 {
     return(time_connected_ >= waitTime && !exiting_ && !dontShowAnymore &&
            (!showOnlyWhenNoHands || controller.GetAllGraphicsHands().Length == 0) &&
            (!showOnlyAfterUse || shown_hands_));
 }
Example #23
0
    // Update is called once per frame
    void Update()
    {
        models = null;
        models = controller.GetAllGraphicsHands();

        if (models.Length > 0)
        {
            currentPosition = models[0].GetPalmPosition();
            currentAngle    = models[0].GetPalmDirection();
            //Debug.Log(currentAngle);

            Vector3 handRotation = (models[0].GetPalmRotation().ToEulerAngles() * Rad2Deg);
            //Debug.Log(handRotation);

            //bird.transform.eulerAngles = handRotation;
            bird.transform.rotation = Quaternion.Euler(new Vector3(0f, handRotation.y, 0f));


            //Debug.Log(bird.transform.eulerAngles.x + ", " + bird.transform.eulerAngles.y + ", " + bird.transform.eulerAngles.z);

            //rotate accordingly
        }

        //flap to elevate, spread fingers to glide
        if (lastPosition != Vector3.zero && bird != null)
        {
            var   fingers  = controller.GetFrame().Hands[0].Fingers;
            float angleSum = 0;
            for (int i = 1; i < fingers.Count - 1; i++)
            {
                angleSum += (fingers[i].Direction - fingers[i + 1].Direction).Magnitude;
            }

            angleSum -= 0.2f;
            angleSum /= 0.8f;
            angleSum  = Mathf.Clamp(angleSum, 0f, 1f);
            //Debug.Log("anglesum: " + angleSum);

            //drag?
            bird.rigidbody.AddForce(-Physics.gravity * angleSum);
            bird.rigidbody.velocity = bird.rigidbody.velocity * 0.99f;


            Vector3 direction = lastPosition - currentPosition;
            float   velocity  = direction.magnitude / Time.deltaTime;

            //upward force
            bird.rigidbody.AddForce(Vector3.up * velocity * magnitude);
        }

        //clamp position
        if (bird.transform.position.y > ceiling)
        {
            bird.transform.position = new Vector3(bird.transform.position.x, ceiling, bird.transform.position.z);
        }
        else if (bird.transform.position.y < flooring)
        {
            bird.transform.position = new Vector3(bird.transform.position.x, flooring, bird.transform.position.z);
        }


        //advance forward
        bird.transform.position = new Vector3(bird.transform.position.x, bird.transform.position.y, bird.transform.position.z + moveForwardMag * Time.deltaTime);

        //must be last
        lastPosition = currentPosition;
    }