Esempio n. 1
0
        public override void IntersectWith(GShape gShape)
        {
            IntersectionResult res;

            //if (gShape is GLine)
            //{
            //    res = Intersection.ArcLine(this, (GLine)gShape);
            //    if (res.IntersectionPoints.Count == 0) return;
            //    IntersectionResults.Add(res);
            //}

            if (gShape is GRectangle)
            {
                new IntersectionResult();
                foreach (var line in ((GRectangle)gShape).Lines)
                {
                    res = Intersection.ArcLine(this, line);
                    if (res.IntersectionPoints.Count == 0)
                    {
                        return;
                    }
                    IntersectionResults.Add(res);
                }
            }
        }
Esempio n. 2
0
        public bool ComputeIntersection(Vector3 source, Vector3 direction, ref IntersectionResults results)
        {
            var overlay = OpenVR.Overlay;

            if (overlay == null)
            {
                return(false);
            }

            var input = new VROverlayIntersectionParams_t();

            input.eOrigin       = SteamVR_Render.instance.trackingSpace;
            input.vSource.v0    = source.x;
            input.vSource.v1    = source.y;
            input.vSource.v2    = -source.z;
            input.vDirection.v0 = direction.x;
            input.vDirection.v1 = direction.y;
            input.vDirection.v2 = -direction.z;

            var output = new VROverlayIntersectionResults_t();

            if (!overlay.ComputeOverlayIntersection(handle, ref input, ref output))
            {
                return(false);
            }

            results.point    = new Vector3(output.vPoint.v0, output.vPoint.v1, -output.vPoint.v2);
            results.normal   = new Vector3(output.vNormal.v0, output.vNormal.v1, -output.vNormal.v2);
            results.UVs      = new Vector2(output.vUVs.v0, output.vUVs.v1);
            results.distance = output.fDistance;
            return(true);
        }
    public bool ComputeIntersection(Vector3 source, Vector3 direction, ref IntersectionResults results)
    {
        var overlay = OpenVR.Overlay;
        if (overlay == null)
            return false;

        var input = new VROverlayIntersectionParams_t();
        input.eOrigin = SteamVR_Render.instance.trackingSpace;
        input.vSource.v0 =  source.x;
        input.vSource.v1 =  source.y;
        input.vSource.v2 = -source.z;
        input.vDirection.v0 =  direction.x;
        input.vDirection.v1 =  direction.y;
        input.vDirection.v2 = -direction.z;

        var output = new VROverlayIntersectionResults_t();
        if (!overlay.ComputeOverlayIntersection(handle, ref input, ref output))
            return false;

        results.point = new Vector3(output.vPoint.v0, output.vPoint.v1, -output.vPoint.v2);
        results.normal = new Vector3(output.vNormal.v0, output.vNormal.v1, -output.vNormal.v2);
        results.UVs = new Vector2(output.vUVs.v0, output.vUVs.v1);
        results.distance = output.fDistance;
        return true;
    }
Esempio n. 4
0
    public OverlayHitResult getUVs(Vector3 source, Vector3 direction)
    {
        var result = new IntersectionResults();
        var hit    = ComputeIntersection(source, direction, ref result);

        return(new OverlayHitResult(hit, result));
    }
Esempio n. 5
0
        /// <summary>
        /// Determine Point On Region
        /// </summary>
        /// <param name="region">Region</param>
        /// <param name="pointOnRegion">Point to be checked</param>
        /// <param name="toleranceLevel">Tolerance Level</param>
        /// <returns>Intersection Results</returns>
        public static IntersectionResults IsPointOn(IRegion3D region, IPoint3D pointOnRegion, double toleranceLevel = MathConstants.ZeroWeak)
        {
            IntersectionResults regionResult = IsPointOn(region.Outline, pointOnRegion, toleranceLevel);

            if (regionResult != IntersectionResults.Inside)
            {
                return(regionResult);
            }

            foreach (IPolyLine3D opening in region.Openings)
            {
                IntersectionResults openingResult = IsPointOn(opening, pointOnRegion, toleranceLevel);
                if (openingResult == IntersectionResults.Inside)
                {
                    return(IntersectionResults.OnInSideOpening);
                }
                else if (openingResult == IntersectionResults.Outside)
                {
                    continue;
                }
                else
                {
                    return(openingResult);
                }
            }

            return(regionResult);
        }
