Пример #1
0
 override public bool BeginCapture(InputEvent e)
 {
     if (Enabled && HasGO(e.hit.hitGO) && in_drag == false)
     {
         if (last_click_time != 0 &&
             (FPlatform.RealTime() - last_click_time) < SceneGraphConfig.ActiveDoubleClickDelay)
         {
             in_double_click = true;
         }
         else
         {
             hitFrame = cockpit.GetLocalFrame(CoordSpace.WorldCoords);
             float fRayT = 0.0f;
             if (RayIntersection.Sphere(e.ray.Origin, e.ray.Direction, hitFrame.Origin, IndicatorDistance, out fRayT) == false)
             {
                 return(false);       // should not happen! but could.
             }
             startHitPos = e.ray.Origin + fRayT * e.ray.Direction;
             start_tilt  = cockpit.TiltAngle;
             start_shift = cockpit.ShiftAngle;
             in_drag     = true;
         }
         return(true);
     }
     return(false);
 }
Пример #2
0
        // returns frame at ray-intersection point, with normal pointing *outwards*
        public static Frame3f GetSphereFrame(float fHUDRadius, float fHorzAngleDeg, float fVertAngleDeg)
        {
            Ray3f r     = VRUtil.MakeRayFromSphereCenter(fHorzAngleDeg, fVertAngleDeg);
            float fRayT = 0.0f;

            RayIntersection.Sphere(r.Origin, r.Direction, Vector3f.Zero, fHUDRadius, out fRayT);
            Vector3f v = r.Origin + fRayT * r.Direction;

            return(new Frame3f(v, v.Normalized));
        }
