示例#1
0
    void Update()
    {
        float dt = Time.deltaTime;

        if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) && Input.GetKeyDown(KeyCode.Q))
        {
            doQuit();
        }

        if (Input.GetKeyDown(KeyCode.H) || Input.GetKeyDown(KeyCode.F1))
        {
            helpScreen.ToggleVisibility();
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            helpScreen.Hide();
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            ResetMousePos();
            // Space bar toggles mode (walk/draw)
            if (mouseMode == MouseMode.Look)
            {
                mouseMode = MouseMode.Stick;
                sb.makeVisible();
            }
            else if (mouseMode == MouseMode.Stick)
            {
                sb.makeInvisible();
                mouseMode = MouseMode.Look;
            }
        }

        if (Input.GetKeyDown(KeyCode.LeftAlt) || Input.GetKeyDown(KeyCode.RightAlt) || Input.GetMouseButtonDown(1))
        {
            // Alt or RMB means "temporarily activate rotate mode"
            // Save current mode, make sure the stick/laser is hidden, and link
            // mouse position to object orientation.
            ResetMousePos();
            savedMode = mouseMode;
            if (mouseMode == MouseMode.Stick)
            {
                sb.makeInvisible();
            }
            mouseMode    = MouseMode.Rotate;
            surfaceDelta = surface.transform.position - camera.transform.position;
        }
        if (Input.GetKeyUp(KeyCode.LeftAlt) || Input.GetKeyUp(KeyCode.RightAlt) || Input.GetMouseButtonUp(1))
        {
            // Alt or RMB release means restore previous mode
            ResetMousePos();
            mouseMode = savedMode;
            if (mouseMode == MouseMode.Stick)
            {
                sb.makeVisible();
            }
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            // Clear all drawing on the PaintableTexture
            pt.Clear();
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            // Klein-Poincare toggle
            h2c.ToggleModel();
            h2c.ExportMode();
        }

        if (Input.GetKeyDown(KeyCode.O))
        {
            // Reset view position
            h2c.ResetPreTransformation();
            h2c.ExportPreTransformation();
        }
        if (Input.GetKey(KeyCode.I))
        {
            h2c.ComposePreTransformation(HypUtil.BoostY(-h2speed * dt));
            h2c.ExportPreTransformation();
        }

        if (Input.GetKey(KeyCode.K))
        {
            h2c.ComposePreTransformation(HypUtil.BoostY(h2speed * dt));
            h2c.ExportPreTransformation();
        }
        if (Input.GetKey(KeyCode.J))
        {
            h2c.ComposePreTransformation(HypUtil.BoostX(h2speed * dt));
            h2c.ExportPreTransformation();
        }
        if (Input.GetKey(KeyCode.L))
        {
            h2c.ComposePreTransformation(HypUtil.BoostX(-h2speed * dt));
            h2c.ExportPreTransformation();
        }


        // Walk & strafe according to keyboard
        float horiz = Input.GetAxis("Horizontal") * speed;
        float depth = Input.GetAxis("Vertical") * speed;

        camera.transform.Translate(horiz * dt, 0f, depth * dt);
        if (mouseMode == MouseMode.Rotate)
        {
            surface.transform.position = camera.transform.position + surfaceDelta;
        }

        if (mouseMode == MouseMode.Look)
        {
            Vector2 mp = AbsMousePos();
            camera.transform.localRotation = cameraInitQ * Quaternion.Euler(0, turnRange * mp.x, 0);
        }
        if (mouseMode == MouseMode.Stick)
        {
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetMouseButton(0))
            {
                sb.makeActive();
            }
            else
            {
                sb.makeInactive();
            }
            Vector2 mp = AbsMousePos();
            stickHolder.transform.localRotation = stickInitQ * Quaternion.Euler(-0.5f * stickRange * mp.y, 0, -0.5f * stickRange * mp.x);
        }
        if (mouseMode == MouseMode.Rotate)
        {
            Vector2 mp = AbsMousePos();
            // TODO: Make this a more intuitive trackball-style object rotation interface.
            surface.transform.localRotation = Quaternion.AngleAxis(turnRange * mp.y, camera.transform.right) * Quaternion.AngleAxis(-turnRange * mp.x, camera.transform.up) * surfaceInitQ;
        }
    }
示例#2
0
    void Update()
    {
        float dt = Time.deltaTime;

        // CTRL-Q on keyboard quits the application
        // (We expect that quit will sometimes be done after headset removal.)
        // TODO: Make a good way to quit from within VR scene.
        if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) && Input.GetKeyDown(KeyCode.Q))
        {
            doQuit();
        }

        if (!sb.visible())
        {
            sb.makeVisible();
        }

        if (Input.GetKeyDown(KeyCode.Y))
        {
            pt.NextTexture();
        }

        if (Input.GetKeyDown(KeyCode.H))
        {
            pt.PreviousTexture();
        }

        if (sb.isGrabbed())
        {
            if (sb.whichGrabbed() == "right")
            {
                // Laser pointer controls that only work if it is grabbed by the correct hand.
                if (OVRInput.GetDown(OVRInput.RawButton.RIndexTrigger))
                {
                    sb.makeActive();    // This setup gave tighter, more responsive controls.
                    sb.setColor();      // Toggling the drill and changing color were
                                        // under-responsive when executing with GetUp()
                }
                else if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger))
                {
                    sb.makeActive();
                }
                else
                {
                    sb.makeInactive();
                }
            }
            else if (sb.whichGrabbed() == "left")
            {
                if (OVRInput.GetDown(OVRInput.RawButton.LIndexTrigger))
                {
                    sb.makeActive();
                    sb.setColor();
                }
                else if (OVRInput.Get(OVRInput.RawButton.LIndexTrigger))
                {
                    sb.makeActive();
                }
                else
                {
                    sb.makeInactive();
                }
            }
        }
    }