Esempio n. 6
0
        public override void IntersectWith(GShape gShape)
        {
            if (gShape is GCircle)
            {
                var res = Intersection.CircleLine((GCircle)gShape, this);

                if (res.IntersectionPoints.Count > 0)
                {
                    IntersectionResults.Add(res);
                }
            }
            else if (gShape is GLine)
            {
                var res = Intersection.LineLine((GLine)gShape, this);

                if (res.IntersectionPoints.Count > 0)
                {
                    IntersectionResults.Add(res);
                }
            }

            else if (gShape is GRectangle)
            {
                foreach (var line in ((GRectangle)gShape).Lines)
                {
                    var res = Intersection.LineLine(line, this);

                    if (res.IntersectionPoints.Count > 0)
                    {
                        IntersectionResults.Add(res);
                    }
                }
            }
            else if (gShape is GPolyLine)
            {
                foreach (var line in ((GPolyLine)gShape).Lines)
                {
                    var res = Intersection.LineLine(line, this);

                    if (res.IntersectionPoints.Count > 0)
                    {
                        IntersectionResults.Add(res);
                    }
                }
            }
            else if (gShape is GCurve)
            {
                var res = Intersection.CurveLine((GCurve)gShape, this);
                if (res.IntersectionPoints.Count == 0)
                {
                    return;
                }
                IntersectionResults.Add(res);
            }
        }
Esempio n. 7
0
    /// <summary>
    /// Attempt to ComputerIntersection the HMD's Gaze and hit an Overlay
    /// </summary>
    /// <param name="changed"></param>
    private void UpdateGaze(ref bool changed)
    {
        FindHMD();
        var hit = false;

        if (_hmdTracker != null && _hmdTracker.IsValid)
        {
            var result = new IntersectionResults();
            hit = ComputeIntersection(_hmdTracker.gameObject.transform.localPosition, _hmdTracker.gameObject.transform.forward, ref result);
            //Debug.Log("Hit! " + gameObject.name);
        }
        HandleAnimateOnGaze(hit, ref changed);
    }
Esempio n. 8
0
    public bool ComputeIntersection(Vector3 source, Vector3 direction, ref IntersectionResults results)
    {
        var vr = SteamVR.instance;

        var input = new VROverlayIntersectionParams_t();
        input.eOrigin = SteamVR_Render.instance.trackingSpace;
        input.vSource.v = new float[] { source.x, source.y, -source.z };
        input.vDirection.v = new float[] { direction.x, direction.y, -direction.z };

        var output = new VROverlayIntersectionResults_t();
        if (!vr.overlay.ComputeOverlayIntersection(handle, ref input, ref output))
            return false;

        results.point = new Vector3(output.vPoint.v[0], output.vPoint.v[1], -output.vPoint.v[2]);
        results.normal = new Vector3(output.vNormal.v[0], output.vNormal.v[1], -output.vNormal.v[2]);
        results.UVs = new Vector2(output.vUVs.v[0], output.vUVs.v[1]);
        results.distance = output.fDistance;
        return true;
    }
Esempio n. 9
0
        public bool GetPlayerPointingAtPositionOnScreen(out Vector2 uv)
        {
            if (Controllers.GetLocalPosition().magnitude < 0.01f)
            {
                uv = Vector2.zero;
                return(false);
            }
            if (Current != null)
            {
                IntersectionResults result = new IntersectionResults();

                if (Current.ComputeIntersection(Controllers.GetLocalPosition(), Controllers.GetLocalAimForward(), ref result))
                {
                    uv = result.UVs;
                    return(true);
                }
            }
            uv = Vector2.zero;
            return(false);
        }
