Esempio n. 1
0
 /// <summary>
 /// Convenience function for cloning PointerEventData
 /// </summary>
 /// <param name="from">Copy this value</param>
 /// <param name="to">to this object</param>
 protected void CopyFromTo(OSVRRayPointerEventData @from, OSVRRayPointerEventData @to)
 {
     @to.position              = @from.position;
     @to.delta                 = @from.delta;
     @to.scrollDelta           = @from.scrollDelta;
     @to.pointerCurrentRaycast = @from.pointerCurrentRaycast;
     @to.pointerEnter          = @from.pointerEnter;
     @to.worldSpaceRay         = @from.worldSpaceRay;
 }
Esempio n. 2
0
        /// <summary>
        /// The purpose of this function is to allow us to switch between using the standard IsPointerMoving
        /// method for mouse driven pointers, but to always return true when it's a ray based pointer.
        /// All real-world ray-based input devices are always moving so for simplicity we just return true
        /// for them.
        ///
        /// If PointerEventData.IsPointerMoving was virtual we could just override that in
        /// OSVRRayPointerEventData.
        /// </summary>
        /// <param name="pointerEvent"></param>
        /// <returns></returns>
        static bool IsPointerMoving(PointerEventData pointerEvent)
        {
            OSVRRayPointerEventData rayPointerEventData = pointerEvent as OSVRRayPointerEventData;

            if (rayPointerEventData != null)
            {
                return(true);
            }
            else
            {
                return(pointerEvent.IsPointerMoving());
            }
        }
Esempio n. 3
0
        protected bool GetPointerData(int id, out OSVRRayPointerEventData data, bool create)
        {
            if (!m_VRRayPointerData.TryGetValue(id, out data) && create)
            {
                data = new OSVRRayPointerEventData(eventSystem)
                {
                    pointerId = id,
                };

                m_VRRayPointerData.Add(id, data);
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// Perform a raycast using the worldSpaceRay in eventData.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="resultAppendList"></param>
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            // This function is closely based on PhysicsRaycaster.Raycast

            if (eventCamera == null)
            {
                return;
            }

            OSVRRayPointerEventData rayPointerEventData = eventData as OSVRRayPointerEventData;

            if (rayPointerEventData == null)
            {
                return;
            }

            var ray = rayPointerEventData.worldSpaceRay;

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics.RaycastAll(ray, dist, finalEventMask);

            if (hits.Length > 1)
            {
                System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
            }

            if (hits.Length != 0)
            {
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    var result = new RaycastResult
                    {
                        gameObject    = hits[b].collider.gameObject,
                        module        = this,
                        distance      = hits[b].distance,
                        index         = resultAppendList.Count,
                        worldPosition = hits[0].point,
                        worldNormal   = hits[0].normal,
                    };
                    resultAppendList.Add(result);
                }
            }
        }