Example #1
0
        // raycast are not that important so the update function is sufficient
        public void Update()
        {
            if (SelectionModelInstance != null && IsActivated)
            {
                Collider[] hitColliders = Physics.OverlapSphere(SelectionModelInstance.transform.position, MaxSphereDiagnoal / 2);

                if (hitColliders.Length > 0)
                {
                    foreach (var collider in hitColliders)
                    {
                        VRIL_Interactable tempObj = collider.transform.gameObject.GetComponent <VRIL_Interactable>();

                        if (tempObj != null &&
                            tempObj.Selection_Selectable &&
                            tempObj != SelectionModelInstance &&
                            tempObj != MainHand &&
                            tempObj != SecondaryHand &&
                            !SelectableObjects.Contains(tempObj))
                        {
                            SelectableObjects.Add(tempObj);
                        }
                    }
                }
                else
                {
                    SelectableObjects.Clear();
                }
            }
        }
Example #2
0
    private void PerformRaycast()
    {
        Ray ray = new Ray(RaycastObject.position, RaycastObject.right);

        if (Physics.Raycast(ray, out hit))
        {
            hitTransform  = hit.transform;
            focusedObject = hitTransform.GetComponent <SelectableObjects>();
            // hitPoint = hit.point;
        }
        else
        {
            focusedObject = null;
            hitTransform  = null;
        }
    }
Example #3
0
    private void PerformRaycast()
    {
        Debug.DrawRay(objForRaycast.position, objForRaycast.right * raycastLength, Color.red);
        Ray ray = new Ray(objForRaycast.position, objForRaycast.right);

        if (Physics.Raycast(ray, out hit, raycastLength))
        {
            hitTransform  = hit.transform;
            focusedObject = hitTransform.GetComponent <SelectableObjects>();
            // hitPoint = hit.point;
        }
        else
        {
            focusedObject = null;
            hitTransform  = null;
        }
    }
Example #4
0
        /// <summary>
        /// Constructs and initializes editor.
        /// </summary>
        /// <param name="document">Reference to document object.</param>
        protected BaseEditor(IDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            this.documentRef            = document;
            Document.DataLoaded        += new EventHandler(OnDocumentDataLoaded);
            Document.DataChanged       += new EventHandler(OnDocumentDataChanged);
            Document.Saving            += new CancelEventHandler(OnDocumentSaving);
            Document.SuccessfullySaved += new EventHandler(OnDocumentSuccessfullySaved);
            Document.SaveAttemptFailed += new EventHandler(OnDocumentSaveAttemptFailed);

            // Initialize selection container
            selectionContainerRef.SelectableObjects = SelectableObjects;
            selectionContainerRef.SelectedObjects   = SelectedObjects;

            // Add document to selection
            SelectableObjects.Add(Document);
        }
Example #5
0
        /// <summary>
        /// Coroutine for single ray cast technique
        /// </summary>
        /// <returns>WaitForSeconds()</returns>
        private IEnumerator ShowRay()
        {
            SingleRayCastLineRenderer.enabled = true;

            while (IsActivated)
            {
                Ray        ray = new Ray(RegisteredControllers[0].transform.position, RegisteredControllers[0].transform.forward);
                RaycastHit raycastHit;

                SingleRayCastLineRenderer.SetPosition(0, ray.origin);

                // check for obstacle at max distance
                if (Physics.Raycast(ray, out raycastHit, MaxRayDistance))
                {
                    VRIL_Interactable interactable = raycastHit.transform.gameObject.GetComponent <VRIL_Interactable>();
                    if (interactable != null && interactable.Selection_Selectable)
                    {
                        if (!SelectableObjects.Contains(interactable))
                        {
                            SelectableObjects.Add(interactable);
                        }
                    }
                    else
                    {
                        SelectableObjects.Clear();
                    }

                    SingleRayCastLineRenderer.SetPosition(1, raycastHit.point);
                }
                else
                {
                    SelectableObjects.Clear();
                    SingleRayCastLineRenderer.SetPosition(1, ray.GetPoint(MaxRayDistance));
                }

                yield return(null);
            }

            SingleRayCastLineRenderer.enabled = false;
        }