Esempio n. 10
0
        public override void IntersectWith(GShape gShape)
        {
            IntersectionResult res;

            if (gShape is GLine)
            {
                res = Intersection.CurveLine(this, (GLine)gShape);

                if (res.IntersectionPoints.Count == 0)
                {
                    return;
                }

                IntersectionResults.Add(res);
            }
            else if (gShape is GRectangle)
            {
                res = Intersection.CurveRectangle(this, (GRectangle)gShape);

                if (res.IntersectionPoints.Count == 0)
                {
                    return;
                }

                IntersectionResults.Add(res);
            }

            else if (gShape is GCurve)
            {
                res = Intersection.CurveCurve(this, (GCurve)gShape);

                if (res.IntersectionPoints.Count == 0)
                {
                    return;
                }
                IntersectionResults.Add(res);
            }
        }
Esempio n. 11
0
        public override void IntersectWith(GShape gShape)
        {
            IntersectionResult res;

            if (gShape is GLine)
            {
                res = Intersection.ParabolaLine(this, (GLine)gShape);

                if (res.IntersectionPoints.Count == 0)
                {
                    return;
                }

                IntersectionResults.Add(res);
            }
            else if (gShape is GParabola)
            {
                res = Intersection.ParabolaParabola(this, (GParabola)gShape);

                if (res.IntersectionPoints.Count == 0)
                {
                    return;
                }

                IntersectionResults.Add(res);
            }
            else if (gShape is GCircle)
            {
                res = Intersection.ParabolaCircle(this, (GCircle)gShape);

                if (res.IntersectionPoints.Count == 0)
                {
                    return;
                }

                IntersectionResults.Add(res);
            }
        }
Esempio n. 12
0
    public bool ComputeIntersection(Vector3 source, Vector3 direction, ref IntersectionResults results)
    {
        var vr = SteamVR.instance;

        var input = new VROverlayIntersectionParams_t();

        input.eOrigin      = SteamVR_Render.instance.trackingSpace;
        input.vSource.v    = new float[] { source.x, source.y, -source.z };
        input.vDirection.v = new float[] { direction.x, direction.y, -direction.z };

        var output = new VROverlayIntersectionResults_t();

        if (!vr.overlay.ComputeOverlayIntersection(handle, ref input, ref output))
        {
            return(false);
        }

        results.point    = new Vector3(output.vPoint.v[0], output.vPoint.v[1], -output.vPoint.v[2]);
        results.normal   = new Vector3(output.vNormal.v[0], output.vNormal.v[1], -output.vNormal.v[2]);
        results.UVs      = new Vector2(output.vUVs.v[0], output.vUVs.v[1]);
        results.distance = output.fDistance;
        return(true);
    }
Esempio n. 13
0
 public OverlayHitResult(bool hit, IntersectionResults result)
 {
     Hit    = hit;
     Result = result;
 }
        private bool TestComputeIntersection(ulong handle, Transform point)
        {
            IntersectionResults results = new IntersectionResults();

            return(SteamVR_Utils.ComputeIntersection(handle, point.position, point.forward, SteamVRManager.trackingSpace, ref results));
        }
