Esempio n. 1
0
    void FixedUpdate()
    {
        // Fake mouse simulation
        //====================================================================
        // If brush button is down, then add to the painting
        // ---------------------test drawing using mouse left button
        if (Input.GetMouseButtonDown(0))
        {
            /*
             * paintingComponent.startNewStroke (painting, brushCursor);
             * Vertex v = new Vertex (
             *                 brushCursor.transform.position,
             *                 brushCursor.transform.rotation,
             *                 1,
             *                 new Vector3 (0, 0, 0)
             *         );
             * paintingComponent.AddVertex (v);
             *
             * isMousePressed = true;
             */
        }

        if (Input.GetMouseButtonUp(0))
        {
            isMousePressed = false;
            paintingComponent.EndStroke();
        }
        // ------------------------------------------------------------

        // If the hand button is down, then grab on to the painting and move it about
        if (Input.GetMouseButton(1))
        {
            Vector3    posChange = handPos - lastHandPos;
            Quaternion rotChange = Quaternion.Inverse(handRot) * lastHandRot;
            GameObject painting  = GameObject.Find("Painting");
            painting.transform.position += posChange;
            painting.transform.rotation *= rotChange;

            MenuManager.CurMenu.GetComponent <Menu> ().Clicked(brushCursor.transform.position);
        }

        if (isMousePressed)
        {
            // when the left mouse button pressed
            // continue to add vertex to line renderer
            Vertex v = new Vertex(
                brushCursor.transform.position,
                brushCursor.transform.rotation,
                1,
                new Vector3(0, 0, 0)
                );
            paintingComponent.AddVertex(v);
        }
        //====================================================================

        // Real time cave drawing
        //====================================================================
        if (user1StartDrawing)
        {
            drawingDebug.text = "Drawing user 1";
            if (user_id == 1 && !MenuManager.ShowMenu)
            {
                Vertex v = new Vertex(
                    brushCursor.transform.position,
                    brushCursor.transform.rotation,
                    1,
                    new Vector3(0, 0, 0)
                    );
                paintingComponent.AddVertex(v);
            }
        }

        if (user2StartDrawing)
        {
            if (user_id == 2 && !MenuManager.ShowMenu)
            {
                Vertex v = new Vertex(
                    brushCursor2.transform.position,
                    brushCursor2.transform.rotation,
                    1,
                    new Vector3(0, 0, 0)
                    );
                paintingComponent2.AddVertex(v);
            }
        }
        //====================================================================

        // Save the current state of the hand
        lastHandPos = handPos;
        lastHandRot = handRot;

        // test
        //MenuManager.drawDebugLine (GameObject.Find ("MenuContainer").transform.position, GameObject.Find ("MenuContainer").transform.position + new Vector3 (0, -10, 0), Color.blue);
        MenuManager.isHover(brushCursor.transform.position);
    }
Esempio 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)
            {
            }
        }
    }