//Member Function: Update//////////////////////////////////////////////////// public void Update() { //Update the leap listener. listener.refresh(); //If the user closes their hand while the game is not paused, pause it. if (listener.hands < 1 || titleMenu.open || !applicationFocused) { //Pause all entities paused = true; //Open the title menu. if (titleMenu.open == false) { titleMenu.enabled = true; } //Hide the hands. this.GetComponent <HandRenderer>().enabled = false; } //Otherwise, keep the game running. else if (listener.hands >= 1 && titleMenu.open == false) { //Unpause all entities. paused = false; //Show the hands. this.GetComponent <HandRenderer>().enabled = true; } }
//Member Function: Update//////////////////////////////////////////////////// public void Update() { //Update the listener. listener.refresh(); //Reset the fingers array. if (fingers != null) { fingers.Clear(); } //Retrieve coordinates for any fingers that are present, but only if the menus are visible. if (listener.fingers > 0 && Core.getInstance().paused) { //Loop over all fingers. for (int i = 0; i < listener.fingers; i++) { //Set up it's position. Vector3 tipPosition = new Vector3(0, 0, 0); //Get a normalized box. normalizedBox = listener.frame.InteractionBox; //Finger coordinates. tipPosition.x = normalizedBox.NormalizePoint(listener.frame.Fingers[i].TipPosition).x; tipPosition.y = normalizedBox.NormalizePoint(listener.frame.Fingers[i].TipPosition).y; //Modify coordinates to equal screen resolution. tipPosition.x = tipPosition.x * Screen.width; tipPosition.y = tipPosition.y * Screen.height; //Flip Y axis. tipPosition.y = tipPosition.y * -1; tipPosition.y += Screen.height; fingers.Add(new Rect(tipPosition.x, tipPosition.y, 16, 16)); } } }
//Update///////////////////////////////////////////////////////////////////// public void Update() { if (listener == null) { listener = new LeapListener(); } //Update the listener. listener.refresh(); //Get a normalized box. normalizedBox = listener.frame.InteractionBox; //First, get any hands that are present. if (listener.hands > 0) { //Reset the hands array. if (hands != null) { for (int i = 0; i < hands.Length; i++) { Destroy(hands[i]); } } //Initialize our hands. hands = new GameObject[listener.hands]; //Loop over all hands. for (int i = 0; i < listener.hands; i++) { try { //Create a new hand. hands[i] = (GameObject)Instantiate(palm); //Set its properties. hands[i].transform.parent = camera.transform; hands[i].name = "Palm:" + i; //Set up it's position. Vector3 palmPosition = new Vector3(0, 0, 0); palmPosition.x += listener.frame.Hands[i].PalmPosition.x / 10; palmPosition.y += verticalOffset; palmPosition.y += listener.frame.Hands[i].PalmPosition.y / 10; palmPosition.z += depth; palmPosition.z += (listener.frame.Hands[i].PalmPosition.z * -1) / 10; //Move the hand. hands[i].transform.localPosition = palmPosition; //Set the hands rotation to neutral. Quaternion lr = hands[i].transform.rotation; Vector3 leap = listener.rotation(listener.frame.Hands[i]); lr.eulerAngles = new Vector3(leap.x * -1, leap.y, leap.z); hands[i].transform.localRotation = lr; } //Watch out for those pesky "index out of bounds" errors. catch (System.IndexOutOfRangeException e) { Debug.LogException(e); } } } //If there aren't any. delete any active palms. else if (hands != null) { for (int i = 0; i < hands.Length; i++) { Destroy(hands[i]); } } //Get any fingers that are present. if (listener.fingers > 0 && listener.hands > 0) { //Reset the fingers array. if (fingers != null && listener.fingers != fingers.Length) { for (int i = 0; i < fingers.Length; i++) { Destroy(fingers[i]); } } //Initialize our fingers. if (fingers == null || listener.fingers != fingers.Length) { fingers = new GameObject[listener.fingers]; } //Loop over all fingers. for (int i = 0; i < listener.fingers; i++) { try { //Create a new finger. if (fingers[i] == null) { fingers[i] = (GameObject)Instantiate(fingerTip); } //Set its properties. fingers[i].name = "Finger:" + i; fingers[i].transform.parent = camera.transform; //Set up it's position. Vector3 tipPosition = new Vector3(0, 0, 0); tipPosition.x += listener.frame.Fingers[i].TipPosition.x / 10; tipPosition.y += verticalOffset; tipPosition.y += listener.frame.Fingers[i].TipPosition.y / 10; tipPosition.z += depth; tipPosition.z += (listener.frame.Fingers[i].TipPosition.z * -1) / 10; //Move the finger to where it belongs. fingers[i].transform.localPosition = tipPosition; //Set the fingers rotation to neutral. Quaternion lr = fingers[i].transform.rotation; lr.eulerAngles = Vector3.zero; fingers[i].transform.localRotation = lr; } //Watch out for those pesky "index out of bounds" errors. catch (System.IndexOutOfRangeException e) { Debug.LogException(e); } } } //If not, delete any active fingers. else if (fingers != null) { for (int i = 0; i < fingers.Length; i++) { Destroy(fingers[i]); } } }
//Member Function: Update//////////////////////////////////////////////////// public void Update() { //Try to read data from the Leap Motion device. try { //Refresh the Leap data. listener.refresh(); //Reset all of the variables. x = y = 0; //If there are hands in the field of view and the leap device is connected, use the LEAPs input. if (!wasdInput && LeapListener.connected && listener.hands > 0 && listener.fingers > 0) { //Do not force WASD input. wasdInputForced = false; //If there's a hand in the field of view (FOV), track it. if (listener.hands > 0 && listener.fingers > 0) { //Right joystick X-Axis. Sensitivity is doubled since a value of '40' is more like '80'. x = (int)(listener.handRoll * -2); //Right joystick Y-Axis. Sensitivity is doubled since a value of '40' is more like '80'. y = (int)(listener.handPitch * -2); } } //Do not force WASD input if the LEAP device is connected and WASD input is turned on. else if (wasdInput || LeapListener.connected) { wasdInputForced = false; } //Force WASD input. else { wasdInputForced = true; } //If a LEAP device is not connected, try the keyboard. I'm sure the pros will prefer this. if (wasdInput || wasdInputForced) { //Left joystick X-Axis. if (Input.GetKey("a")) { x += -80; } if (Input.GetKey("d")) { x += 80; } //Left joystick Y-Axis. if (Input.GetKey("w")) { y += 80; } if (Input.GetKey("s")) { y += -80; } } } //If reading data fails, assert that WASD input is now being used. catch (System.Exception e) { wasdInput = true; } }