Exemplo n.º 1
0
        // does not test bounds!
        // [TODO] this is going to be weird... need to test bounds, I think
        public bool FindAnyRayIntersection(Ray3f ray, out AnyRayHit hit)
        {
            hit = null;

            UIRayHit bestUIHit = null;
            SORayHit bestSOHit = null;

            foreach (var ui in vUIElements)
            {
                UIRayHit uiHit;
                if (ui.FindRayIntersection(ray, out uiHit))
                {
                    if (bestUIHit == null || uiHit.fHitDist < bestUIHit.fHitDist)
                    {
                        bestUIHit = uiHit;
                    }
                }
            }
            foreach (var so in VisibleSceneObjects)
            {
                if (!is_selectable(so))
                {
                    continue;
                }
                SORayHit objHit;
                if (so.FindRayIntersection(ray, out objHit))
                {
                    if (bestSOHit == null || objHit.fHitDist < bestSOHit.fHitDist)
                    {
                        bestSOHit = objHit;
                    }
                }
            }
            if (bestUIHit != null)
            {
                if (bestSOHit == null || bestSOHit.fHitDist > bestUIHit.fHitDist)
                {
                    hit = new AnyRayHit(bestUIHit);
                }
                else
                {
                    hit = new AnyRayHit(bestSOHit);
                }
            }
            else if (bestSOHit != null)
            {
                hit = new AnyRayHit(bestSOHit);
            }

            return(hit != null);
        }
