Ejemplo n.º 1
0
    void OnVREvent(VREvent e)
    {
        if (e.Name == headTrackingEvent)
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray(matrix4x4DataField));
            transform.position = m.GetTranslation();
            transform.rotation = m.GetRotation();
            //Debug.Log("Head Position = " + m.GetTranslation().ToString());
            //Debug.Log("Head Rotation = " + m.GetRotation().ToString());

            Vector3 offsetInLocalCoords = new Vector3(0.0f, 0.0f, Camera.main.nearClipPlane + 0.001f);
            Vector3 offsetInWorldCoords = transform.TransformVector(offsetInLocalCoords);
            transform.position += offsetInWorldCoords;
        }
    }
Ejemplo n.º 2
0
    // This function gets called every time a new VREvent is generated.  Typically, VREvents will come
    // from the MinVR server, which polls trackers, buttons, and other input devices for input.  When
    // debugging on your laptop, you can also generate 'fake' VREvents using the VRMain script.
    void OnVREvent(VREvent e)
    {
        // USER 2 ==========================================================
        if (e.Name == "Brush2_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            brushPos = m.GetTranslation();
            brushRot = m.GetRotation();
            brushCursor2.transform.position = brushPos;
            brushCursor2.transform.rotation = brushRot;

            // Menu Selection ----------------------------------------------
            if (MenuManager.ShowMenu && user_id == 2)
            {
                // Color change when hover on the button
                MenuManager.isHover(brushCursor2.transform.position);
            }
        }
        else if (e.Name == "Hand2_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            handPos = m.GetTranslation();
            handRot = m.GetRotation();
            handCursor2.transform.position = handPos;
            handCursor2.transform.rotation = handRot;
        }
        else if (e.Name == "Head2_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            headPos = m.GetTranslation();
            headRot = m.GetRotation();
        }
        // Button Controls --------------------------------------------------
        else if (e.Name == "stylus0_btn1_up")
        {
            // stylys 0: blue pen

            if (user_id == 2)
            {
                // Show Main Menu
                if (MenuManager.CurMenu == null)
                {
                    // Open Main Menu
                    Menu mainMenu = null;
                    //Debug.Log (MenuManager.Menus.Count);
                    foreach (var item in MenuManager.Menus)
                    {
                        if (item.gameObject.name == "MainMenu")
                        {
                            mainMenu = item;
                            break;
                        }
                    }

                    if (mainMenu == null)
                    {
                        // TODO: catch could not find error
                    }
                    else
                    {
                        /*
                         * mainMenu.ShowMenu = true;
                         * mainMenu.gameObject.SetActive (true);
                         * MenuManager.CurMenu = mainMenu.gameObject;
                         * MenuManager.ShowMenu = true;
                         * Vector3 hpos = GameObject.Find ("User2").transform.position;
                         * MenuContainer.transform.position = new Vector3 (hpos.x, hpos.y - 70, hpos.z);
                         */
                        Vector3 hpos = GameObject.Find("User2").transform.position;

                        MenuManager.OpenMenu(mainMenu, new Vector3(hpos.x, hpos.y - 2, hpos.z), MenuContainer);
                    }
                }
                else
                {
                    MenuManager.CloseMenu();
                }
            }
        }
        else if (e.Name == "stylus0_btn0_down")
        {
            if (user_id == 2)
            {
                if (!MenuManager.ShowMenu)
                {
                    paintingComponent2.startNewStroke(painting2, brushCursor2);
                }
            }
            else if (user_id == 1)
            {
                // determine user 2 whether menu is open
            }
        }
        else if (e.Name == "stylus0_btn0_up")
        {
            if (user_id == 2)
            {
                if (MenuManager.ShowMenu)
                {
                    // Call the function when the button is selected
                    MenuManager.CurMenu.GetComponent <Menu> ().Clicked(brushCursor2.transform.position);
                }
                else
                {
                    paintingComponent2.EndStroke();
                }
            }
        }

        // USER 1 ==========================================================
        else if (e.Name == "Brush1_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            brushPos = m.GetTranslation();
            brushRot = m.GetRotation();
            brushCursor.transform.position = brushPos;
            brushCursor.transform.rotation = brushRot;

            if (MenuManager.ShowMenu && user_id == 1)
            {
                // Color change when hover on the button
                MenuManager.isHover(brushCursor.transform.position);
            }
        }
        else if (e.Name == "Hand1_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            handPos = m.GetTranslation();
            handRot = m.GetRotation();
            handCursor.transform.position = handPos;
            handCursor.transform.rotation = handRot;
        }
        else if (e.Name == "Head1_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            headPos = m.GetTranslation();
            headRot = m.GetRotation();
        }
        // Button Controls --------------------------------------------------
        else if (e.Name == "stylus1_btn1_up")
        {
            // stylys 1: red pen

            if (user_id == 1)
            {
                // Show Main Menu
                if (MenuManager.CurMenu == null)
                {
                    // Open Main Menu
                    Menu mainMenu = null;
                    Debug.Log(MenuManager.Menus.Count);
                    foreach (var item in MenuManager.Menus)
                    {
                        if (item.gameObject.name == "MainMenu")
                        {
                            mainMenu = item;
                            break;
                        }
                    }

                    if (mainMenu == null)
                    {
                        // TODO: catch could not find error
                    }
                    else
                    {
                        /*
                         * mainMenu.ShowMenu = true;
                         * mainMenu.gameObject.SetActive (true);
                         * MenuManager.CurMenu = mainMenu.gameObject;
                         * MenuManager.ShowMenu = true;
                         * Vector3 hpos = GameObject.Find ("User1").transform.position;
                         * MenuContainer.transform.position = new Vector3 (hpos.x, hpos.y - 70, hpos.z);
                         */

                        Vector3 hpos = GameObject.Find("User1").transform.position;

                        MenuManager.OpenMenu(mainMenu, new Vector3(hpos.x, hpos.y - 2, hpos.z), MenuContainer);
                    }
                }
                else
                {
                    MenuManager.CloseMenu();
                }
            }
        }
        else if (e.Name == "stylus1_btn0_down")
        {
            if (user_id == 1)
            {
                if (!MenuManager.ShowMenu)
                {
                    paintingComponent.startNewStroke(painting, brushCursor);
                }
            }
            else if (user_id == 2)
            {
                // determine user 1 whether menu is open
            }
        }
        else if (e.Name == "stylus1_btn0_up")
        {
            if (user_id == 1)
            {
                if (MenuManager.ShowMenu)
                {
                    // Call the function when the button is selected
                    MenuManager.CurMenu.GetComponent <Menu> ().Clicked(brushCursor.transform.position);
                }
                else
                {
                    paintingComponent.EndStroke();
                }
            }
        }
        // Client input events -----------------------------------------------
        else if (e.Name == "Type_Change")
        {
            if (user_id == 1)
            {
            }
            else if (user_id == 2)
            {
            }
        }
        else if (e.Name == "Color_Change")
        {
            if (user_id == 1)
            {
            }
            else if (user_id == 2)
            {
            }
        }
        else if (e.Name == "Start_Collaboration")
        {
            if (user_id == 1)
            {
            }
            else if (user_id == 2)
            {
            }
        }
    }