Esempio n. 15
0
    public static bool ComputeIntersection(ulong handle, Vector3 source, Vector3 direction, ETrackingUniverseOrigin trackingUniverseOrigin, ref IntersectionResults results)
    {
        var input = new VROverlayIntersectionParams_t {
            eOrigin    = trackingUniverseOrigin,
            vSource    = { v0 = source.x, v1 = source.y, v2 = -source.z },
            vDirection = { v0 = direction.x, v1 = direction.y, v2 = -direction.z }
        };

        var output = new VROverlayIntersectionResults_t();

        if (!OpenVR.Overlay.ComputeOverlayIntersection(handle, ref input, ref output))
        {
            return(false);
        }

        results.point    = new Vector3(output.vPoint.v0, output.vPoint.v1, -output.vPoint.v2);
        results.normal   = new Vector3(output.vNormal.v0, output.vNormal.v1, -output.vNormal.v2);
        results.UVs      = new Vector2(output.vUVs.v0, output.vUVs.v1);
        results.distance = output.fDistance;
        return(true);
    }
        private bool CalculateIntersection(DPOverlayBase dpBase, out IntersectionResults results)
        {
            results = new IntersectionResults();

            return(SteamVR_Utils.ComputeIntersection(dpBase.overlay.handle, pointer.position, pointer.forward, SteamVRManager.trackingSpace, ref results));
        }
        public override bool HandleInteractionDetection(out List <Vector3> cursorPositions)
        {
            cursorPositions = new List <Vector3>();


            //DPOverlayBase closestOverlay;

            List <DPLaserCollisionData> collisions = new List <DPLaserCollisionData>();

            //bool foundOverlay = false;

            //Foreach of the overlays
            for (int i = 0; i < OverlayManager.I.overlays.Count; i++)
            {
                DPOverlayBase dpToTest = OverlayManager.I.overlays[i];

                //Don't process invisible or non-interactable overlays
                if (!dpToTest.overlay.shouldRender || !dpToTest.isInteractable)
                {
                    continue;
                }

                //Ignore look/distance hiding overlays:
                if (dpToTest.lookHidingActive || dpToTest.distanceHidingActive)
                {
                    continue;
                }

                if (!isActivated && !dpToTest.alwaysInteract && !dpToTest.allowMultipuleInteractors)
                {
                    continue;
                }

                //If the laser isn't activated, global interaction isn't activated, and the overlay doesn't want interaction when the bar is closed, just skip it.
                //If the overlay supports multi-interact, it's possible we might want to enable this laser, so we don't skip this quite yet.
                // ^^ if (!isActivated && !OverlayInteractionManager.interactionEnabled && !dpToTest.usePointInteraction && !dpToTest.allowMultipuleInteractors) continue;

                //If the overlay anchor is the same as the interactor, skip
                if (dpToTest.overlay.trackedDevice != DPOverlayTrackedDevice.None && dpToTest.overlay.trackedDevice == trackedDevice)
                {
                    continue;
                }

                //If the laser intersects with the overlay
                if (CalculateIntersection(dpToTest, out IntersectionResults hitResults))
                {
                    //Add it to the list of possible intersections
                    collisions.Add(new DPLaserCollisionData()
                    {
                        results = hitResults, dpBase = dpToTest
                    });
                }
            }


            //Actually handle interaction stuff once we find the closest collided overlay
            if (collisions.Count >= 1)
            {
                //Find the closest collision data out of all the collisions
                DPLaserCollisionData closest = collisions[0];

                for (int j = 1; j < collisions.Count; j++)
                {
                    if (collisions[j].results.distance < closest.results.distance)
                    {
                        closest = collisions[j];
                    }
                }

                //We've found the closest one, and can now interact.

                mostRecentIntersection = closest.results;

                //If interaction is not globally enabled, but the overlay has a flag for pointing interaction, we enable this laser.
                if (!isActivated && !OverlayInteractionManager.interactionEnabled)
                {
                    if (closest.dpBase.alwaysInteract)
                    {
                        //OverlayInteractionManager.I.TempEnableInteraction(inputSource);

                        //tempMultiInteractActive = true;

                        Activate(true);
                        if (closest.dpBase.alwaysInteractBlockInput)
                        {
                            OverlayInteractionManager.BlockInput(true);
                        }
                        //OverlayInteractionManager.I.
                    }

                    //Else, if interaction is not globally enabled, we return.
                    else
                    {
                        return(false);
                    }
                }


                //If we were using multi-touch on the old overlay, Disable the laser again:
                if (targetDP != closest.dpBase && targetDP != null && OverlayInteractionManager.interactionEnabled && OverlayInteractionManager.I.primaryLaser != this)
                {
                    multiInteractActive = false;
                    Disable();
                }


                //Activate the laser if it's not on and this overlay uses multi-interact:
                if (OverlayInteractionManager.interactionEnabled && !isActivated && closest.dpBase.allowMultipuleInteractors)
                {
                    multiInteractActive = true;
                    Activate(true);
                }


                else if (!isActivated)
                {
                    return(false);
                }


                //HIT A NEW OVERLAY
                //If we hit another overlay, disable interaction on the old overlay.
                if (targetDP != closest.dpBase && targetDP != null)
                {
                    targetDP.isBeingInteracted = false;
                    activatedTempEatClick      = true;

                    //If interaction isn't globally enabled, we need to turn off this laser when we leave this overlay.
                    if (!OverlayInteractionManager.interactionEnabled && !TheBarManager.isOpened)
                    {
                        Disable();
                        if (OverlayInteractionManager.inputBlocked)
                        {
                            OverlayInteractionManager.BlockInput(false);
                        }
                    }
                }


                targetDP = closest.dpBase;
                targetDP.isBeingInteracted = true;

                isInteracting = true;

                //Show the window bottom:
                if (OverlayInteractionManager.I.primaryLaser == this)
                {
                    DPToolbar.I.Target(targetDP);
                }


                targetDP.HandleColliderInteracted(this, new List <Vector2>()
                {
                    closest.results.UVs
                });


                cursorPositions.Add(closest.results.point);


                //return since we found an overlay for interaction
                return(true);
            }

            //Else, we found no overlays to interact with, so reset the state:


            //If we were temporarially interacting with a multi-touch overlay, disable this laser again.
            if (OverlayInteractionManager.interactionEnabled && OverlayInteractionManager.I.primaryLaser != this)
            {
                multiInteractActive = false;
                Disable();
            }


            if (targetDP != null)
            {
                targetDP.isBeingInteracted = false;

                //If interaction isn't globally enabled, we need to turn off this laser when we leave this overlay.
                if (!OverlayInteractionManager.interactionEnabled && !TheBarManager.isOpened)
                {
                    Disable();

                    if (OverlayInteractionManager.inputBlocked)
                    {
                        OverlayInteractionManager.BlockInput(false);
                    }
                }
            }

            targetDP      = null;
            isInteracting = false;
            return(false);
        }
