Esempio n. 1
0
        public override void UpdateModule()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);

            m_LastMousePosition = m_MousePosition;
            m_MousePosition     = Input.mousePosition;
        }
Esempio n. 2
0
        void HandleNoRayHit()
        {
            float distance = rayDrawDistance;

            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray ray = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            SetPointerVisibility();

            if (linePointer != null)
            {
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, rayDrawDistance))
                {
                    distance = hit.distance;
                }
                linePointer.SetPosition(0, ray.origin);
                linePointer.SetPosition(1, ray.origin + ray.direction * distance);
            }

            if (gazePointer != null)
            {
                gazePointer.gameObject.SetActive(gazePointerVisibility);
                gazePointer.position = ray.origin + ray.direction * distance;
            }
        }
Esempio n. 3
0
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray selectionRay = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            SetPointerVisibility();
            SetPointer(selectionRay);
        }
Esempio n. 4
0
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray selectionRay = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            if (Application.isEditor)
            {
                // WM: in Editor, force right touch controller to be active.
                activeController = OVRInput.Controller.RTouch;
                selectionRay     = EditorRay;
            }

            SetPointerVisibility();
            SetPointer(selectionRay);
        }
Esempio n. 5
0
        void HandleSelectionRayHit(Vector3 hitPosition, Vector3 hitNormal)
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray ray = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            SetPointerVisibility();

            if (linePointer != null)
            {
                linePointer.SetPosition(0, ray.origin);
                linePointer.SetPosition(1, hitPosition);
            }

            if (gazePointer != null)
            {
                gazePointer.gameObject.SetActive(true);
                gazePointer.position = hitPosition;
            }
        }
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray pointer = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            RaycastHit hit; // Was anything hit?

            if (Physics.Raycast(pointer, out hit, raycastDistance, ~excludeLayers))
            {
                if (lastHit != null && lastHit != hit.transform) // if we hit a different object, exit hover for old object
                {
                    if (onHoverExit != null)
                    {
                        onHoverExit.Invoke(lastHit);
                    }
                    lastHit = null;
                }

                if (lastHit == null) // we hit something, enter hover
                {
                    if (onHoverEnter != null)
                    {
                        onHoverEnter.Invoke(hit.transform);
                    }
                }

                if (onHover != null) // hover (not enter hover, rather the callback called every time while hovering)
                {
                    onHover.Invoke(hit.transform);
                }

                lastHit = hit.transform;


                if (activeController != OVRInput.Controller.None) // Handle selection callbacks
                {
                    if (OVRInput.GetDown(primaryButton, activeController))
                    {
                        triggerDown = lastHit;

                        if (onSelect != null)
                        {
                            onSelect.Invoke(triggerDown);
                        }
                    }
                }
            }

            else if (lastHit != null) // Nothing was hit, handle exit callback
            {
                if (onHoverExit != null)
                {
                    onHoverExit.Invoke(lastHit);
                }
                lastHit = null;
            }

            if (OVRInput.GetUp(primaryButton, activeController)) // handle deselect
            {
                if (onDeselect != null && triggerDown != null)
                {
                    onDeselect.Invoke(triggerDown);
                    triggerDown = null;
                }
            }
        }
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            if (leftPress)
            {
                activeController = OVRInput.Controller.RTouch;
            }
            if (rightPress)
            {
                activeController = OVRInput.Controller.LTouch;
            }
            VisualizerScript.setController(activeController);
            Debug.Log("active controller " + activeController);
            Debug.Log("lpress " + leftPress + ", rightPres " + rightPress);


            Ray pointer = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            RaycastHit hit; // Was anything hit?

            if (Physics.Raycast(pointer, out hit, raycastDistance, ~excludeLayers))
            {
                if (lastHit != null && lastHit != hit.transform) // if we hit a different object, exit hover for old object
                {
                    if (onHoverExit != null)
                    {
                        onHoverExit.Invoke(lastHit, isLeftController(activeController));
                    }
                    lastHit = null;
                }

                if (lastHit == null) // we hit something, enter hover
                {
                    if (onHoverEnter != null)
                    {
                        onHoverEnter.Invoke(hit.transform, isLeftController(activeController));
                    }
                }

                if (onHover != null) // hover (not enter hover, rather the callback called every time while hovering)
                {
                    onHover.Invoke(hit.transform, isLeftController(activeController));
                }

                lastHit = hit.transform;


                if (activeController != OVRInput.Controller.None) // Handle selection callbacks
                {
                    if (OVRInput.GetDown(primaryButton, activeController))
                    {
                        if (isLeftController(activeController))
                        {
                            leftPress             = true;
                            leftSelectedTransform = lastHit;
                        }
                        else
                        {
                            rightPress             = true;
                            rightSelectedTransform = lastHit;
                        }

                        if (onSelect != null && lastHit != null)
                        {
                            onSelect.Invoke(lastHit, isLeftController(activeController));
                        }
                    }
                }
            }

            else if (lastHit != null) // Nothing was hit, handle exit callback
            {
                if (onHoverExit != null)
                {
                    onHoverExit.Invoke(lastHit, isLeftController(activeController));
                }
                lastHit = null;
            }

            if (OVRInput.GetUp(primaryButton, OVRInput.Controller.LTouch)) // handle deselect
            {
                if (onDeselect != null && leftSelectedTransform != null)
                {
                    onDeselect.Invoke(leftSelectedTransform, true);
                    leftSelectedTransform = null;
                    leftPress             = false;
                }
            }
            if (OVRInput.GetUp(primaryButton, OVRInput.Controller.RTouch)) // handle deselect
            {
                if (onDeselect != null && rightSelectedTransform != null)
                {
                    onDeselect.Invoke(rightSelectedTransform, false);
                    rightSelectedTransform = null;
                    rightPress             = false;
                }
            }
        }
