Ejemplo n.º 1
0
        public void PreRender(Vector3f cameraPosition)
        {
            FScene scene = so.GetScene();

            // update world-space segment that we need for ray-intersections
            Frame3f frameW = scene.ToWorldFrame(center);

            segmentW.Center    = frameW.Origin;
            segmentW.Direction = frameW.Z;
            segmentW.Extent    = scene.ToWorldDimension(extent);

            //lineGO.GetComponent<LineRenderer>().SetPosition(0, segmentW.P0);

            fLineWidthW = VRUtil.GetVRRadiusForVisualAngle(segmentW.Center, cameraPosition,
                                                           SceneGraphConfig.DefaultSnapCurveVisualDegrees);
            // [RMS] not sure this makes sense...eg what if we have multiple parents? they could
            //   have different scalings, no? ParentScale seems to be inherited from scene scaling,
            //   somehow, but it is unclear...
            float fParentScale = lineGO.transform.parent.localScale[0];
            float fSceneScale  = scene.GetSceneScale();

            fLineWidthW = fLineWidthW / fParentScale / fSceneScale;

            LineRenderer ren = lineGO.GetComponent <LineRenderer>();

            ren.startWidth = ren.endWidth = fLineWidthW;
        }
Ejemplo n.º 2
0
        // called on per-frame Update()
        override public void PreRender()
        {
            gizmo.Show();

            foreach (var v in Widgets)
            {
                float fScaling = VRUtil.GetVRRadiusForVisualAngle(
                    v.Key.GetPosition(),
                    parentScene.ActiveCamera.GetPosition(),
                    SceneGraphConfig.DefaultPivotVisualDegrees);
                fScaling /= parentScene.GetSceneScale();
                v.Key.SetLocalScale(new Vector3f(fScaling, fScaling, fScaling));
            }
        }
Ejemplo n.º 3
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;
            }
Ejemplo n.º 4
0
        public void UpdateMeasurePoint(Vector3d point, CoordSpace eSpace, int nPointNum, bool isFixedPoint = true)
        {
            if (eSpace == CoordSpace.ObjectCoords)
            {
                throw new NotSupportedException("TwoPointMeasureTool.UpdateMeasurePoint");
            }

            Vector3d pointS = (eSpace == CoordSpace.SceneCoords) ? point : scene.ToSceneP(point);

            int i = MathUtil.Clamp(nPointNum, 0, 1);

            setPointsS[i]        = pointS;
            snappedPointsS[i]    = setPointsS[i];
            point_initialized[i] = true;

            if (isFixedPoint)
            {
                return;
            }

            // snap
            List <SceneObject> targets = (SpecificTargets != null) ? SpecificTargets : new List <SceneObject>(scene.SceneObjects);

            float fAvgSnapDist = 0;
            int   avgcount     = 0;

            foreach (var so in targets)
            {
                fAvgSnapDist += VRUtil.GetVRRadiusForVisualAngle(so.GetLocalFrame(CoordSpace.WorldCoords).Origin,
                                                                 scene.ActiveCamera.GetPosition(), snapThresholdAngle);
                avgcount++;
            }
            if (avgcount == 0)
            {
                return;
            }
            fAvgSnapDist /= avgcount;

            SORayHit nearestW;
            Vector3d pointW = (eSpace == CoordSpace.WorldCoords) ? point : scene.ToWorldP(point);

            if (SceneUtil.FindNearestPoint(targets, pointW, fAvgSnapDist, out nearestW, CoordSpace.WorldCoords))
            {
                snappedPointsS[i] = scene.ToSceneP(nearestW.hitPos);
            }
        }
Ejemplo n.º 5
0
        public void PreRender(Vector3f cameraPosition)
        {
            // since we are supporting case where so is moving (ie bimanual grab), we need to
            // update position here. And SetGameObjectFrame() does not support SceneCoords.
            // So map scene to world
            Frame3f FrameW = SceneTransforms.TransformTo(FrameS, so, CoordSpace.SceneCoords, CoordSpace.WorldCoords);

            UnityUtil.SetGameObjectFrame(primGO, FrameW, CoordSpace.WorldCoords);

            float fScaling = VRUtil.GetVRRadiusForVisualAngle(
                primGO.transform.position, cameraPosition,
                SceneGraphConfig.DefaultPivotVisualDegrees * 0.98f);
            // [RMS] not sure this makes sense...eg what if we have multiple parents? they could
            //   have different scalings, no? ParentScale seems to be inherited from scene scaling,
            //   somehow, but it is unclear...
            float fParentScale = primGO.transform.parent.localScale[0];
            float fSceneScale  = so.GetScene().GetSceneScale();

            fScaling = fScaling / fParentScale / fSceneScale;
            primGO.transform.localScale = new Vector3f(fScaling, fScaling, fScaling);
        }