Exemplo n.º 2
0
        bool update_last_hit(MeshEditorTool tool, Ray3f rayS)
        {
            int hit_id = -1; Frame3f hitFrameS = Frame3f.Identity;

            MeshEditorOpType.ElementType hitType = MeshEditorOpType.ElementType.Triangle;
            if (tool.FindHitElement(rayS, ref hitFrameS, ref hit_id, ref hitType))
            {
                lastHitFrameS      = hitFrameS;
                lastHitElementID   = hit_id;
                lastHitElementType = hitType;
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        // see comment above
        public bool Find2DCockpitUIHoverHit(Ray3f orthoEyeRay, out UIRayHit bestHit)
        {
            if (Use2DCockpit == false)
            {
                throw new Exception("FContext.Find2DUIHit: 2D UI layer is not enabled!");
            }

            bestHit = null;
            if (options.EnableCockpit)
            {
                return(activeCockpit.FindUIHoverRayIntersection(orthoEyeRay, out bestHit));
            }
            return(false);
        }
Exemplo n.º 4
0
        public static Frame3f GetCylinderFrameFromAngleHeight(float fHUDRadius, float fHorzAngleDeg, float fVertHeight)
        {
            Ray3f r = VRUtil.MakeRayFromSphereCenter(fHorzAngleDeg, 0);

            r.Direction = fHUDRadius * r.Direction + fVertHeight * Vector3f.AxisY;
            r.Direction.Normalize();
            float fRayT = 0.0f;

            RayIntersection.InfiniteCylinder(r.Origin, r.Direction, Vector3f.Zero, Vector3f.AxisY, fHUDRadius, out fRayT);
            Vector3f v = r.Origin + fRayT * r.Direction;
            Vector3f n = new Vector3f(v[0], 0, v[2]).Normalized;

            return(new Frame3f(v, n));
        }
Exemplo n.º 5
0
 public override CaptureRequest WantsCapture(InputState input)
 {
     if (input.bLeftTriggerPressed ^ input.bRightTriggerPressed)
     {
         CaptureSide eSide  = (input.bLeftTriggerPressed) ? CaptureSide.Left : CaptureSide.Right;
         Ray3f       useRay = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
         SORayHit    rayHit;
         if (scene.Scene.FindSORayIntersection(useRay, out rayHit))
         {
             return(CaptureRequest.Begin(this, eSide));
         }
     }
     return(CaptureRequest.Ignore);
 }
        override protected void OnBeginCapture(Ray3f worldRay, Standard3DWidget w)
        {
            List <SceneObject> PotentialTargets = new List <SceneObject>(ConstraintSurfaces);

            foreach (var v in Widgets)
            {
                if (v.Value is SurfaceConstrainedPointWidget)
                {
                    SurfaceConstrainedPointWidget widget = v.Value as SurfaceConstrainedPointWidget;
                    widget.SourceSO           = Targets[0];
                    widget.ConstraintSurfaces = PotentialTargets;
                }
            }
        }
Exemplo n.º 7
0
        public override bool UpdateCapture(ITransformable target, Ray3f worldRay)
        {
            Ray3f    sceneRay = Scene.ToSceneRay(worldRay);
            Vector3f newPos   = (Vector3f)ScenePositionF(sceneRay);

            Frame3f f = SourceSO.GetLocalFrame(CoordSpace.SceneCoords);

            if (f.Origin.EpsilonEqual(newPos, MathUtil.Epsilonf) == false)
            {
                f.Origin = newPos;
                SourceSO.SetLocalFrame(f, CoordSpace.SceneCoords);
            }

            return(true);
        }
Exemplo n.º 8
0
        public bool FindRayIntersection(Ray3f ray, out UIRayHit hit)
        {
            hit = null;
            GameObjectRayHit hitg = null;

            if (is_interactive && FindGORayIntersection(ray, out hitg))
            {
                if (hitg.hitGO != null)
                {
                    hit = new UIRayHit(hitg, this);
                    return(true);
                }
            }
            return(false);
        }
        public override Capture BeginCapture(InputState input, CaptureSide eSide)
        {
            Ray3f    useRay = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
            UIRayHit uiHit;

            if (scene.FindUIHit(useRay, out uiHit))
            {
                bool bCanCapture = uiHit.hitUI.BeginCapture(InputEvent.Spatial(eSide, input, new AnyRayHit(uiHit)));
                if (bCanCapture)
                {
                    return(Capture.Begin(this, eSide, uiHit.hitUI));
                }
            }
            return(Capture.Ignore);
        }
Exemplo n.º 10
0
        virtual public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            GameObjectRayHit hitg = null;

            if (FindGORayIntersection(ray, out hitg))
            {
                if (hitg.hitGO != null)
                {
                    hit = new SORayHit(hitg, this);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 11
0
        bool check_object_ray_hit(InputState input, CaptureSide eSide)
        {
            Ray3f    useRay = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
            SORayHit rayHit;

            if (context.Scene.FindSORayIntersection(useRay, out rayHit, ObjectFilterF))
            {
                var tso = rayHit.hitSO;
                if (tso != null)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 12
0
            public void UpdateSetWorldScale(Ray3f left, Ray3f right)
            {
                Vector3f hit1  = hitFrame.RayPlaneIntersection(left.Origin, left.Direction, 2);
                Vector3f hit2  = hitFrame.RayPlaneIntersection(right.Origin, right.Direction, 2);
                Vector3f avg   = (hit1 + hit2) * 0.5f;
                float    r0    = (hit1 - (Vector3f)go.transform.position).Length;
                float    r1    = (hit2 - (Vector3f)go.transform.position).Length;
                float    r     = (r0 + r1) * 0.5f;
                float    min_r = VRUtil.GetVRRadiusForVisualAngle(avg, camState.camPosition, 2.0f);

                r = (float)Math.Max(r, min_r);
                go.transform.localScale = r * Vector3f.One;
                go.GetComponent <Renderer>().material =
                    (r > deadzone_r) ? mYes : mNo;
            }
Exemplo n.º 13
0
        override public Capture BeginCapture(InputState input, CaptureSide eSide)
        {
            Ray3f    worldRay = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
            SORayHit rayHit;
            bool     bHit = context.Scene.FindSORayIntersection(worldRay, out rayHit, ObjectFilterF);

            if (bHit)
            {
                targetSO = rayHit.hitSO;
                BaseSurfacePointTool tool = context.ToolManager.GetActiveTool((int)eSide) as BaseSurfacePointTool;
                tool.Begin(targetSO, Vector2d.Zero, worldRay);

                return(Capture.Begin(this, eSide));
            }
            return(Capture.Ignore);
        }
Exemplo n.º 14
0
        override public Capture UpdateCapture(InputState input, CaptureData data)
        {
            bool bReleased = (data.which == CaptureSide.Left) ? input.bLeftTriggerReleased : input.bRightTriggerReleased;

            if (bReleased)
            {
                tool.End();
                return(Capture.End);
            }
            else
            {
                Ray3f worldRay = (data.which == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
                tool.Update(worldRay);
                return(Capture.Continue);
            }
        }
        public override Capture BeginCapture(InputState input, CaptureSide eSide)
        {
            Ray3f    useRay = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
            SORayHit rayHit;

            if (cockpit.Scene.FindSORayIntersection(useRay, out rayHit))
            {
                var tso = rayHit.hitSO as TransformableSO;
                if (tso != null)
                {
                    Frame3f handF = (eSide == CaptureSide.Left) ? input.LeftHandFrame : input.RightHandFrame;
                    return(Capture.Begin(this, eSide, new GrabInfo(cockpit, tso, handF)));
                }
            }
            return(Capture.Ignore);
        }
Exemplo n.º 16
0
        override public Capture BeginCapture(InputState input, CaptureSide eSide)
        {
            Ray3f worldRay            = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
            DrawSurfaceCurveTool tool = context.ToolManager.GetActiveTool((int)eSide) as DrawSurfaceCurveTool;

            if (tool.InputMode == DrawSurfaceCurveTool.DrawMode.Continuous)
            {
                tool.BeginDraw_Ray_Continuous(worldRay);
            }
            else
            {
                tool.BeginDraw_Ray_MultiClick();
            }

            return(Capture.Begin(this, eSide));
        }
Exemplo n.º 17
0
 public bool FindWorldBoundsHit(Ray3f ray, out GameObjectRayHit hit)
 {
     hit = null;
     foreach (var go in this.vBoundsObjects)
     {
         GameObjectRayHit myHit = null;
         if (UnityUtil.FindGORayIntersection(ray, go, out myHit))
         {
             if (hit == null || myHit.fHitDist < hit.fHitDist)
             {
                 hit = myHit;
             }
         }
     }
     return(hit != null);
 }
Exemplo n.º 18
0
        public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            if (EnableSelection == false)
            {
                return(false);
            }

            bool bHit = SceneUtil.FindNearestRayIntersection(vChildren, ray, out hit);

            if (bHit)
            {
                hit.hitSO = this;
            }
            return(bHit);
        }
Exemplo n.º 19
0
        public bool FindRayIntersection(Ray3f ray, out SORayHit hit)
        {
            hit = null;
            if (SelectionMode == SelectionModes.NoSelection)
            {
                return(false);
            }

            bool bHit = SceneUtil.FindNearestRayIntersection(vChildren, ray, out hit);

            if (bHit && SelectionMode == SelectionModes.SelectGroup)
            {
                hit.hitSO = this;
            }
            return(bHit);
        }
Exemplo n.º 20
0
        public virtual void UpdateDrawPreview_Ray_MultiClick(Ray3f ray)
        {
            if (preview == null || preview.VertexCount == 0)
            {
                return;
            }
            SORayHit hit;
            bool     bHit = target.FindRayIntersection(ray, out hit);

            if (bHit)
            {
                float    offset = Scene.ToWorldDimension(SurfaceOffsetScene);
                Vector3f vHit   = hit.hitPos + offset * hit.hitNormal;
                Vector3f vPos   = Scene.ToSceneP(vHit);
                preview[preview.VertexCount - 1] = vPos;
            }
        }
Exemplo n.º 21
0
        public bool FindRayIntersection(Ray3f ray, out float fHitDist)
        {
            fHitDist = float.PositiveInfinity;
            float fHitThreshSqr = 2.0f * fLineWidthW;

            fHitThreshSqr *= fHitThreshSqr;

            DistRay3Segment3 dist      = new DistRay3Segment3(ray, segmentW);
            float            fDistWSqr = (float)dist.GetSquared();

            if (fDistWSqr < fHitThreshSqr)
            {
                fHitDist = (float)dist.RayParameter;
                return(true);
            }
            return(false);
        }
Exemplo n.º 22
0
        public override CaptureRequest WantsCapture(InputState input)
        {
            // don't show if anyone else is capturing (how did we even get here??)
            // [TODO] should improve this in the future. There are places where we would want to
            //   show, but we would have to restrict menu items (eg moving camera while in
            //   active xform breaks things).
            if (input.LeftCaptureActive || input.RightCaptureActive)
            {
                return(CaptureRequest.Ignore);
            }

            // currently only supporting a single popup at a time!
            if (popup != null)
            {
                return(CaptureRequest.Ignore);
            }

            bool        bActivate = false;
            CaptureSide eSide     = CaptureSide.Any;
            Ray3f       useRay    = new Ray3f(Vector3f.Zero, Vector3f.AxisY);

            if (input.IsForDevice(InputDevice.Mouse) || input.IsForDevice(InputDevice.Gamepad))
            {
                bActivate = input.bRightMousePressed || input.bRightTriggerPressed;
                useRay    = (input.bRightMousePressed) ? input.vMouseWorldRay : input.vGamepadWorldRay;
            }
            else if (input.IsForDevice(InputDevice.AnySpatialDevice))
            {
                bActivate = input.bXButtonPressed || input.bAButtonPressed;
                useRay    = (input.bXButtonPressed) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
                eSide     = (input.bXButtonPressed) ? CaptureSide.Left : CaptureSide.Right;
            }
            if (!bActivate)
            {
                return(CaptureRequest.Ignore);
            }

            AnyRayHit rayHit;

            if (cockpit.Scene.FindSceneRayIntersection(useRay, out rayHit) == false)
            {
                return(CaptureRequest.Ignore);
            }

            return(CaptureRequest.Begin(this, eSide));
        }
Exemplo n.º 23
0
 override public CaptureRequest WantsCapture(InputState input)
 {
     if (input.bLeftTriggerPressed ^ input.bRightTriggerPressed)
     {
         CaptureSide eSide = (input.bLeftTriggerPressed) ? CaptureSide.Left : CaptureSide.Right;
         if (context.ToolManager.GetActiveTool((int)eSide) == tool)
         {
             Ray3f worldRay  = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
             int   hit_pt_id = tool.FindNearestHitPoint(worldRay);
             if (hit_pt_id >= 0)
             {
                 return(CaptureRequest.Begin(this, eSide));
             }
         }
     }
     return(CaptureRequest.Ignore);
 }
Exemplo n.º 24
0
        public void EndStroke()
        {
            if (CurrentStroke.Count >= 2)
            {
                DMesh3 mesh = Target.Mesh;

                TransformSequence toScene = SceneTransforms.ObjectToSceneXForm(Target);

                List <int> tris1 = new List <int>(), tris2 = new List <int>();
                Ray3f      first = CurrentStroke[0], last = CurrentStroke[CurrentStroke.Count - 1];

                Vector3f v0 = PlaneFrameS.RayPlaneIntersection(first.Origin, first.Direction, 2);
                Vector3f v1 = PlaneFrameS.RayPlaneIntersection(last.Origin, last.Direction, 2);

                Vector3f planeN = Vector3f.Cross(first.Direction, last.Direction);
                Frame3f  planeF = new Frame3f((v0 + v1) / 2, planeN);

                foreach (int tid in mesh.TriangleIndices())
                {
                    Vector3f c = (Vector3f)mesh.GetTriCentroid(tid);
                    c = toScene.TransformP(c);
                    if (planeF.DistanceToPlaneSigned(c, 2) < 0)
                    {
                        tris1.Add(tid);
                    }
                    else
                    {
                        tris2.Add(tid);
                    }
                }

                double area1 = MeshMeasurements.AreaT(mesh, tris1);
                double area2 = MeshMeasurements.AreaT(mesh, tris2);

                lastSelection = new MeshFaceSelection(mesh);
                lastSelection.Select((area1 > area2) ? tris2 : tris1);
                lastSelection.LocalOptimize();

                if (OnStrokeCompletedF != null)
                {
                    OnStrokeCompletedF(Target, lastSelection);
                }
            }

            CurrentStroke.Clear();
        }
Exemplo n.º 25
0
        override protected void OnUpdateCapture(Ray3f worldRay, Standard3DWidget w)
        {
            SceneObject hitSO = null;
            SORayHit    hit;
            IEnumerable <SceneObject> targetSOs = this.targets;

            if (parentScene.FindSORayIntersection(worldRay, out hit, (x) => ((x is PivotSO) == false) && (targetSOs.Contains(x) == false)))
            {
                hitSO = hit.hitSO;
            }
            if (hitSO != null && hitSO != curActiveSO)
            {
                Snaps.RemoveFromActive(curActiveSO);
                Snaps.AddToActive(hitSO);
                curActiveSO = hitSO;
            }
        }
Exemplo n.º 26
0
        Vector3f vInitialHitPos;     // initial hit position in frame

        public override bool BeginCapture(ITransformable target, Ray3f worldRay, UIRayHit hit)
        {
            if (target.SupportsScaling == false)
            {
                return(false);
            }

            // save local and world frames
            scaleFrameW  = target.GetLocalFrame(CoordSpace.WorldCoords);
            cameraFrameW = new Frame3f(scaleFrameW.Origin, activeCamera.transform.rotation);
            startScale   = target.GetLocalScale();

            // save initial hitpos in plane
            vInitialHitPos = cameraFrameW.RayPlaneIntersection(worldRay.Origin, worldRay.Direction, 2);

            return(true);
        }
 public override CaptureRequest WantsCapture(InputState input)
 {
     if (input.bLeftTriggerPressed ^ input.bRightTriggerPressed)
     {
         CaptureSide eSide  = (input.bLeftTriggerPressed) ? CaptureSide.Left : CaptureSide.Right;
         Ray3f       useRay = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
         UIRayHit    uiHit;
         if (scene.FindUIHit(useRay, out uiHit))
         {
             bool bCanCapture = uiHit.hitUI.WantsCapture(InputEvent.Spatial(eSide, input, new AnyRayHit(uiHit)));
             if (bCanCapture)
             {
                 return(CaptureRequest.Begin(this, eSide));
             }
         }
     }
     return(CaptureRequest.Ignore);
 }
Exemplo n.º 28
0
        bool SiblingFromRay(OctPositionVector subjectPos, VOBoundsDepthNode parent, Ray3f ray, out VOBoundsDepthNode sibling, out Vector3f escapeMagnitudes)
        {
            sibling = new VOBoundsDepthNode(null, default(Bounds));

            Bounds subjectBounds = subjectPos.octant(parent.bounds);

            escapeMagnitudes = EscapeVector.GetCornerMagnitudes(subjectBounds, ray) + new Vector3f(magNudge, magNudge, magNudge);

            OctPositionVector siblingPosVector;
            var cardinalDirection = ray.direction.GetDirection(escapeMagnitudes.IndexOfAbsMin);

            if (subjectPos.Shift(cardinalDirection, out siblingPosVector))
            {
                sibling = new VOBoundsDepthNode(parent.node[siblingPosVector.flatIndex], siblingPosVector.octant(parent.bounds), parent.depth + 1);
                return(true);
            }
            return(false);
        }
 public override Capture UpdateCapture(InputState input, CaptureData data)
 {
     if ((data.which == CaptureSide.Left && input.bLeftTriggerReleased) ||
         (data.which == CaptureSide.Right && input.bRightTriggerReleased))
     {
         Ray3f    useRay = (data.which == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
         SORayHit rayHit;
         if (scene.Scene.FindSORayIntersection(useRay, out rayHit) == false)
         {
             scene.Scene.ClearSelection();
         }
         return(Capture.End);
     }
     else
     {
         return(Capture.Continue);
     }
 }
Exemplo n.º 30
0
        public override Capture UpdateCapture(InputState input, CaptureData data)
        {
            // [RMS] this is a hack to release input for shoulder+trigger gestures
            if ((data.which == CaptureSide.Left && input.bLeftShoulderPressed) ||
                (data.which == CaptureSide.Right && input.bRightShoulderPressed))
            {
                return(Capture.End);
            }

            if ((data.which == CaptureSide.Left && input.bLeftTriggerReleased) ||
                (data.which == CaptureSide.Right && input.bRightTriggerReleased))
            {
                Ray3f       useRay = (data.which == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
                SceneObject so     = data.custom_data as SceneObject;
                SORayHit    rayHit;
                if (so != null && so.FindRayIntersection(useRay, out rayHit))
                {
                    // if other trigger is down we do multi-select add/remove toggling
                    bool bOtherDown =
                        (data.which == CaptureSide.Left && input.bRightTriggerDown) ||
                        (data.which == CaptureSide.Right && input.bLeftTriggerDown);
                    if (bOtherDown)
                    {
                        if (scene.Scene.IsSelected(so))
                        {
                            scene.Scene.Deselect(so);
                        }
                        else
                        {
                            scene.Scene.Select(so, false);
                        }
                    }
                    else
                    {
                        scene.Scene.Select(so, true);
                    }
                }
                return(Capture.End);
            }
            else
            {
                return(Capture.Continue);
            }
        }