Esempio n. 8
0
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray pointer = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            RaycastHit hit; // Was anything hit?

            if (Physics.Raycast(pointer, out hit, raycastDistance, ~excludeLayers))
            {
                if (lastHit != null && lastHit != hit.transform)
                {
                    if (onHoverExit != null)
                    {
                        onHoverExit.Invoke(lastHit);
                    }
                    lastHit = null;
                }

                if (lastHit == null)
                {
                    if (onHoverEnter != null)
                    {
                        onHoverEnter.Invoke(hit.transform);
                    }
                }

                if (onHover != null)
                {
                    onHover.Invoke(hit.transform);
                    if (OVRInput.Get(OVRInput.Button.Two))
                    {
                        print("Terrain touche !");
                        tempFile = hit.transform.GetComponent <createTerrain>();

                        if (_outils == OutilsChoix.MONTER)
                        {
                            tempFile.ModifPosY(hit.point, forcePointer, sizePointer);
                        }
                        else if (_outils == OutilsChoix.DESCENDRE)
                        {
                            tempFile.ModifPosY(hit.point, -forcePointer, sizePointer);
                        }
                    }
                }

                lastHit = hit.transform;

                // Handle selection callbacks. An object is selected if the button selecting it was
                // pressed AND released while hovering over the object.
                if (activeController != OVRInput.Controller.None)
                {
                    if (OVRInput.GetDown(secondaryButton, activeController))
                    {
                        padDown = lastHit;
                    }
                    else if (OVRInput.GetUp(secondaryButton, activeController))
                    {
                        if (padDown != null && padDown == lastHit)
                        {
                            if (onSecondarySelect != null)
                            {
                                onSecondarySelect.Invoke(padDown);
                            }
                        }
                    }
                    if (!OVRInput.Get(secondaryButton, activeController))
                    {
                        padDown = null;
                    }

                    if (OVRInput.GetDown(primaryButton, activeController))
                    {
                        triggerDown = lastHit;
                    }
                    else if (OVRInput.GetUp(primaryButton, activeController))
                    {
                        if (triggerDown != null && triggerDown == lastHit)
                        {
                            if (onPrimarySelect != null)
                            {
                                onPrimarySelect.Invoke(triggerDown);
                            }
                        }
                    }
                    if (!OVRInput.Get(primaryButton, activeController))
                    {
                        triggerDown = null;
                    }
                }
#if UNITY_ANDROID && !UNITY_EDITOR
                // Gaze pointer fallback
                else
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        triggerDown = lastHit;
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        if (triggerDown != null && triggerDown == lastHit)
                        {
                            if (onPrimarySelect != null)
                            {
                                onPrimarySelect.Invoke(triggerDown);
                            }
                        }
                    }
                    if (!Input.GetMouseButton(0))
                    {
                        triggerDown = null;
                    }
                }
#endif
            }
            // Nothing was hit, handle exit callback
            else if (lastHit != null)
            {
                if (onHoverExit != null)
                {
                    onHoverExit.Invoke(lastHit);
                }
                lastHit = null;
            }
        }
