Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        findPlaneClosestTo3DCursor();
        // the interaction cursor is positioned where the cursor is
        //interactionCursor.transform.position = calcInteractionCursorPosition ();

        // debugging purposes
        if (debugMode)
        {
            DrawDebug();
        }

        DrawCursor(StripWidth);
        // change the orientation of the strip on the basis of the joystick press right
        if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickRight, _dominantHand))
        {
            CursorOrientationFactor += 0.02f;
            //StrokeOrientation = Vector3.RotateTowards (StrokeOrientation, OVRInput.GetLocalControllerRotation (OVRInput.Controller.RTouch) * Vector3.right, 0.05f, 0.0f);
        }
        else if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickLeft, _dominantHand))
        {
            CursorOrientationFactor -= 0.02f;
            //StrokeOrientation = Vector3.RotateTowards (StrokeOrientation, OVRInput.GetLocalControllerRotation (OVRInput.Controller.RTouch) * Vector3.up, 0.05f, 0.0f);
        }

        /*
         * // change the transparency of the avatar if the controller button 'A' is pressed. This was done so that I could see the 3D strokes that I have made more clearly
         * if (OVRInput.Get (OVRInput.Button.Two, OVRInput.Controller.RTouch)) {
         *      _baseMeshRenderer.material.color = new Color(_baseMeshRenderer.material.color.r, _baseMeshRenderer.material.color.g, _baseMeshRenderer.material.color.b, 0.0f);
         *      //baseMesh.SetActive (false);
         * } else {
         *      //baseMesh.SetActive (true);
         *      _baseMeshRenderer.material.color = new Color(_baseMeshRenderer.material.color.r, _baseMeshRenderer.material.color.g, _baseMeshRenderer.material.color.b, 1.0f);
         * }
         */

        // Lets try giving the user a control on determining the distance of the 3D cursor from the controller. "A" button brings the cursor closer and "B" button pushes it away
        if (OVRInput.Get(OVRInput.Button.Two, _dominantHand))
        {
            _cursorDistance += _cursorDistanceSpeed;
        }
        if (OVRInput.Get(OVRInput.Button.One, _dominantHand))
        {
            _cursorDistance -= _cursorDistanceSpeed;
        }

        // Change the width of the strip on the basis of the joystick press down
        if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickUp, _dominantHand))
        {
            StripWidth += stripWidthChangeFactor;
        }
        else if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickDown, _dominantHand))
        {
            StripWidth -= stripWidthChangeFactor;
        }

        // Start and stop the strip drawing process
        // create the strip gameobject and setup initial parameters
        if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, _dominantHand))
        {
            GameObject go = createStrokeGameObject();
            _currLine = go.AddComponent <MeshLineRenderer> ();
            _currLine.SetMaterial(new Material(strokeMat));
            _currLine.setWidth(StripWidth);
            _currLine.SetOrientation(calcCursorOrientation());
            //currLine.endWidth = 0.1f;
            numClicks     = 0;
            _prevPoint    = calcCursorPosition();
            ModeDetermine = "drawing";
        }
        // add strips to the existing stroke that you are drawing
        else if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, _dominantHand))
        {
            //currLine.positionCount = numClicks + 1;
            //currLine.SetPosition (numClicks, OVRInput.GetLocalControllerPosition (OVRInput.Controller.RTouch));
            _currLine.setWidth(StripWidth);
            _currPoint = calcCursorPosition();
            cleanPoint(_currLine, _currPoint);
            _currLine.SetOrientation(calcCursorOrientation());
            _prevPoint = _currPoint;
            numClicks++;
        }
        // when you stop drawing change the mode to idle so that you can respond to ui changes again
        else if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, _dominantHand))
        {
            ModeDetermine = "idle";
        }


        /*
         * if (CollisionDetector.CollidingBodyPart != null) {
         *      Debug.Log (CollisionDetector.CollidingBodyPart.transform.name);
         * }*/

        // event system for detecting the frame where gripDown happens
        if (OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, _dominantHand) > 0.9f)
        {
            if (_gripDownCount == 0)
            {
                _gripDownCount = 1;
                _gripDown      = true;
            }
            else
            {
                _gripDown = false;
            }
        }
        else
        {
            if (_gripDownCount == 1)
            {
                _gripDownCount = 0;
            }
        }

        // assigning the origin of the drawing surface as this origin's x,y has to be defined in order to use the magnified surface.
        if (_gripDown)
        {
            if (_originCursorPosition == new Vector3())
            {
                _originCursorPosition = calcCursorPosition();
                _originCursorRotation = OVRInput.GetLocalControllerRotation(_dominantHand);
                Vector3 scale = new Vector3(0.02f, 0.02f, 0.02f);
                GenerateGrid(_originCursorPosition, _originCursorRotation, scale);
            }
            else
            {
                _originCursorPosition = new Vector3();
                _originCursorRotation = new Quaternion();
                _grid.SetActive(false);
            }
        }
    }