Ejemplo n.º 6
0
        public override Capture BeginCapture(InputState input, CaptureSide eSide)
        {
            HandInfo hi = new HandInfo();

            hi.eMode = ActionMode.TransformCamera;

            Frame3f camFrame = cockpit.ActiveCamera.GetWorldFrame();

            // if both rays hit scene and are within a few visual degrees, then we
            // we pull out a sphere and use it to re-scale the world.
            // Otherwise do normal hand-transform actions
            AnyRayHit hit1, hit2;
            bool      bHit1 = cockpit.Scene.FindSceneRayIntersection(input.vLeftSpatialWorldRay, out hit1);
            bool      bHit2 = cockpit.Scene.FindSceneRayIntersection(input.vRightSpatialWorldRay, out hit2);

            if (bHit1 && bHit2)
            {
                Vector3 avg = (hit1.hitPos + hit2.hitPos) * 0.5f;
                float   d   = VRUtil.GetVRRadiusForVisualAngle(avg, camFrame.Origin, 2.0f);
                if ((hit1.hitPos - hit2.hitPos).Length < d)
                {
                    hi.eMode = ActionMode.SetWorldScale;
                    Frame3f centerF = cockpit.Scene.SceneFrame;
                    centerF.Origin = avg;
                    Frame3f planeF = new Frame3f(centerF.Origin, camFrame.Z);
                    hi.BeginSetWorldScale(centerF, planeF, 2 * d);
                    hi.UpdateSetWorldScale(input.vLeftSpatialWorldRay, input.vRightSpatialWorldRay);
                }
            }

            hi.leftStartF  = input.LeftHandFrame;
            hi.rightStartF = input.RightHandFrame;
            hi.camState    = cockpit.ActiveCamera.Manipulator().GetCurrentState(cockpit.Scene);
            hi.camRight    = camFrame.X;
            hi.camForward  = camFrame.Z;

            cockpit.ActiveCamera.SetTargetVisible(true);

            return(Capture.Begin(this, CaptureSide.Both, hi));
        }
Ejemplo n.º 7
0
        // returns snapped world-frame, or input frame if no snap
        public Frame3f UpdateSnapW(Frame3f fSourceFrameW, SnapSet Snaps)
        {
            FScene scene        = targetSO.GetScene();
            float  fSnapRadiusW = VRUtil.GetVRRadiusForVisualAngle(fSourceFrameW.Origin,
                                                                   scene.ActiveCamera.GetPosition(), SnapThreshVisualAngleDeg);
            float fSnapRadiusS = fSnapRadiusW / scene.GetSceneScale();

            // fSourceFrameW in Scene coordinates
            Frame3f fSourceS = scene.ToSceneFrame(fSourceFrameW);

            SnapResult best_snap    = null;
            float      fNearest     = float.MaxValue;
            Frame3f    fBestSourceL = Frame3f.Identity;

            // snapframes are stored in local coords relative to object
            foreach (Frame3f fPointFrameL in snapFramesL)
            {
                // convert local-coord snap frame into scene coords
                Frame3f fPointFrameS = fSourceS.FromFrame(fPointFrameL);

                SnapResult snap = Snaps.FindNearestSnapPointS(fPointFrameS, fSnapRadiusS);
                if (snap != null)
                {
                    float d = ((Vector3f)snap.FrameS.Origin - fPointFrameS.Origin).Length;
                    if (d < fNearest)
                    {
                        fNearest     = d;
                        fBestSourceL = fPointFrameL;
                        best_snap    = snap;
                    }
                }
            }

            snapState.UpdateState(best_snap, fBestSourceL);
            if (snapState.IsSnapped)
            {
                SnapResult useSnap    = snapState.ActiveSnapTarget;
                Frame3f    useSourceL = (Frame3f)snapState.ActiveSnapData;

                if (SnapOrientation)
                {
                    // compute min-rotation frame, then align origins
                    Frame3f fAlignedSourceS =
                        Frame3f.SolveMinRotation(fSourceS, useSnap.FrameS);
                    Frame3f  fPointFrameS = fAlignedSourceS.FromFrame(useSourceL);
                    Vector3f deltaS       = (Vector3f)useSnap.FrameS.Origin - fPointFrameS.Origin;
                    snapFrameS = fAlignedSourceS.Translated(deltaS);


                    //// this is tricky...we have an object-space frame useSourceL, which
                    ////  we want to snap to a scene-space frame usePoint.FrameS. So we need
                    ////  to shift origin of that frame by -useSourceL_in_FrameS!
                    //snapFrameS = usePoint.FrameS.Translated(
                    //    -usePoint.FrameS.FromFrameV(useSourceL.Origin));
                }
                else
                {
                    // translation-only snap - find shift in scene space, apply to input source frame
                    Frame3f  fPointFrameS = fSourceS.FromFrame(useSourceL);
                    Vector3f deltaS       = (Vector3f)useSnap.FrameS.Origin - fPointFrameS.Origin;
                    snapFrameS = fSourceS.Translated(deltaS);
                }

                // now convert to world frame for return
                return(scene.ToWorldFrame(snapFrameS));
            }

            return(fSourceFrameW);
        }