Esempio n. 9
0
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray pointer = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            RaycastHit hit; // Was anything hit?

            if (Physics.Raycast(pointer, out hit, raycastDistance, ~excludeLayers))
            {
                myHitPos = hit.point;
                myOVRPointerVisualizer.rayDrawDistance = hit.distance;
                //Debug.Log(hit.distance);


                if (lastHit != null && lastHit != hit.transform)
                {
                    if (onHoverExit != null)
                    {
                        onHoverExit.Invoke(lastHit);
                    }
                    lastHit = null;
                }

                if (lastHit == null)
                {
                    if (onHoverEnter != null)
                    {
                        onHoverEnter.Invoke(hit.transform);
                    }
                }

                if (onHover != null)
                {
                    onHover.Invoke(hit.transform);
                }

                lastHit = hit.transform;

                // Handle selection callbacks. An object is selected if the button selecting it was
                // pressed AND released while hovering over the object.

                if (activeController != OVRInput.Controller.None)
                {
                    if (OVRInput.GetDown(secondaryButton, activeController))
                    {
                        secondaryDown = lastHit;
                        //Debug.Log("1");
                    }
                    else if (OVRInput.GetUp(secondaryButton, activeController))
                    {
                        if (secondaryDown != null && secondaryDown == lastHit)
                        {
                            if (onSecondarySelect != null)
                            {
                                onSecondarySelect.Invoke(secondaryDown, pointer);
                                //Debug.Log("2");
                            }
                        }
                    }
                    if (!OVRInput.Get(secondaryButton, activeController))
                    {
                        secondaryDown = null;
                        //Debug.Log("3");
                    }

                    if (OVRInput.GetDown(primaryButton, activeController))
                    {
                        primaryDown = lastHit;
                        //Debug.Log("4");
                    }
                    else if (OVRInput.GetUp(primaryButton, activeController))
                    {
                        if (primaryDown != null && primaryDown == lastHit)
                        {
                            if (onPrimarySelect != null)
                            {
                                onPrimarySelect.Invoke(primaryDown, pointer);
                                //Debug.Log("5");
                            }
                        }
                    }
                    if (!OVRInput.Get(primaryButton, activeController))
                    {
                        primaryDown = null;
                        //Debug.Log("6");
                    }
                }

                if (lastHit)
                {
                    ///
                    if (OVRInput.Get(aButton, activeController))
                    {
                        aDown = lastHit;
                    }
                    else
                    {
                        aDown = null;
                    }
                    if (OVRInput.Get(bButton, activeController))
                    {
                        bDown = lastHit;
                    }
                    else
                    {
                        bDown = null;
                    }
                }



                if (aDown)
                {
                    //Debug.Log("A---->" + aDown);
                    onHoverADown.Invoke(aDown);
                }

                if (bDown)
                {
                    //Debug.Log("B---->" + bDown);
                    onHoverBDown.Invoke(bDown);
                }

                if (primaryDown && !secondaryDown)
                {
                    //Debug.Log(primaryDown);
                    //Debug.Log(axisValue);
                    if (!tractorBeaming)
                    {
                        tractorBeaming           = true;
                        tractorTime              = 0.0f;
                        tractorAxisInputFiltered = 0.0f;
                    }
                    else
                    {
                        tractorTime += Time.deltaTime;
                        if (tractorTime > tractorDelay)
                        {
                            float axisValue = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, activeController);
                            tractorAxisInputFiltered = Mathf.Lerp(tractorAxisInputFiltered, axisValue, tractorLerp);
                            onPrimarySelectDownAxis.Invoke(primaryDown, pointer, tractorAxisInputFiltered);
                        }
                    }
                }
                else if (secondaryDown && !primaryDown)
                {
                    //Debug.Log(secondaryDown);
                    //Debug.Log(axisValue);
                    if (!tractorBeaming)
                    {
                        tractorBeaming           = true;
                        tractorTime             += Time.deltaTime;
                        tractorAxisInputFiltered = 0.0f;
                    }
                    else
                    {
                        tractorTime++;
                        if (tractorTime > tractorDelay)
                        {
                            float axisValue = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, activeController);
                            tractorAxisInputFiltered = Mathf.Lerp(tractorAxisInputFiltered, axisValue, tractorLerp);
                            onSecondarySelectDownAxis.Invoke(secondaryDown, pointer, tractorAxisInputFiltered);
                        }
                    }
                }
                else
                {
                    tractorBeaming = false;
                }

#if UNITY_ANDROID && !UNITY_EDITOR
                // Gaze pointer fallback
                else
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        triggerDown = lastHit;
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        if (triggerDown != null && triggerDown == lastHit)
                        {
                            if (onPrimarySelect != null)
                            {
                                onPrimarySelect.Invoke(triggerDown);
                            }
                        }
                    }
                    if (!Input.GetMouseButton(0))
                    {
                        triggerDown = null;
                    }
                }
#endif

                //REMOTE GRAB
                if (!remoteGrab)
                {
                    // remoteGrab not set - looking for candidate
                    if (lastHit)
                    {
                        if (primaryDown && secondaryDown)
                        {
                            if (lastHit == primaryDown && lastHit == secondaryDown)
                            {
                                // START remote grabbing
                                //Debug.Log(lastHit + " is candidate for remoteGrab");
                                remoteGrab = lastHit;
                                // initially set remoteGrabTargetDistance to hit.distance
                                remoteGrabTargetDistance = hit.distance;
                                remoteGrabHitOffset      = remoteGrab.position - hit.point;
                                //Debug.Log("   --->" + hit.distance);
                                remoteGrabStartPos  = hit.point;
                                approxMovingAvgPoke = 0f;
                                remoteGrabTime      = 0.0f;

                                remoteGrabObjectStartQ     = remoteGrab.gameObject.transform.rotation;
                                remoteGrabControllerStartQ = OVRInput.GetLocalControllerRotation(activeController);

                                BackboneUnit bu = (remoteGrab.gameObject.GetComponent("BackboneUnit") as BackboneUnit);
                                if (bu != null)
                                {
                                    bu.SetRemoteGrabSelect(true);
                                    //bu.remoteGrabSelectOn = true;
                                    //bu.UpdateRenderMode();
                                }

                                //Rigidbody hitRigidBody = lastHit.gameObject.GetComponent<Rigidbody>();
                                //remoteGrabOffset = hitRigidBody.position - hit.point;
                            }
                        }
                    }
                }
                else
                {
                }
            }