Esempio n. 18
0
        /// <summary>
        /// Calculate inner partial polyline by intersecting region and polyline
        /// </summary>
        /// <param name="region">IRegion3D</param>
        /// <param name="innerPolyline">Polyline3D used to calculate inner partial polyline</param>
        /// <param name="innerPolylineList">List of inner partial polyline prepared from the given polygon and polyline</param>
        /// <returns>IntersectionResults</returns>
        public static IntersectionResults Intersect(IRegion3D region, IPolyLine3D innerPolyline, ICollection <IPolyLine3D> innerPolylineList)
        {
            if (region == null || innerPolyline == null || innerPolylineList == null)
            {
                return(IntersectionResults.Undefined);
            }

            IPolyLine3D     outerPolyline           = region.Outline;
            List <IPoint3D> listOfIntersectionPoint = new List <IPoint3D>();

            Intersect(outerPolyline, innerPolyline, listOfIntersectionPoint);
            foreach (IPolyLine3D opening in region.Openings)
            {
                Intersect(opening, innerPolyline, listOfIntersectionPoint);
            }

            if (listOfIntersectionPoint.Count < 1)
            {
                IPoint3D point = GetPointOnPolyLine(innerPolyline, 0.5);
                return(IsPointOn(region, point));
            }

            SortedSet <double> relativePositionSet = new SortedSet <double>();

            relativePositionSet.Add(0);
            relativePositionSet.Add(1);
            foreach (IPoint3D point in listOfIntersectionPoint)
            {
                double relativePosition = 0;
                if (GetRelativePosition(innerPolyline, point, ref relativePosition))
                {
                    if (!relativePositionSet.Contains(relativePosition))
                    {
                        relativePositionSet.Add(relativePosition);
                    }
                }
            }

            IList <ISegment3D> splittedSegments = SplitPolyline(innerPolyline, relativePositionSet);

            if (splittedSegments == null)
            {
                return(IntersectionResults.Undefined);
            }

            IntersectionResults interSectionResult = IntersectionResults.Undefined;

            foreach (ISegment3D segment in splittedSegments)
            {
                IPoint3D point = new Point3D();
                if (GetPointOnSegment(segment, 0.5, ref point))
                {
                    IntersectionResults result = IsPointOn(region, point);
                    interSectionResult |= result;
                    if (result == IntersectionResults.Inside || result == IntersectionResults.OnBorderCurve)
                    {
                        IPolyLine3D polyline = new PolyLine3D();
                        if (innerPolylineList.Count < 1)
                        {
                            polyline.Add(segment);
                        }
                        else
                        {
                            IPolyLine3D existingPolyline = innerPolylineList.Last();
                            if (existingPolyline.Count < 1)
                            {
                                polyline.Add(segment);
                            }
                            else
                            {
                                if (existingPolyline.Count > 1)
                                {
                                    ISegment3D lastSegment = existingPolyline.Segments.Last();
                                    if (lastSegment.EndPoint.Equals(segment.StartPoint))
                                    {
                                        polyline = existingPolyline;
                                    }
                                }

                                polyline.Add(segment);
                            }
                        }

                        if (!innerPolylineList.Contains(polyline))
                        {
                            innerPolylineList.Add(polyline);
                        }
                    }
                }
            }

            if (innerPolylineList.Count < 1)
            {
                return(IntersectionResults.OnBorderNode | IntersectionResults.Outside);
            }

            return(interSectionResult);
        }