Ejemplo n.º 8
0
        public override Capture BeginCapture(InputState input, CaptureSide eSide)
        {
            if (input.LeftCaptureActive || input.RightCaptureActive || popup != null)
            {
                DebugUtil.Warning("SceneRightClickBehavior.BeginCapture - we should not be here...");
                return(Capture.Ignore);
            }

            Ray3f useRay = new Ray3f(Vector3f.Zero, Vector3f.AxisY);

            if (input.IsForDevice(InputDevice.Mouse) || input.IsForDevice(InputDevice.Gamepad))
            {
                useRay = (input.bRightMousePressed) ? input.vMouseWorldRay : input.vGamepadWorldRay;
            }
            else if (input.IsForDevice(InputDevice.AnySpatialDevice))
            {
                useRay = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay;
            }

            // raycast into scene to find hit object/position for menu. We try Pivots first,
            // because they are special and have priority (?? always ??). Then we cast into general scene.
            SORayHit  pivotHit;
            bool      bHitPivot = cockpit.Scene.FindSORayIntersection(useRay, out pivotHit, (x) => { return(x is PivotSO); });
            AnyRayHit rayHit;

            if (bHitPivot)
            {
                rayHit = new AnyRayHit(pivotHit);
            }
            else
            {
                if (cockpit.Scene.FindSceneRayIntersection(useRay, out rayHit) == false)
                {
                    return(Capture.Ignore);
                }
            }

            // find center of menu in space
            Vector3f vHUDCenter   = cockpit.RootGameObject.GetPosition();
            Vector3f menuLocation = rayHit.hitPos;

            if (Placement == PlacementMode.OnHUDSphere)
            {
                float fRayT;
                bool  bHit = RayIntersection.Sphere(useRay.Origin, useRay.Direction,
                                                    vHUDCenter, HUDRadius, out fRayT);
                Debug.Assert(bHit);
                menuLocation = useRay.Origin + fRayT * useRay.Direction;
            }

            // compute extents
            float fDiameter = VRUtil.GetVRRadiusForVisualAngle(
                menuLocation, cockpit.ActiveCamera.GetPosition(), VisualDiameter);

            if (rayHit.eType == HitType.SceneObjectHit && rayHit.hitSO is PivotSO)
            {
                popup = GeneratePivotRadialMenu(fDiameter, rayHit.hitSO as PivotSO);
            }
            else if (rayHit.eType == HitType.SceneObjectHit)
            {
                popup = GenerateSceneObjectRadialMenu(fDiameter, rayHit);
            }
            else
            {
                popup = GenerateDefaultRadialMenu(fDiameter, rayHit);
            }
            popup.Create();
            popup.Name = "popup_menu";

            if (Placement == PlacementMode.InScene)
            {
                HUDUtil.PlaceInScene(popup, vHUDCenter, menuLocation);
            }
            else
            {
                HUDUtil.PlaceInSphere(popup, HUDRadius, vHUDCenter, menuLocation);
            }

            // this is a bit of a hack...radial menu lives in-scene, if we attach it to
            //   cockpit then it will move with cockpit, which is wrong. So we want to
            //   stick it in the scene. But, at least for now, we still want it to be
            //   drawn in the cockpit layer, so we add to cockpit first, them remove and
            //   re-add to the scene
            cockpit.AddUIElement(popup, false);
            cockpit.RemoveUIElement(popup, false);
            cockpit.Scene.AddUIElement(popup, false);

            HUDUtil.AnimatedShow(popup, 0.2f);

            return(Capture.Begin(this, eSide));
        }