private void OnTriggerEnter(Collider other) { if (!other.name.EndsWith("pointer")) { return; } if (GestureManagerVR.isGesturing) { return; } if (this.key == "Shift") { shiftActive = true; return; } if (this.key == "Alt") { altActive = true; return; } if (this.key == "CapsLock") { shiftActive = !shiftActive; return; } if (this.key == "Escape" || this.key == "Enter") { GestureManagerVR.setInputFocus(null); return; } GestureManagerVR.keyboardInput(this); }
private void OnTriggerEnter(Collider other) { GestureManager gm = GestureManagerVR.me?.gestureManager; if (!other.name.EndsWith("pointer") || gm == null) { return; } if (GestureManagerVR.isGesturing) { return; } switch (this.operation) { case Operation.LoadGestureFile: gm.loadFromFile(); break; case Operation.SaveGestureFile: gm.saveToFile(); break; } GestureManagerVR.setInputFocus(null); GestureManagerVR.refresh(); }
public void refresh() { if (!this.initialized) { this.init(); } GestureManagerVR.refreshTextInputs(this.gameObject); }
private void OnTriggerEnter(Collider other) { GestureManager gm = GestureManagerVR.me?.gestureManager; if (!other.name.EndsWith("pointer") || gm == null) { return; } if (GestureManagerVR.isGesturing) { return; } if (gm.gr != null) { int num_gestures = gm.gr.numberOfGestures(); if (this.forward) { gm.record_gesture_id = (gm.record_gesture_id + 1 >= num_gestures) ? -1 : gm.record_gesture_id + 1; } else { gm.record_gesture_id = (gm.record_gesture_id - 1 < -1) ? num_gestures - 1 : gm.record_gesture_id - 1; } if (gestureNameDisplay != null) { string gestureName = gm.record_gesture_id == -1 ? "[Testing, not recording]" : gm.gr.getGestureName(gm.record_gesture_id); gestureNameDisplay.text = gestureName; } } else if (gm.gc != null) { int num_combinations = gm.gc.numberOfGestureCombinations(); if (this.forward) { gm.record_combination_id = (gm.record_combination_id + 1 >= num_combinations) ? -1 : gm.record_combination_id + 1; } else { gm.record_combination_id = (gm.record_combination_id - 1 < -1) ? num_combinations - 1 : gm.record_combination_id - 1; } if (gestureNameDisplay != null) { string gestureName = gm.record_combination_id == -1 ? "[Testing, not recording]" : gm.gc.getGestureCombinationName(gm.record_combination_id); gestureNameDisplay.text = gestureName; } } GestureManagerVR.setInputFocus(null); }
// Start is called before the first frame update void Start() { me = this; inputFocus = null; keyboard?.SetActive(false); for (int i = 0; i < this.transform.childCount; i++) { GameObject child = this.transform.GetChild(i).gameObject; switch (child.name) { case "SubmenuNumberOfParts": submenuNumberOfParts = child; break; case "SubmenuFiles": submenuFiles = child; break; case "SubmenuGesture": submenuGesture = child; break; case "SubmenuCombination": submenuCombination = child; break; case "SubmenuRecord": submenuRecord = child; break; case "SubmenuTraining": submenuTraining = child; break; } for (int k = 0; k < child.transform.childCount; k++) { GameObject grandChild = child.transform.GetChild(k).gameObject; EditableTextField editableTextField = grandChild.GetComponent <EditableTextField>(); if (editableTextField != null) { editableTextField.refreshText(); } } } refresh(); }
private void OnTriggerEnter(Collider other) { GestureManager gm = GestureManagerVR.me?.gestureManager; if (!other.name.EndsWith("pointer") || gm == null) { return; } if (GestureManagerVR.isGesturing) { return; } if (gm.gr != null) { if (this.operation == Operation.StartTraining) { gm.gr.startTraining(); } else { gm.gr.stopTraining(); } } else if (gm.gc != null) { if (this.operation == Operation.StartTraining) { gm.gc.startTraining(); } else { gm.gc.stopTraining(); } } GestureManagerVR.setInputFocus(null); GestureManagerVR.refresh(); }
private void OnTriggerEnter(Collider other) { GestureManager gm = GestureManagerVR.me?.gestureManager; if (!other.name.EndsWith("pointer") || gm == null || gm.gc == null) { return; } if (GestureManagerVR.isGesturing) { return; } switch (this.operation) { case Operation.CreateCombination: this.submenuCombination.CurrentCombination = gm.gc.createGestureCombination("New Combination"); break; case Operation.DeleteCombination: if (this.submenuCombination.CurrentCombination >= 0) { gm.gc.deleteGestureCombination(this.submenuCombination.CurrentCombination); this.submenuCombination.CurrentCombination--; GestureManagerVR.refresh(); } break; case Operation.NextCombination: { int numCombinations = gm.gc.numberOfGestureCombinations(); if (numCombinations == 0) { this.submenuCombination.CurrentCombination = -1; } else if (this.submenuCombination.CurrentCombination + 1 >= numCombinations) { this.submenuCombination.CurrentCombination = 0; } else { this.submenuCombination.CurrentCombination++; } } break; case Operation.PreviousCombination: { int numCombinations = gm.gc.numberOfGestureCombinations(); if (numCombinations == 0) { this.submenuCombination.CurrentCombination = -1; } else if (this.submenuCombination.CurrentCombination - 1 < 0) { this.submenuCombination.CurrentCombination = numCombinations - 1; } else { this.submenuCombination.CurrentCombination--; } } break; case Operation.NextPart: { int numParts = gm.gc.numberOfParts(); if (numParts == 0) { this.submenuCombination.CurrentPart = -1; } else if (this.submenuCombination.CurrentPart + 1 >= numParts) { this.submenuCombination.CurrentPart = 0; } else { this.submenuCombination.CurrentPart++; } } break; case Operation.PreviousPart: { int numParts = gm.gc.numberOfParts(); if (numParts == 0) { this.submenuCombination.CurrentPart = -1; } else if (this.submenuCombination.CurrentPart - 1 < 0) { this.submenuCombination.CurrentPart = numParts - 1; } else { this.submenuCombination.CurrentPart--; } } break; case Operation.NextGesture: { int numGestures = gm.gc.numberOfGestures(this.submenuCombination.CurrentPart); if (numGestures == 0) { this.submenuCombination.CurrentGesture = -1; // -1 = [NONE] } else if (this.submenuCombination.CurrentGesture + 1 >= numGestures) { this.submenuCombination.CurrentGesture = -1; // -1 = [NONE] } else { this.submenuCombination.CurrentGesture++; } } break; case Operation.PreviousGesture: { int numGestures = gm.gc.numberOfGestures(this.submenuCombination.CurrentPart); if (numGestures == 0) { this.submenuCombination.CurrentGesture = -1; // -1 = [NONE] } else if (this.submenuCombination.CurrentGesture - 1 < -1) // -1 = [NONE] { this.submenuCombination.CurrentGesture = numGestures - 1; } else { this.submenuCombination.CurrentGesture--; } } break; } GestureManagerVR.setInputFocus(null); this.submenuCombination.refresh(); }
// Update: void Update() { float escape = Input.GetAxis("escape"); if (escape > 0.0f) { Application.Quit(); } if (this.gr == null && this.gc == null) { ConsoleText.text = "Welcome to MiVRy Gesture Recognition!\n" + "This manager allows you to create and record gestures,\n" + "and organize gesture files."; return; } if (training_started) { if ((this.gr != null && this.gr.isTraining()) || (this.gc != null && this.gc.isTraining())) { ConsoleText.text = "Currently training...\n" + "Current recognition performance: " + (this.last_performance_report * 100).ToString() + "%.\n"; GestureManagerVR.refresh(); return; } else { training_started = false; ConsoleText.text = "Training finished!\n" + "Final recognition performance: " + (this.last_performance_report * 100).ToString() + "%.\n"; GestureManagerVR.refresh(); } } else if ((this.gr != null && this.gr.isTraining()) || (this.gc != null && this.gc.isTraining())) { training_started = true; ConsoleText.text = "Currently training...\n" + "Current recognition performance: " + (this.last_performance_report * 100).ToString() + "%.\n"; GestureManagerVR.refresh(); return; } float trigger_left = Input.GetAxis("LeftControllerTrigger"); float trigger_right = Input.GetAxis("RightControllerTrigger"); // Single Gesture recognition / 1-handed operation if (this.gr != null) { // If the user is not yet dragging (pressing the trigger) on either controller, he hasn't started a gesture yet. if (active_controller == null) { // If the user presses either controller's trigger, we start a new gesture. if (trigger_right > 0.85) { // Right controller trigger pressed. active_controller = GameObject.Find("Right Hand"); } else if (trigger_left > 0.85) { // Left controller trigger pressed. active_controller = GameObject.Find("Left Hand"); } else { // If we arrive here, the user is pressing neither controller's trigger: // nothing to do. return; } // If we arrive here: either trigger was pressed, so we start the gesture. GameObject hmd = GameObject.Find("Main Camera"); // alternative: Camera.main.gameObject Vector3 hmd_p = hmd.transform.position; Quaternion hmd_q = hmd.transform.rotation; gr.startStroke(hmd_p, hmd_q, record_gesture_id); gesture_started = true; return; } // If we arrive here, the user is currently dragging with one of the controllers. // Check if the user is still dragging or if he let go of the trigger button. if (trigger_left > 0.85 || trigger_right > 0.85) { // The user is still dragging with the controller: continue the gesture. Vector3 p = active_controller.transform.position; Quaternion q = active_controller.transform.rotation; gr.contdStrokeQ(p, q); addToStrokeTrail(p); return; } // else: if we arrive here, the user let go of the trigger, ending a gesture. active_controller = null; // Delete the objectes that we used to display the gesture. foreach (string star in stroke) { Destroy(GameObject.Find(star)); stroke_index = 0; } double similarity = 0; // This will receive the similarity value (0~1) Vector3 pos = Vector3.zero; // This will receive the position where the gesture was performed. double scale = 0; // This will receive the scale at which the gesture was performed. Vector3 dir0 = Vector3.zero; // This will receive the primary direction in which the gesture was performed (greatest expansion). Vector3 dir1 = Vector3.zero; // This will receive the secondary direction of the gesture. Vector3 dir2 = Vector3.zero; // This will receive the minor direction of the gesture (direction of smallest expansion). int gesture_id = gr.endStroke(ref similarity, ref pos, ref scale, ref dir0, ref dir1, ref dir2); gesture_started = false; GestureManagerVR.refresh(); // If we are currently recording samples for a custom gesture, check if we have recorded enough samples yet. if (record_gesture_id >= 0) { // Currently recording samples for a custom gesture - check how many we have recorded so far. ConsoleText.text = "Recorded a gesture sample for " + gr.getGestureName(record_gesture_id) + ".\n" + "Total number of recorded samples for this gesture: " + gr.getGestureNumberOfSamples(record_gesture_id) + ".\n"; return; } // else: if we arrive here, we're not recording new samples, // but instead have identified a gesture. if (gesture_id < 0) { // Error trying to identify any gesture ConsoleText.text = "Failed to identify gesture."; } else { string gesture_name = gr.getGestureName(gesture_id); ConsoleText.text = "Identified gesture " + gesture_name + "(" + gesture_id + ")\n(Similarity: " + similarity + ")"; } return; } // GestureCombination recognition / 2-handed operation if (this.gc != null) { // If the user presses either controller's trigger, we start a new gesture. if (trigger_pressed_left == false && trigger_left > 0.9) { // Controller trigger pressed. trigger_pressed_left = true; GameObject hmd = GameObject.Find("Main Camera"); // alternative: Camera.main.gameObject Vector3 hmd_p = hmd.transform.position; Quaternion hmd_q = hmd.transform.rotation; int gesture_id = -1; if (record_combination_id >= 0) { gesture_id = gc.getCombinationPartGesture(record_combination_id, lefthand_combination_part); } gc.startStroke(lefthand_combination_part, hmd_p, hmd_q, gesture_id); gesture_started = true; } if (trigger_pressed_right == false && trigger_right > 0.9) { // Controller trigger pressed. trigger_pressed_right = true; GameObject hmd = GameObject.Find("Main Camera"); // alternative: Camera.main.gameObject Vector3 hmd_p = hmd.transform.position; Quaternion hmd_q = hmd.transform.rotation; int gesture_id = -1; if (record_combination_id >= 0) { gesture_id = gc.getCombinationPartGesture(record_combination_id, righthand_combination_part); } gc.startStroke(righthand_combination_part, hmd_p, hmd_q, gesture_id); gesture_started = true; } if (gesture_started == false) { // nothing to do. return; } // If we arrive here, the user is currently dragging with one of the controllers. if (trigger_pressed_left == true) { if (trigger_left < 0.85) { // User let go of a trigger and held controller still gc.endStroke(lefthand_combination_part); trigger_pressed_left = false; } else { // User still dragging or still moving after trigger pressed GameObject left_hand = GameObject.Find("Left Hand"); gc.contdStrokeQ(lefthand_combination_part, left_hand.transform.position, left_hand.transform.rotation); // Show the stroke by instatiating new objects addToStrokeTrail(left_hand.transform.position); } } if (trigger_pressed_right == true) { if (trigger_right < 0.85) { // User let go of a trigger and held controller still gc.endStroke(righthand_combination_part); trigger_pressed_right = false; } else { // User still dragging or still moving after trigger pressed GameObject right_hand = GameObject.Find("Right Hand"); gc.contdStrokeQ(righthand_combination_part, right_hand.transform.position, right_hand.transform.rotation); // Show the stroke by instatiating new objects addToStrokeTrail(right_hand.transform.position); } } if (trigger_pressed_left || trigger_pressed_right) { // User still dragging with either hand - nothing left to do return; } // else: if we arrive here, the user let go of both triggers, ending the gesture. gesture_started = false; // Delete the objectes that we used to display the gesture. foreach (string star in stroke) { Destroy(GameObject.Find(star)); stroke_index = 0; } double similarity = 0; // This will receive a similarity value (0~1). int recognized_combination_id = gc.identifyGestureCombination(ref similarity); // If we are currently recording samples for a custom gesture, check if we have recorded enough samples yet. if (record_combination_id >= 0) { // Currently recording samples for a custom gesture - check how many we have recorded so far. int connected_gesture_id_left = gc.getCombinationPartGesture(record_combination_id, lefthand_combination_part); int connected_gesture_id_right = gc.getCombinationPartGesture(record_combination_id, righthand_combination_part); int num_samples_left = gc.getGestureNumberOfSamples(lefthand_combination_part, connected_gesture_id_left); int num_samples_right = gc.getGestureNumberOfSamples(righthand_combination_part, connected_gesture_id_right); // Currently recording samples for a custom gesture - check how many we have recorded so far. ConsoleText.text = "Recorded a gesture sample for " + gc.getGestureCombinationName(record_combination_id) + ".\n" + "Total number of recorded samples for this gesture: " + num_samples_left + " left / " + num_samples_right + " right.\n"; GestureManagerVR.refresh(); return; } // else: if we arrive here, we're not recording new samples for custom gestures, // but instead have identified a new gesture. // Perform the action associated with that gesture. if (recognized_combination_id < 0) { // Error trying to identify any gesture ConsoleText.text = "Failed to identify gesture."; } else { string combination_name = gc.getGestureCombinationName(recognized_combination_id); ConsoleText.text = "Identified gesture combination '" + combination_name + "' (" + recognized_combination_id + ")\n(Similarity: " + similarity + ")"; } } }
private void OnTriggerEnter(Collider other) { GestureManager gm = GestureManagerVR.me?.gestureManager; if (!other.name.EndsWith("pointer") || gm == null) { return; } if (GestureManagerVR.isGesturing) { return; } switch (this.operation) { case Operation.CreateGesture: this.submenuGesture.CurrentGesture = (gm.gr != null) ? gm.gr.createGesture("New Gesture") : (gm.gc != null) ? gm.gc.createGesture(this.submenuGesture.CurrentPart, "New Gesture") : -1; break; case Operation.DeleteGesture: if (this.submenuGesture.CurrentGesture >= 0) { if (gm.gr != null) { gm.gr.deleteGesture(this.submenuGesture.CurrentGesture); } if (gm.gc != null) { gm.gc.deleteGesture(this.submenuGesture.CurrentPart, this.submenuGesture.CurrentGesture); } this.submenuGesture.CurrentGesture--; GestureManagerVR.refresh(); } break; case Operation.DeleteLastSample: if (this.submenuGesture.CurrentGesture >= 0) { if (gm.gr != null) { int numSamples = gm.gr.getGestureNumberOfSamples(this.submenuGesture.CurrentGesture); if (numSamples > 0) { gm.gr.deleteGestureSample(this.submenuGesture.CurrentGesture, numSamples - 1); } } else if (gm.gc != null) { int numSamples = gm.gc.getGestureNumberOfSamples(this.submenuGesture.CurrentPart, this.submenuGesture.CurrentGesture); if (numSamples > 0) { gm.gc.deleteGestureSample(this.submenuGesture.CurrentPart, this.submenuGesture.CurrentGesture, numSamples - 1); } } } break; case Operation.DeleteAllSamples: if (this.submenuGesture.CurrentGesture >= 0) { if (gm.gr != null) { gm.gr.deleteAllGestureSamples(this.submenuGesture.CurrentGesture); } else if (gm.gc != null) { gm.gc.deleteAllGestureSamples(this.submenuGesture.CurrentPart, this.submenuGesture.CurrentGesture); } } break; case Operation.NextGesture: { int numGestures = (gm.gr != null) ? gm.gr.numberOfGestures() : (gm.gc != null) ? gm.gc.numberOfGestures(this.submenuGesture.CurrentPart) : -1; if (numGestures == 0) { this.submenuGesture.CurrentGesture = -1; } else if (this.submenuGesture.CurrentGesture + 1 >= numGestures) { this.submenuGesture.CurrentGesture = 0; } else { this.submenuGesture.CurrentGesture++; } } break; case Operation.PreviousGesture: { int numGestures = (gm.gr != null) ? gm.gr.numberOfGestures() : (gm.gc != null) ? gm.gc.numberOfGestures(this.submenuGesture.CurrentPart) : -1; if (numGestures == 0) { this.submenuGesture.CurrentGesture = -1; } else if (this.submenuGesture.CurrentGesture - 1 < 0) { this.submenuGesture.CurrentGesture = numGestures - 1; } else { this.submenuGesture.CurrentGesture--; } } break; case Operation.NextPart: { if (gm.gc == null) { break; } int numParts = gm.gc.numberOfParts(); if (numParts == 0) { this.submenuGesture.CurrentPart = -1; } else if (this.submenuGesture.CurrentPart + 1 >= numParts) { this.submenuGesture.CurrentPart = 0; } else { this.submenuGesture.CurrentPart++; } } break; case Operation.PreviousPart: { if (gm.gc == null) { break; } int numParts = gm.gc.numberOfParts(); if (numParts == 0) { this.submenuGesture.CurrentPart = -1; } else if (this.submenuGesture.CurrentPart - 1 < 0) { this.submenuGesture.CurrentPart = numParts - 1; } else { this.submenuGesture.CurrentPart--; } } break; } GestureManagerVR.setInputFocus(null); this.submenuGesture.refesh(); }