void OnGUI() { //GUI.skin = guiskin; float screenH8th = Screen.height / 8.0f; float screenH4th = Screen.height / 4.0f; float screenHHalf = Screen.height / 2.0f; float screenW8th = Screen.width / 8.0f; float screenW4th = Screen.width / 4.0f; float screenWHalf = Screen.width / 2.0f; // AA: commented fubi button // if (FubiUnity.FubiButton (new Rect (screenW8th, screenH8th, screenW8th, 100), "Fubi Button", "FubiButton")) // { // buttonPressed = true; // } // AA: commented fubi swipe menu // string selection = FubiUnity.FubiSwipeMenu(new Vector2(screenWHalf, screenHHalf), screenH4th, options, "FubiSwipeMenu", "FubiSwipeCenter"); // if (selection.Length > 0) // swipeMenuSelection = selection; // AA: commented fubi gesture animation if (FubiUnity.FubiGesture(new Rect(screenWHalf + screenW8th, screenH8th, screenW8th, screenH4th), "RightHandWavingAboveTheShoulder", new GUIStyle())) { gesturePerformed = true; } // AA: No messages required // if (buttonPressed) // GUI.Box(new Rect (screenW8th, screenHHalf + screenH4th, screenW4th, 100), "Button pressed!"); // // if (swipeMenuSelection.Length > 0) // GUI.Box(new Rect (screenWHalf - screenW8th, screenHHalf + screenH4th, screenW4th, 100), "Last Selection: "+swipeMenuSelection); // // if (gesturePerformed) // GUI.Box (new Rect (screenWHalf + screenW8th, screenHHalf + screenH4th, screenW4th, 100), "Waving gesture performed!"); }
// Initialization void Start() { //AA: Filter visalization related initializations filter = new Filter(); fv = new FilterVisualization(); fm = new FilterManager(); fv.filterOutputLocX = Screen.width / 3 - 50; fv.Initialise(); fv.DrawCircle(); m_colorTextureDictionary = new Dictionary <string, Texture2D>(); foreach (Texture2D tex in m_colorTextures) { m_colorTextureDictionary.Add(tex.name, tex); } LoadFilters(); // First set instance so Fubi.release will not be called while destroying old objects instance = this; // Remain this instance active until new one is created DontDestroyOnLoad(this); // Destroy old instance of Fubi object[] objects = GameObject.FindObjectsOfType(typeof(FubiUnity)); if (objects.Length > 1) { Destroy(((FubiUnity)objects[0])); } m_lastMouseClick = 0; m_lastGesture = 0; // Init FUBI if (!m_disableFubi) { // Only init if not already done if (!Fubi.isInitialized()) { Fubi.init(new FubiUtils.SensorOptions(new FubiUtils.StreamOptions(640, 480, 30), new FubiUtils.StreamOptions(640, 480, 30), new FubiUtils.StreamOptions(-1, -1, -1), FubiUtils.SensorType.OPENNI2), new FubiUtils.FilterOptions()); if (!Fubi.isInitialized()) { Debug.Log("Fubi: FAILED to initialize Fubi!"); } else { Debug.Log("Fubi: initialized!"); } } } else { m_disableTrackingImage = true; } // Initialize debug image // m_depthMapTexture = new Texture2D((int)(m_xRes / m_factor), (int)(m_yRes / m_factor), TextureFormat.RGBA32, false); // m_depthMapPixels = new Color[(int)((m_xRes / m_factor) * (m_yRes / m_factor))]; // m_rawImage = new byte[(int)(m_xRes * m_yRes * 4)]; m_userImageTexture = null; // Disable system cursor if (m_defaultCursor != null && m_disableFubi == false) { Screen.showCursor = false; } else { Screen.showCursor = true; } // Default mapping values m_mapping.x = -100.0f; m_mapping.y = 200.0f; m_mapping.height = 550.0f; // Get screen aspect m_aspect = (float)Screen.width / (float)Screen.height; // Calculated Map width with aspect m_mapping.width = m_mapping.height / m_aspect; if (Fubi.isInitialized()) { // Clear old gesture recognizers Fubi.clearUserDefinedRecognizers(); // And (re)load them if (Fubi.loadRecognizersFromXML("UnitySampleRecognizers.xml")) { Debug.Log("Fubi: gesture recognizers 'BarRecognizers.xml' loaded!"); } else { Debug.Log("Fubi: loading XML recognizers failed!"); } // load mouse control recognizers if (Fubi.loadRecognizersFromXML("MouseControlRecognizers.xml")) { Debug.Log("Fubi: mouse control recognizers loaded!"); } else { Debug.Log("Fubi: loading mouse control recognizers failed!"); } } }
// // Swipe recognition vars // private bool m_swipeMenuActive = false; // bool m_swipeMenuDisplayedLastFrame = false; // bool m_swipeMenuDisplayed = false; // // For the right hand // private string[][] m_swipeRecognizers; // private double m_lastSwipeRecognition = 0; // private double[][] m_lastSwipeRecognitions; // private uint m_handToFrontRecognizer; // private double m_lastHandToFront = 0, m_handToFrontEnd = 0; // // And for the left hand // private string[][] m_leftSwipeRecognizers; // private double m_lastLeftSwipeRecognition = 0; // private double[][] m_lastLeftSwipeRecognitions; // private uint m_leftHandToFrontRecognizer; // private double m_lastLeftHandToFront = 0, m_leftHandToFrontEnd = 0; // // Template for the swipe gesture recognizers // string m_swipeCombinationXMLTemplate = @"<CombinationRecognizer name=""{0}""> // <State minDuration=""0.2"" maxInterruptionTime=""0.1"" timeForTransition=""0.7""> // <Recognizer name=""{1}""/> // <Recognizer name=""{2}""/> // </State> // <State> // <Recognizer name=""{3}""/> // </State> // </CombinationRecognizer>"; // Initialization void Start() { //AA: Our filter class filter = new Filter(); // First set instance so Fubi.release will not be called while destroying old objects instance = this; // Remain this instance active until new one is created DontDestroyOnLoad(this); // Destroy old instance of Fubi object[] objects = GameObject.FindObjectsOfType(typeof(FubiUnity)); if (objects.Length > 1) { Destroy(((FubiUnity)objects[0])); } // AA: delete, we don't need gestures // // Load gesture symbols (might be specific to that scene) // for (int i=0; i < m_gestureSymbols.Length; ++i) // { // if (m_gestureSymbols[i].Length == 1) // m_gestureSymbolDict.Add(m_gestureSymbols[i][0].name, m_gestureSymbols[i]); // else if (m_gestureSymbols[i].Length >= 1) // m_gestureSymbolDict.Add(m_gestureSymbols[i][0].name.Substring(0, m_gestureSymbols[i][0].name.Length-1), m_gestureSymbols[i]); // } m_lastMouseClick = 0; m_lastGesture = 0; // Init FUBI if (!m_disableFubi) { // Only init if not already done if (!Fubi.isInitialized()) { Fubi.init(new FubiUtils.SensorOptions(new FubiUtils.StreamOptions(640, 480, 30), new FubiUtils.StreamOptions(640, 480, 30), new FubiUtils.StreamOptions(-1, -1, -1), FubiUtils.SensorType.OPENNI2), new FubiUtils.FilterOptions()); if (!Fubi.isInitialized()) Debug.Log("Fubi: FAILED to initialize Fubi!"); else { Debug.Log("Fubi: initialized!"); } } } else m_disableTrackingImage = true; // Initialize debug image m_depthMapTexture = new Texture2D((int)(m_xRes / m_factor), (int)(m_yRes / m_factor), TextureFormat.RGBA32, false); m_depthMapPixels = new Color[(int)((m_xRes / m_factor) * (m_yRes / m_factor))]; m_rawImage = new byte[(int)(m_xRes * m_yRes * 4)]; m_userImageTexture = null; // Disable system cursor if (m_defaultCursor != null && m_disableFubi == false) Screen.showCursor = false; else Screen.showCursor = true; // Default mapping values // m_mapping.x = -100.0f; // m_mapping.y = 200.0f; // m_mapping.height = 550.0f; m_mapping.x = -100.0f; m_mapping.y = 200.0f; m_mapping.height = 550.0f; // Get screen aspect m_aspect = (float)Screen.width / (float)Screen.height; // Calculated Map width with aspect m_mapping.width = m_mapping.height / m_aspect; if (Fubi.isInitialized()) { // Clear old gesture recognizers Fubi.clearUserDefinedRecognizers(); // And (re)load them if (Fubi.loadRecognizersFromXML("UnitySampleRecognizers.xml")) Debug.Log("Fubi: gesture recognizers 'BarRecognizers.xml' loaded!"); else Debug.Log("Fubi: loading XML recognizers failed!"); // load mouse control recognizers if (Fubi.loadRecognizersFromXML("MouseControlRecognizers.xml")) Debug.Log("Fubi: mouse control recognizers loaded!"); else Debug.Log("Fubi: loading mouse control recognizers failed!"); } //AA: we don't need swipe code // // Recognizer for activating the swipe menu // m_handToFrontRecognizer = Fubi.addJointRelationRecognizer(FubiUtils.SkeletonJoint.RIGHT_HAND, // FubiUtils.SkeletonJoint.RIGHT_SHOULDER, -200.0f, -200.0f, float.MinValue, 300.0f, 300.0f, -250.0f); // // Swipe recognizers for 1 to 12 options in a swipe menu // m_swipeRecognizers = new string[12][]; // m_lastSwipeRecognitions = new double[12][]; // for (uint i = 0; i < 12; ++i) // { // uint len = i + 1; // float rotAdd = 2.0f * Mathf.PI / len; // float maxAngleDiff = Mathf.Min(45.0f, 360.0f / len); // m_swipeRecognizers[i] = new string[len]; // m_lastSwipeRecognitions[i] = new double[len]; // for (uint j = 0; j < len; ++j) // { // float currRot = j * rotAdd; // if (i < 2) // currRot += Mathf.PI / 2.0f; // float dirX = Mathf.Sin(currRot); // float dirY = Mathf.Cos(currRot); // m_lastSwipeRecognitions[i][j] = 0; // uint movRecIndex = Fubi.addLinearMovementRecognizer( // FubiUtils.SkeletonJoint.RIGHT_HAND, // FubiUtils.SkeletonJoint.RIGHT_SHOULDER, // dirX, dirY, 0, 250.0f, float.MaxValue, false, -1, null, maxAngleDiff); // uint movPosRecIndex = Fubi.addJointRelationRecognizer( // FubiUtils.SkeletonJoint.RIGHT_HAND, // FubiUtils.SkeletonJoint.RIGHT_SHOULDER, // (dirX < -0.05f) ? float.MinValue : -200.0f, // (dirY < -0.05f) ? float.MinValue : -200.0f, // float.MinValue, // (dirX > 0.05f) ? float.MaxValue : 300.0f, // (dirY > 0.05f) ? float.MaxValue : 300.0f, // -125.0f); // uint stopRecIndex = Fubi.addJointRelationRecognizer( // FubiUtils.SkeletonJoint.RIGHT_HAND, // FubiUtils.SkeletonJoint.RIGHT_SHOULDER, // (dirX > 0.05f) ? (150.0f * dirX) : float.MinValue, // (dirY > 0.05f) ? (100.0f * dirY) : float.MinValue, // float.MinValue, // (dirX < -0.05f) ? (100.0f * dirX) : float.MaxValue, // (dirY < -0.05f) ? (150.0f * dirY) : float.MaxValue, // float.MaxValue); // string name = string.Format("swipeRec{0}", movRecIndex); // string combinationDef = string.Format(m_swipeCombinationXMLTemplate, name, movRecIndex, movPosRecIndex, stopRecIndex); // if (Fubi.addCombinationRecognizer(combinationDef)) // m_swipeRecognizers[i][j] = name; // else m_swipeRecognizers[i][j] = ""; // } // } // // Now for the left hand // m_leftHandToFrontRecognizer = Fubi.addJointRelationRecognizer(FubiUtils.SkeletonJoint.LEFT_HAND, // FubiUtils.SkeletonJoint.LEFT_SHOULDER, -300.0f, -200.0f, float.MinValue, 200.0f, 300.0f, -250.0f); // // Swipe recognizers for 1 to 12 options in a swipe menu // m_leftSwipeRecognizers = new string[12][]; // m_lastLeftSwipeRecognitions = new double[12][]; // for (uint i = 0; i < 12; ++i) // { // uint len = i + 1; // float rotAdd = 2.0f * Mathf.PI / len; // float maxAngleDiff = Mathf.Min(45.0f, 360.0f / len); // m_leftSwipeRecognizers[i] = new string[len]; // m_lastLeftSwipeRecognitions[i] = new double[len]; // for (uint j = 0; j < len; ++j) // { // float currRot = j * rotAdd; // if (i < 2) // currRot += Mathf.PI / 2.0f; // float dirX = Mathf.Sin(currRot); // float dirY = Mathf.Cos(currRot); // m_lastLeftSwipeRecognitions[i][j] = 0; // uint movRecIndex = Fubi.addLinearMovementRecognizer( // FubiUtils.SkeletonJoint.LEFT_HAND, // FubiUtils.SkeletonJoint.LEFT_SHOULDER, // dirX, dirY, 0, 250.0f, float.MaxValue, false, -1, null, maxAngleDiff); // uint movPosRecIndex = Fubi.addJointRelationRecognizer( // FubiUtils.SkeletonJoint.LEFT_HAND, // FubiUtils.SkeletonJoint.LEFT_SHOULDER, // (dirX < -0.05f) ? float.MinValue : -300.0f, // (dirY < -0.05f) ? float.MinValue : -200.0f, // float.MinValue, // (dirX > 0.05f) ? float.MaxValue : 200.0f, // (dirY > 0.05f) ? float.MaxValue : 300.0f, // -125.0f); // uint stopRecIndex = Fubi.addJointRelationRecognizer( // FubiUtils.SkeletonJoint.LEFT_HAND, // FubiUtils.SkeletonJoint.LEFT_SHOULDER, // (dirX > 0.05f) ? (100.0f * dirX) : float.MinValue, // (dirY > 0.05f) ? (100.0f * dirY) : float.MinValue, // float.MinValue, // (dirX < -0.05f) ? (150.0f * dirX) : float.MaxValue, // (dirY < -0.05f) ? (150.0f * dirY) : float.MaxValue, // float.MaxValue); // string name = string.Format("swipeLeftRec{0}", movRecIndex); // string combinationDef = string.Format(m_swipeCombinationXMLTemplate, name, movRecIndex, movPosRecIndex, stopRecIndex); // if (Fubi.addCombinationRecognizer(combinationDef)) // m_leftSwipeRecognizers[i][j] = name; // else m_leftSwipeRecognizers[i][j] = ""; // } // } }