Example #6
0
    // Update is called once per frame


    void Update()
    {
        CheckKeyInput();
        PerformRaycast();


        bool grabPressed = OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger, OVRInput.Controller.Touch) > 0f;

        if ((!grabbing) && grabPressed) //if haven't grabbed, now grab
        {
            if (focusedObject)
            {
                grabbing = true;
                focusedObject.SetMaterialColor("_Color", focusedObject.selectionColor);
                initialObjPosition = focusedObject.transform.position;
                grabbedObject      = focusedObject;
            }
        }
        else if (grabbing && !grabPressed) //let go of the object
        {
            grabbing = false;
            if (grabbedObject.selected)
            {
                grabbedObject.SetMaterialColor("_Color", grabbedObject.m_renderers[0].materials[0].GetColor("_Color"));
            }
            else
            {
                grabbedObject.SetMaterialColor("_Color", grabbedObject.defaultColor);
                grabbedObject = null;
            }
        }
        if (grabbing)
        {
            if (OVRInput.GetDown(startManipulateKey))
            {
                if (!startManipulating)
                {
                    initialObjPosition = grabbedObject.transform.position;
                    xdiff = 0;
                    zdiff = 0;
                }

                startManipulating = !startManipulating;
            }

            if (!startManipulating)
            {
                return;
            }
            controllerPositionCurrentFrame = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
            xdiff += (controllerPositionCurrentFrame.x - controllerPositionLastFrame.x);
            zdiff += (controllerPositionCurrentFrame.z - controllerPositionLastFrame.z);
            if (grabbedObject.alignWithWall)
            {
                zdiff = 0;
            }

            grabbedObject.transform.position = initialObjPosition + new Vector3(-zdiff, 0, xdiff) * objMovementSpeed;



            controllerPositionLastFrame = controllerPositionCurrentFrame;
            Vector3    c      = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch).eulerAngles;
            Vector3    objR   = grabbedObject.transform.rotation.eulerAngles;
            Vector3    nEuler = new Vector3(objR.x, c.y, objR.z);
            Quaternion q      = Quaternion.Euler(nEuler);
            grabbedObject.transform.rotation = q;
        }
    }
Example #7
0
        /// <summary>
        /// Spindle and Wheel Selection Coroutine
        /// <para>Only used for the selection of models between controller</para>
        /// </summary>
        /// <returns></returns>
        private IEnumerator SpindleAndWheelSelection()
        {
            Vector3 pos = RegisteredControllers[0].transform.position - (RegisteredControllers[0].transform.position - RegisteredControllers[1].transform.position) / 2;

            Collider[] hitColliders;

            // set up selection model
            if (SelectionModelInstance == null)
            {
                SelectionModelInstance      = Instantiate(SelectionModel, pos, Quaternion.identity);
                SelectionModelInstance.name = "VRIL_SelectionModel_SpindleAndWheel";

                float connectionRayDistance = (RegisteredControllers[0].transform.position - RegisteredControllers[1].transform.position).sqrMagnitude;
                CurrentSphereDiagonal = connectionRayDistance - connectionRayDistance / DistanceDivider;

                SelectionModelInstance.transform.localScale = new Vector3(CurrentSphereDiagonal, CurrentSphereDiagonal, CurrentSphereDiagonal);
            }

            while (selectionModeActivated)
            {
                // set line position
                LineRenderer.SetPosition(0, RegisteredControllers[0].transform.position);
                LineRenderer.SetPosition(1, RegisteredControllers[1].transform.position);

                // set model position
                pos = RegisteredControllers[0].transform.position - (RegisteredControllers[0].transform.position - RegisteredControllers[1].transform.position) / 2;
                SelectionModelInstance.transform.position = pos;

                float connectionRayDistance = (RegisteredControllers[0].transform.position - RegisteredControllers[1].transform.position).sqrMagnitude;

                // resize based on connectionraydistance
                if (connectionRayDistance < MaxSphereDiagnoal && connectionRayDistance > MinSphereDiagonal)
                {
                    CurrentSphereDiagonal = connectionRayDistance - connectionRayDistance / DistanceDivider;
                    SelectionModelInstance.transform.localScale = new Vector3(CurrentSphereDiagonal, CurrentSphereDiagonal, CurrentSphereDiagonal);
                }

                // colliders
                hitColliders = Physics.OverlapSphere(SelectionModelInstance.transform.position, CurrentSphereDiagonal / 2);

                if (hitColliders.Length > 0)
                {
                    foreach (var collider in hitColliders)
                    {
                        VRIL_Interactable tempObj = collider.transform.gameObject.GetComponent <VRIL_Interactable>();

                        if (tempObj != null &&
                            tempObj.Selection_Selectable &&
                            tempObj != SelectionModelInstance &&
                            !SelectableObjects.Contains(tempObj))
                        {
                            SelectableObjects.Add(tempObj);
                        }
                    }
                }
                else
                {
                    SelectableObjects.Clear();
                }

                yield return(new WaitForSeconds(CoroutineWaitTime));
            }

            SelectionModelInstance?.SetActive(false);

            yield return(null);
        }