Esempio n. 19
0
        public override void IntersectWith(GShape gShape)
        {
            IntersectionResult result;

            if (gShape is GLine)
            {
                foreach (var line in Lines)
                {
                    result = Intersection.LineLine((GLine)gShape, line);

                    if (result.IntersectionPoints.Count > 0)
                    {
                        IntersectionResults.Add(result);
                    }
                }
            }
            else if (gShape is GCircle)
            {
                foreach (var line in Lines)
                {
                    result = Intersection.CircleRectangle((GCircle)gShape, this);

                    if (result.IntersectionPoints.Count == 0)
                    {
                        return;
                    }

                    IntersectionResults.Add(result);
                }
            }
            else if (gShape is GRectangle)
            {
                foreach (var line in Lines)
                {
                    foreach (var recLine in ((GRectangle)gShape).Lines)
                    {
                        result = Intersection.LineLine(line, recLine);

                        if (result.IntersectionPoints.Count == 0)
                        {
                            continue;
                        }

                        IntersectionResults.Add(result);
                    }
                }
            }

            else if (gShape is GPolyLine)
            {
                foreach (var line in Lines)
                {
                    foreach (var pLine in ((GPolyLine)gShape).Lines)
                    {
                        result = Intersection.LineLine(line, pLine);

                        if (result.IntersectionPoints.Count == 0)
                        {
                            continue;
                        }

                        IntersectionResults.Add(result);
                    }
                }
            }

            else if (gShape is GCurve)
            {
                result = Intersection.CurveRectangle((GCurve)gShape, this);

                if (result.IntersectionPoints.Count == 0)
                {
                    return;
                }

                IntersectionResults.Add(result);
            }
        }
Esempio n. 20
0
 public bool PollNextEvent(ref VREvent_t pEvent) => default;                                                     // 0x0000000180CC7510-0x0000000180CC7610
 public bool ComputeIntersection(Vector3 source, Vector3 direction, ref IntersectionResults results) => default; // 0x0000000180CC7090-0x0000000180CC72D0