Ejemplo n.º 3
0
 // This function gets called every time a new VREvent is generated.  Typically, VREvents will come
 // from the MinVR server, which polls trackers, buttons, and other input devices for input.  When
 // debugging on your laptop, you can also generate 'fake' VREvents using the VRMain script.
 void OnVREvent(VREvent e)
 {
     if (e.Name == "Brush_Move")             // for faster user 2
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         brushPos = m.GetTranslation();
         brushRot = m.GetRotation();
         brushCursor.transform.position = brushPos;
         brushCursor.transform.rotation = brushRot;
     }
     else if (e.Name == "Hand_Move")
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         handPos = m.GetTranslation();
         handRot = m.GetRotation();
         handCursor.transform.position = handPos;
         handCursor.transform.rotation = handRot;
     }
     else if (e.Name == "user_header_1" && user_id)             // for cave painting system user 1
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         headPos = m.GetTranslation();
         headRot = m.GetRotation();
         headObj.transform.position = headPos;
         headObj.transform.rotation = headRot;
     }
     else if (e.Name == "user_header_2" && !user_id)             // for cave painting system user 2
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         handPos = m.GetTranslation();
         handRot = m.GetRotation();
         headObj.transform.position = headPos;
         headObj.transform.rotation = headRot;
     }
     else if (e.Name == "Head_Move")
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         headPos = m.GetTranslation();
         handRot = m.GetRotation();
     }
     else if (e.Name == "Mouse_Down")                // TODO : useless for now
     {
         Debug.Log("mouse down");
     }
     else if (e.Name == "Mouse_Up")
     {
         Debug.Log("mouse up");
     }
     else if (e.Name == "stylus1_btn0_down")                    // user 2 start to draw
     {
         startDrawing = true;
         Debug.Log("Red User 2 drawing down");
     }
     else if (e.Name == "stylus1_btn0_up")
     {
         startDrawing = false;
         Debug.Log("Red User 2 drawing up");
     }
     else if (e.Name == "stylus1_btn1_down")                // controll what user 2 see
     // TODO : manipulate User 2 camera
     {
         Debug.Log("Red User 2 control down");
     }
     else if (e.Name == "stylus1_btn1_up")
     {
         // TODO : .... I don't know for now
         Debug.Log("Red User 2 control up");
     }
     else if (e.Name == "stylus1_btn1_down")                // user 1 start to draw
     {
         startDrawing = true;
         Debug.Log("Red User 1 control down");
     }
     else if (e.Name == "stylus1_btn1_up")
     {
         startDrawing = false;
         Debug.Log("Red User 1 control up");
     }
     else if (e.Name == "stylus1_btn1_down")                // controll what user 1 see
     // TODO : manipulate User 1 camera
     {
         Debug.Log("Red User 1 control down");
     }
     else if (e.Name == "stylus1_btn1_up")
     {
         // TODO : .... I don't know for now
         Debug.Log("Red User 1 control up");
     }
 }