Example #8
0
        /// <summary>
        /// Coroutine for Depthray
        /// <para>Controller is used with a selection model to select objects</para>
        /// </summary>
        /// <returns></returns>
        private IEnumerator ShowRay()
        {
            SingleRayCastLineRenderer.enabled = true;
            Ray ray = new Ray(RegisteredControllers[0].transform.position, RegisteredControllers[0].transform.forward);

            Collider[] hitColliders;

            if (SelectionModelInstance == null)
            {
                SelectionModelInstance      = Instantiate(SelectionModel, ray.GetPoint(0), Quaternion.identity);
                SelectionModelInstance.name = "VRIL_SelectionModel_DepthRay";
                SelectionModelInstance.transform.localScale = new Vector3(SphereDiagnoal, SphereDiagnoal, SphereDiagnoal);
                CurrentSphereDiagonal = SphereDiagnoal;
            }
            else
            {
                SelectionModelInstance.SetActive(true);
            }

            while (IsActivated)
            {
                ray = new Ray(RegisteredControllers[0].transform.position, RegisteredControllers[0].transform.forward);
                SingleRayCastLineRenderer.SetPosition(0, ray.origin);
                SingleRayCastLineRenderer.SetPosition(1, ray.GetPoint(MaxRayDistance));

                float distance   = (RegisteredControllers[0].transform.position - RegisteredControllers[1].transform.position).sqrMagnitude;
                float pointValue = distance * DistanceMapping;

                if (pointValue >= MaxRayDistance)
                {
                    pointValue = MaxRayDistance;
                }

                SelectionModelInstance.transform.position = ray.GetPoint(pointValue);

                hitColliders = Physics.OverlapSphere(SelectionModelInstance.transform.position, CurrentSphereDiagonal / 2);

                if (hitColliders.Length > 0)
                {
                    foreach (var collider in hitColliders)
                    {
                        VRIL_Interactable tempObj = collider.transform.gameObject.GetComponent <VRIL_Interactable>();

                        if (tempObj != null &&
                            tempObj.Selection_Selectable &&
                            tempObj != SelectionModelInstance &&
                            !SelectableObjects.Contains(tempObj))
                        {
                            SelectableObjects.Add(tempObj);
                        }
                    }
                }
                else
                {
                    SelectableObjects.Clear();
                }

                yield return(new WaitForSeconds(CoroutineWaitTime));
            }

            SelectionModelInstance.SetActive(false);
            SingleRayCastLineRenderer.enabled = false;
        }