Пример #3
0
        override public bool UpdateCapture(InputEvent e)
        {
            if (in_drag)
            {
                float fRayT = 0.0f;
                if (RayIntersection.Sphere(e.ray.Origin, e.ray.Direction, hitFrame.Origin, IndicatorDistance, out fRayT) == false)
                {
                    return(true);        // should not happen, but I guess it could if user
                }
                // had arms out in some crazy position...
                Vector3f v        = e.ray.Origin + fRayT * e.ray.Direction;
                Vector3f vToHit   = (v - hitFrame.Origin).Normalized;
                Vector3f vToStart = (startHitPos - hitFrame.Origin).Normalized;
                float    deltaUp  = -VRUtil.PlaneAngleSigned(vToHit, vToStart, hitFrame.X);
                cockpit.TiltAngle = MathUtil.Clamp(start_tilt + deltaUp, -30.0f, 20.0f);
                float deltaLR = -VRUtil.PlaneAngleSigned(vToHit, vToStart, hitFrame.Y);
                cockpit.ShiftAngle = start_shift + deltaLR;
                //if ( tracker.IsLocked == false )
                cockpit.ShiftAngle = MathUtil.Clamp(cockpit.ShiftAngle, -10.0f, 10.0f);
            }

            return(true);
        }
    // Use this for initialization
    public override void Awake()
    {
        // if we need to auto-configure Rift vs Vive vs (?) VR, we need
        // to do this before any other F3 setup, because MainCamera will change
        // and we are caching that in a lot of places...
        if (AutoConfigVR)
        {
            VRCameraRig = gs.VRPlatform.AutoConfigureVR();
        }

        // restore any settings
        SceneGraphConfig.RestorePreferences();

        // set up some defaults
        // this will move the ground plane down, but the bunnies will be floating...
        //SceneGraphConfig.InitialSceneTranslate = -4.0f * Vector3f.AxisY;
        SceneGraphConfig.DefaultSceneCurveVisualDegrees = 0.5f;
        SceneGraphConfig.DefaultPivotVisualDegrees      = 1.5f;
        SceneGraphConfig.DefaultAxisGizmoVisualDegrees  = 10.0f;
        SceneGraphConfig.InitialSceneTranslate          = -4 * Vector3f.AxisY;


        SceneOptions options = new SceneOptions();

        options.UseSystemMouseCursor = false;
        options.Use2DCockpit         = false;
        options.EnableTransforms     = true;
        options.EnableCockpit        = true;
        options.CockpitInitializer   = new PhotoToolCockpit();

        options.MouseCameraControls = new MayaCameraHotkeys();
        options.SpatialCameraRig    = VRCameraRig;

        // very verbose
        options.LogLevel = 2;

        context = new FContext();
        context.Start(options);

        // if you had other gizmos, you would register them here
        //context.TransformManager.RegisterGizmoType("snap_drag", new SnapDragGizmoBuilder());
        //controller.TransformManager.SetActiveGizmoType("snap_drag");

        // if you had other tools, you would register them here.
        context.ToolManager.RegisterToolType(DrawPrimitivesTool.Identifier, new DrawPrimitivesToolBuilder());
        context.ToolManager.RegisterToolType(DrawSurfaceCurveTool.Identifier, new DrawSurfaceCurveToolBuilder()
        {
            AttachCurveToSurface = true,
            DefaultSamplingRateS = 0.0025f, DefaultSurfaceOffsetS = 0.0025f,
            CurveMaterialF       = () => { var mat = context.Scene.DefaultCurveSOMaterial.Clone(); mat.RGBColor = Colorf.VideoRed; return(mat); }
        });
        context.ToolManager.SetActiveToolType(DrawSurfaceCurveTool.Identifier, ToolSide.Right);

        // Set up standard scene lighting if requested
        if (options.EnableDefaultLighting)
        {
            GameObject lighting = GameObject.Find("SceneLighting");
            if (lighting == null)
            {
                lighting = new GameObject("SceneLighting");
            }
            SceneLightingSetup setup = lighting.AddComponent <SceneLightingSetup>();
            setup.Context       = context;
            setup.LightDistance = 30.0f; // related to total scene scale...
        }


        Context.Scene.DisableSelectionMaterial = true;


        /*
         * Import elements of Unity scene that already exist into the FScene
         */

        // set up ground plane geometry (optional)
        GameObject groundPlane = GameObject.Find("GroundPlane");

        if (groundPlane != null && groundPlane.IsVisible())
        {
            context.Scene.AddWorldBoundsObject(groundPlane);
        }


        float    fSquareSize = 1.0f;
        Vector3f eyePos      = context.ActiveCamera.GetPosition();

        System.Random rand = new System.Random(31337);

        // [RMS] this path only works in Editor, is relative to top-level project directory
        string sPhotoFolder = "Data\\PhotoSets\\kitchen";

        string[] photos = Directory.GetFiles(sPhotoFolder);
        foreach (string filename in photos)
        {
            Texture2D tex = load_texture(filename);
            if (tex == null)
            {
                continue;
            }

            float fScale = fSquareSize / (float)tex.width;
            if (tex.height > tex.width)
            {
                fScale = fSquareSize / (float)tex.height;
            }

            float w = fScale * (float)tex.width;
            float h = fScale * (float)tex.height;

            TrivialRectGenerator rectgen = new TrivialRectGenerator()
            {
                Width = w, Height = h
            };
            rectgen.Generate();
            DMesh3 mesh = new DMesh3(MeshComponents.VertexUVs);
            rectgen.MakeMesh(mesh);

            SOMaterial material = new SOMaterial()
            {
                Name     = "photomaterial",
                Type     = SOMaterial.MaterialType.TextureMap,
                RGBColor = Colorf.White
            };
            material.MainTexture = tex;

            DMeshSO so = new DMeshSO();
            so.Create(mesh, material);
            context.Scene.AddSceneObject(so);

            float horz = rand.Next(-50, 50);
            float vert = rand.Next(-20, 25);
            int   mult = 1000;
            float dist = (float)(rand.Next(2 * mult, 3 * mult)) / (float)mult;

            Ray3f r = VRUtil.MakeRayFromSphereCenter(horz, vert);
            r.Origin += eyePos;
            float fRayT = 0.0f;
            RayIntersection.Sphere(r.Origin, r.Direction, eyePos, dist, out fRayT);
            Vector3f v = r.Origin + fRayT * r.Direction;
            Frame3f  f = new Frame3f(v, v.Normalized);

            Vector3f toEye = context.ActiveCamera.GetPosition() - f.Origin;
            toEye.Normalize();
            f.AlignAxis(1, toEye);
            f.ConstrainedAlignAxis(2, Vector3f.AxisY, f.Y);

            so.SetLocalFrame(f, CoordSpace.WorldCoords);
        }
    }
Пример #5
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));
        }