Пример #1
0
    static void Main(string[] args)
    {
        Demos.TestMode = args.Length > 0 && args[0].ToLower() == "-test";

        StereoKitApp.settings.assetsFolder = Program.Root;
        if (!StereoKitApp.Initialize("StereoKit C#", Demos.TestMode ? Runtime.Flatscreen : Runtime.MixedReality, true))
        {
            Environment.Exit(1);
        }
        CommonInit();

        Demos.FindDemos();
        Demos.SetActive(args.Length > 0 ? args[0] : "Geo");
        Demos.Initialize();

        while (StereoKitApp.Step(() =>
        {
            Demos.Update();
            CommonUpdate();
        }))
        {
            ;
        }

        Demos.Shutdown();
        CommonShutdown();

        StereoKitApp.Shutdown();
    }
Пример #2
0
        static void Main(string[] args)
        {
            if (!StereoKitApp.Initialize("ex01", Runtime.MixedReality))
            {
                Environment.Exit(1);
            }

            Solid solid = new Solid(Vec3.Zero, Quat.Identity);

            Model cube = Model.FromMesh(
                Mesh.GenerateRoundedCube(Vec3.One, 0.2f),
                Default.Material);

            Plane floor = new Plane(Vec3.Up, 10);

            solid.AddBox(Vec3.One);

            while (StereoKitApp.Step(() =>
            {
                Log.Info(String.Format("normal: {0}", floor.normal));
                cube.SetTransform(0, solid.GetPose().ToMatrix());
                cube.Draw(Matrix.TS(Vec3.Zero, 0.1f));
            }))
            {
                ;
            }

            StereoKitApp.Shutdown();
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Initialize StereoKit
            StereoKitApp.settings.assetsFolder = "Assets";
            if (!StereoKitApp.Initialize("ContextualAssistanceV2", Runtime.MixedReality))
            {
                Environment.Exit(1);
            }

            camera = new UdpFRCamera();
            _      = camera.Start();

            socket = new DisplayUdpSocket();
            socket.OnReceivedDisplayCommand += Program.OnReceivedDisplayCommand;

            _ = camera.Connect("172.22.192.1", "9999");
            _ = socket.Connect("172.22.192.1", "9998");

            // Core application loop
            while (StereoKitApp.Step(() =>
            {
            }))
            {
                ;
            }
            StereoKitApp.Shutdown();
        }
Пример #4
0
        private void DisplayButtonPanel()
        {
            Vec3 headPosition   = Input.Head.position;
            Vec3 windowPosition = new Vec3(0.4f, 0f, 0.1f);
            Pose windowPose     = new Pose(windowPosition, Quat.LookAt(windowPosition, headPosition));

            UI.WindowBegin("Button Panel", ref windowPose, new Vec2(25f, 25f) * Units.cm2m, false);
            if (UI.Button("Cube"))
            {
                whichObject = "cube";
            }
            if (UI.Button("Sphere"))
            {
                whichObject = "sphere";
            }
            if (UI.Button("Reset"))
            {
                spawnedModels.Clear();
                objects.Clear();
                spawnedModels.Add(Model.FromMesh(
                                      Mesh.GenerateCube(new Vec3(20f, 1f, 20f)),
                                      Default.Material
                                      ));
                objects.Add(floor);
            }
            if (UI.Button("Exit"))
            {
                StereoKitApp.Quit();
            }
            UI.WindowEnd();
        }
Пример #5
0
        static void Main(string[] args)
        {
            Model cubeModel;
            Model sphereModel;

            if (!StereoKitApp.Initialize("MessingWithBounds", Runtime.MixedReality))
            {
                Environment.Exit(1);
            }

            // Creating models
            cubeModel = Model.FromMesh(
                Mesh.GenerateCube(Vec3.One * 0.25f),
                Default.Material
                );
            sphereModel = Model.FromMesh(
                Mesh.GenerateSphere(0.15f),
                Default.Material
                );

            // Creating grabbable versions of the above models
            Grabbable grabbableCube   = new Grabbable(ref cubeModel, new Vec3(-0.25f, 0f, 0f));
            Grabbable grabbableSphere = new Grabbable(ref sphereModel, new Vec3(0.25f, 0f, 0f));

            while (StereoKitApp.Step(() =>
            {
                grabbableCube.Update();
                grabbableSphere.Update();
            }))
            {
                ;
            }

            StereoKitApp.Shutdown();
        }
Пример #6
0
    static void Main(string[] args)
    {
        StereoKitApp.settings.shaderCache = Program.Root;
        if (!StereoKitApp.Initialize("StereoKit C#", Runtime.Flatscreen, true))
        {
            Environment.Exit(1);
        }
        CommonInit();

        activeScene = new DemoUI();
        activeScene.Initialize();

        while (StereoKitApp.Step(() =>
        {
            if (nextScene != null)
            {
                activeScene.Shutdown();
                nextScene.Initialize();
                activeScene = nextScene;
                nextScene = null;
            }
            CommonUpdate();
            activeScene.Update();
        }))
        {
            ;
        }

        activeScene.Shutdown();
        CommonShutdown();

        StereoKitApp.Shutdown();
    }
Пример #7
0
    public static void Update()
    {
        if (nextScene != null)
        {
            activeScene.Shutdown();
            if (IsTesting)
            {
                Input.HandVisible(Handed.Max, false);
            }

            nextScene.Initialize();
            activeScene = nextScene;
            nextScene   = null;
        }
        activeScene.Update();

        if (IsTesting && FinishedWithTest())
        {
            testIndex += 1;
            if (testIndex >= allTests.Count)
            {
                StereoKitApp.Quit();
            }
            else
            {
                SetTestActive(allTests[testIndex].Name);
            }
        }
    }
Пример #8
0
 /// <summary>If the file picker is `Active`, this will cancel it out and remove it from
 /// the stepper list. If it's already inactive, this does nothing!</summary>
 public static void Hide()
 {
     if (_inst != null)
     {
         StereoKitApp.RemoveStepper(_inst);
     }
     _inst = null;
 }
Пример #9
0
        static void Main(string[] args)
        {
            // Initialize StereoKit! Before initialization, we can prepare a few settings,
            // like the assetsFolder. This is the folder that StereoKit will look for assets
            // in when provided a relative folder name. Then we just Initialize StereoKit with
            // the name of our app! Initialize can also be told to make a flatscreen app, or
            // how to behave if the preferred initialization mode fails.
            StereoKitApp.settings.assetsFolder = "Assets";
            if (!StereoKitApp.Initialize("StereoKitPaintTutorial"))
            {
                Environment.Exit(1);
            }

            // This is a simple radial hand menu where we'll store some quick actions! It's
            // activated by a grip motion, and is great for fast, gesture-like activation
            // of menu items. It also can be used with multiple HandRadialLayers to nest
            // commands in sub-menus.
            //
            // Steppers are classes that implement the IStepper interface, and once added to
            // StereoKit's stepper list, will have their Step method called each frame! This
            // is a great way to add fire-and-forget objects or systems that need to update
            // each frame.
            StereoKitApp.AddStepper(new HandMenuRadial(
                                        new HandRadialLayer("Root", -90,
                                                            new HandMenuItem("Undo", null, () => activePainting?.Undo()),
                                                            new HandMenuItem("Redo", null, () => activePainting?.Redo()))));

            // Initialize the palette menu, see PaletteMenu.cs! This class manages the palette
            // UI object for manipulating our brush stroke size and color.
            paletteMenu = new PaletteMenu();

            // Step the application each frame, until StereoKit is told to exit! The callback
            // code here is called every frame after input and system events, but before the
            // draw events!
            while (StereoKitApp.Step(() =>
            {
                // Send input information to the painting, it will handle this info to create
                // brush strokes. This will also draw the painting too!
                activePainting.Step(Handed.Right, paletteMenu.PaintColor, paletteMenu.PaintSize);

                // Step our palette UI!
                paletteMenu.Step();

                // Step our application's menu! This includes Save/Load Clear and Quit commands.
                StepMenuWindow();
            }))
            {
                ;
            }

            // We're done! Clean up StereoKit and all its resources :)
            StereoKitApp.Shutdown();
        }
Пример #10
0
 /// :End:
 ///
 void ShowWindow()
 {
     /// :CodeDoc: Guides User Interface
     /// Then we'll move over to the application step where we'll do the rest of the UI code!
     ///
     /// We'll start with a window titled "Window" that's 20cm wide, and auto-resizes on the
     /// y-axis. The Units class is pretty helpful here, as it allows us to reason more visually
     /// about the units we're using! StereoKit uses meters as its base unit, which look a little
     /// awkward, especially in the millimeter range.
     ///
     /// We'll also use a toggle to turn the window's header on and off! The value from that toggle
     /// is passed in here via the showHeader field.
     ///
     UI.WindowBegin("Window", ref windowPose, new Vec2(20, 0) * Units.cm2m, windowShowHeader);
     ///
     /// When you begin a window, all visual elements are now relative to that window! UI takes advantage
     /// of the Hierarchy class and pushes the window's pose onto the Hierarchy stack. Ending the window
     /// will pop the pose off the hierarchy stack, and return things to normal!
     ///
     /// Here's that toggle button! You'll also notice our use of 'ref' values in a lot of the UI
     /// code. UI functions typically follow the pattern of returning true/false to indicate they've
     /// been interacted with during the frame, so you can nicely wrap them in 'if' statements to
     /// react to change!
     ///
     /// Then with the 'ref' parameter, we let you pass in the current state of the UI element. The UI
     /// element will update that value for you based on user interaction, but you can also change it
     /// yourself whenever you want to!
     ///
     UI.Toggle("Show Header", ref windowShowHeader);
     ///
     /// Here's an example slider! We start off with a label element, and tell the UI to
     /// keep the next item on the same line. The slider clamps to the range [0,1], and
     /// will step at intervals of 0.2. If you want it to slide continuously, you can just set
     /// the `step` value to 0!
     ///
     UI.Label("Slide");
     UI.SameLine();
     UI.HSlider("slider", ref windowSlider, 0, 1, 0.2f, 72 * Units.mm2m);
     ///
     /// Here's how you use a simple button! Just check it with an 'if'. Any UI method
     /// will return true on the frame when their value or state has changed.
     ///
     if (UI.ButtonRound("Exit", windowPowerSprite))
     {
         StereoKitApp.Quit();
     }
     ///
     /// And for every begin, there must also be an end! StereoKit will log errors when this
     /// occurs, so keep your eyes peeled for that!
     ///
     UI.WindowEnd();
     /// :End:
 }
Пример #11
0
 /// <summary>Show a file picker to the user! If one is already up, it'll be cancelled out,
 /// and this one will replace it.</summary>
 /// <param name="initialFolder">The starting folder. By default (or null), this'll just be
 /// the working directory.</param>
 /// <param name="onSelectFile">The function to call when the user has selected a file.</param>
 /// <param name="onCancel">If the file selection has been cancelled, this'll get called!</param>
 /// <param name="filters">What file types should show up in the picker?</param>
 public static void Show(string initialFolder, Action <string> onSelectFile, Action onCancel, params FileFilter[] filters)
 {
     if (_inst != null)
     {
         _inst._onCancel?.Invoke();
     }
     if (_inst == null)
     {
         _inst = StereoKitApp.AddStepper(new FilePicker());
     }
     _inst.Setup(initialFolder, onSelectFile, onCancel, filters);
 }
Пример #12
0
 /// <summary>Show a file picker to the user! If one is already up, it'll be cancelled out,
 /// and this one will replace it.</summary>
 /// <param name="mode">For opening files, or for saving them?</param>
 /// <param name="initialFolder">The starting folder. By default (or null), this'll just be
 /// the working directory.</param>
 /// <param name="onSelectFile">The function to call when the user has selected a file.</param>
 /// <param name="onCancel">If the file selection has been cancelled, this'll get called!</param>
 /// <param name="filters">What file types should show up in the picker?</param>
 public static void Show(FilePickerMode mode, string initialFolder, Action <string> onSelectFile, Action onCancel, params FileFilter[] filters)
 {
     if (_inst != null)
     {
         _inst._onCancel?.Invoke();
     }
     if (_inst == null)
     {
         _inst = StereoKitApp.AddStepper(new FilePicker());
         Vec3 pos = Input.Head.position + Input.Head.Forward * .5f + Input.Head.Up * 0.2f;
         _inst._windowPose = new Pose(pos, Quat.LookAt(pos, Input.Head.position));
     }
     _inst.Setup(mode, initialFolder, onSelectFile, onCancel, filters);
 }
Пример #13
0
        static void StepMenuWindow()
        {
            // Begin the application's menu window
            UI.WindowBegin("Menu", ref menuPose, new Vec2(20, 0) * Units.cm2m);

            // When the user presses the save button, lets show a save file dialog! When a file
            // name and folder have been selected, it'll make a call to SavePainting with the
            // file's path name with the .skp extension.
            if (UI.Button("Save"))
            {
                FilePicker.Show(
                    FilePickerMode.Save,
                    defaultFolder,
                    SavePainting,
                    new FileFilter("Painting", "*.skp"));
            }

            // And on that same line, we'll have a load button! This'll let the user pick out
            // any .skp files, and will call LoadPainting with the selected file.
            UI.SameLine();
            if (UI.Button("Load"))
            {
                FilePicker.Show(
                    FilePickerMode.Open,
                    defaultFolder,
                    LoadPainting,
                    new FileFilter("Painting", "*.skp"));
            }

            // Clear is easy! Just create a new Painting object!
            if (UI.Button("Clear"))
            {
                activePainting = new Painting();
            }

            // And if they want to quit? Just tell StereoKit! This will let StereoKit finish the
            // the frame properly, and then break out of the Step loop above.
            if (UI.Button("Quit"))
            {
                StereoKitApp.Quit();
            }

            // And end the window!
            UI.WindowEnd();
        }
Пример #14
0
        static void Main(string[] args)
        {
            if (!StereoKitApp.Initialize("Day00_ex01", Runtime.Flatscreen))
            {
                Environment.Exit(1);
            }

            //Cube cube = new Cube(0);
            //Cube cube1 = new Cube(0.2f);
            //Cube cube2 = new Cube(-0.2f);

            CubeList cubeList       = new CubeList();
            Vec3     collision_size = new Vec3(5, 2, 1);
            Vec3     collision_pos  = new Vec3(0, -0.5f, 0);

            // Setting transparency, for some reason
            // the cube goes transparent in the area of
            // the colliding hand

            Material trans = Default.Material;

            trans.Transparency = Transparency.None;

            //creating the collision box

            Model collision_box = Model.FromMesh(
                Mesh.GenerateRoundedCube(collision_size, 0),
                trans);

            while (StereoKitApp.Step(() =>
            {
                //cube.Step();
                //cube1.Step();
                //cube2.Step();
                cubeList.Step();
                collision_box.Draw(Matrix.TS(collision_pos, 0.1f));

                cubeList.DeleteCube();
            }))
            {
                ;
            }

            StereoKitApp.Shutdown();
        }
Пример #15
0
        static void Main(string[] args)
        {
            if (!StereoKitApp.Initialize("StereoKitProject_ballon", Runtime.MixedReality))
            {
                Environment.Exit(1);
            }
            ObjectSet ObjectBlowing = new ObjectSet();

            while (StereoKitApp.Step(() =>
            {
                ObjectBlowing.Update();
            }))
            {
                ;
            }

            StereoKitApp.Shutdown();
        }
Пример #16
0
        private void DisplayButtonPanel()
        {
            Vec3 headPosition   = Input.Head.position;
            Vec3 windowPosition = new Vec3(0.4f, 0f, 0.1f);
            Pose windowPose     = new Pose(windowPosition, Quat.LookAt(windowPosition, headPosition));

            UI.WindowBegin("Button Panel", ref windowPose, new Vec2(20f, 20f) * Units.cm2m, false);

            if (UI.Button("Start"))
            {
                start = true;
            }

            if (UI.Button("Exit"))
            {
                StereoKitApp.Quit();
            }
            UI.WindowEnd();
        }
Пример #17
0
        static void Main(string[] args)
        {
            if (!StereoKitApp.Initialize("StereoKit C#", Runtime.MixedReality, true))
            {
                Environment.Exit(1);
            }

            Model cube = new Model(Mesh.GenerateRoundedCube(Vec3.One, 0.1f), Material.Find("default/material"));

            while (StereoKitApp.Step(() =>
            {
                Renderer.Add(cube, Matrix.Identity, Color.White);
            }))
            {
                ;
            }

            StereoKitApp.Shutdown();
        }
Пример #18
0
        static void Main(string[] args)
        {
            if (!StereoKitApp.Initialize("MessingWithSolids", Runtime.MixedReality))
            {
                Environment.Exit(1);
            }

            ObjectSpawner ObjectSpawner = new ObjectSpawner();

            while (StereoKitApp.Step(() =>
            {
                ObjectSpawner.Update();
            }))
            {
                ;
            }

            StereoKitApp.Shutdown();
        }
Пример #19
0
    static void CommonUpdate()
    {
        if (Input.Key(Key.Esc).IsJustActive())
        {
            StereoKitApp.Quit();
        }

        // If we can't see the world, we'll draw a floor!
        if (StereoKitApp.System.displayType == Display.Opaque)
        {
            Renderer.Add(floorMesh, floorTr, Color.White);
        }

        // Skip selection window if we're in test mode
        if (Tests.IsTesting)
        {
            return;
        }

        // Make a window for demo selection
        UI.WindowBegin("Demos", ref demoSelectPose, new Vec2(50 * U.cm, 0));
        for (int i = 0; i < Tests.DemoCount; i++)
        {
            string name = Tests.GetDemoName(i).Substring("Demo".Length);

            if (UI.Button(name))
            {
                Tests.SetDemoActive(i);
            }
            UI.SameLine();
        }
        UI.WindowEnd();

        RulerWindow();
        DebugToolWindow.Step();
        /// :CodeSample: Log.Subscribe Log
        /// And in your Update loop, you can draw the window.
        LogWindow();
        /// And that's it!
        /// :End:
    }
Пример #20
0
    static void Main(string[] args)
    {
        StereoKitApp.settings.shaderCache = Program.Root;
        if (!StereoKitApp.Initialize("StereoKit C#", Runtime.MixedReality, true))
        {
            Environment.Exit(1);
        }
        CommonInit();

        while (StereoKitApp.Step(() =>
        {
            CommonUpdate();
        }))
        {
            ;
        }

        CommonShutdown();

        StereoKitApp.Shutdown();
    }
Пример #21
0
        static void Main(string[] args)
        {
            if (!StereoKitApp.Initialize("Project", Runtime.MixedReality))
            {
                Environment.Exit(1);
            }

            Model cube = Model.FromMesh(
                Mesh.GenerateRoundedCube(Vec3.One, 0.2f),
                Material.Find(DefaultIds.material));

            while (StereoKitApp.Step(() =>
            {
                cube.Draw(Matrix.TS(Vec3.Zero, 0.1f));
            }))
            {
                ;
            }

            StereoKitApp.Shutdown();
        }
Пример #22
0
    /// :End:

    //////////////////////

    static void Main(string[] args)
    {
        Tests.IsTesting = args.Length > 0 && args[0].ToLower() == "-test";
        Time.Scale      = Tests.IsTesting ? 0 : 1;

        /// :CodeSample: Log.Subscribe Log
        /// Then you add the OnLog method into the log events like this in your initialization
        /// code!
        Log.Subscribe(OnLog);
        /// :End:
        Log.Filter = LogLevel.Diagnostic;
        Log.Write(LogLevel.Diagnostic, "Temp path: " + System.IO.Path.GetTempPath());
        StereoKitApp.settings.assetsFolder = Program.Root;
        if (!StereoKitApp.Initialize("StereoKit C#", Tests.IsTesting ? Runtime.Flatscreen : Runtime.MixedReality, true))
        {
            Environment.Exit(1);
        }

        CommonInit();

        Tests.FindTests();
        Tests.SetTestActive(args.Length > 0 ? args[0] : "Lines");
        Tests.Initialize();

        while (StereoKitApp.Step(() =>
        {
            Tests.Update();
            CommonUpdate();
        }))
        {
            ;
        }

        Tests.Shutdown();
        CommonShutdown();

        StereoKitApp.Shutdown();
    }
Пример #23
0
        static void Main(string[] args)
        {
            // Initialize StereoKit
            StereoKitApp.settings.assetsFolder = "Assets";
            if (!StereoKitApp.Initialize("SKTemplate_UWP_Name", Runtime.MixedReality))
            {
                Environment.Exit(1);
            }


            // Create assets used by the app
            Pose  cubePose = new Pose(0, 0, -0.5f, Quat.Identity);
            Model cube     = Model.FromMesh(
                Mesh.GenerateRoundedCube(Vec3.One * 0.1f, 0.02f),
                Default.MaterialUI);

            Matrix   floorTransform = Matrix.TS(new Vec3(0, -1.5f, 0), new Vec3(30, 0.1f, 30));
            Material floorMaterial  = new Material(Shader.FromFile("floor.hlsl"));

            floorMaterial.Transparency = Transparency.Blend;


            // Core application loop
            while (StereoKitApp.Step(() =>
            {
                if (StereoKitApp.System.displayType == Display.Opaque)
                {
                    Default.MeshCube.Draw(floorMaterial, floorTransform);
                }

                UI.Handle("Cube", ref cubePose, cube.Bounds);
                cube.Draw(cubePose.ToMatrix());
            }))
            {
                ;
            }
            StereoKitApp.Shutdown();
        }
Пример #24
0
    /// :End:

    //////////////////////

    static void Main(string[] args)
    {
        Demos.TestMode = args.Length > 0 && args[0].ToLower() == "-test";
        Time.Scale     = Demos.TestMode ? 0 : 1;

        Log.Filter = LogLevel.Diagnostic;
        StereoKitApp.settings.assetsFolder = Program.Root;
        if (!StereoKitApp.Initialize("StereoKit C#", Demos.TestMode ? Runtime.Flatscreen : Runtime.MixedReality, true))
        {
            Environment.Exit(1);
        }

        if (Demos.TestMode)
        {
            Input.HandVisible(Handed.Max, false);
        }

        CommonInit();

        Demos.FindDemos();
        Demos.SetActive(args.Length > 0 ? args[0] : "Lines");
        Demos.Initialize();

        while (StereoKitApp.Step(() =>
        {
            Demos.Update();
            CommonUpdate();
        }))
        {
            ;
        }

        Demos.Shutdown();
        CommonShutdown();

        StereoKitApp.Shutdown();
    }
Пример #25
0
    public static void Update()
    {
        if (nextScene != null)
        {
            activeScene.Shutdown();
            nextScene.Initialize();
            activeScene = nextScene;
            nextScene   = null;
        }
        activeScene.Update();

        if (TestMode)
        {
            testIndex += 1;
            if (testIndex >= Count)
            {
                StereoKitApp.Quit();
            }
            else
            {
                SetActive(testIndex);
            }
        }
    }
Пример #26
0
    public void Update()
    {
        if (Demos.TestMode)
        {
            Renderer.Screenshot(new Vec3(-0.325f, -0.00f, .075f), new Vec3(-.4f, -0.05f, 0), 600, 400, "../../../docs/img/screenshots/GuideUserInterface.jpg");
            Renderer.Screenshot(new Vec3(0.225f, 0.0f, .175f), new Vec3(.4f, 0.0f, 0), 400, 600, "../../../docs/img/screenshots/GuideUserInterfaceCustom.jpg");
        }

        /// :CodeDoc: Guides User Interface
        /// Then we'll move over to the application step where we'll do the rest of the UI code!
        ///
        /// We'll start with a window titled "Window" that's 20cm wide, and auto-resizes on the
        /// y-axis. The Units class is pretty helpful here, as it allows us to reason more visually
        /// about the units we're using! StereoKit uses meters as its base unit, which look a little
        /// awkward, especially in the millimeter range.
        ///
        /// We'll also use a toggle to turn the window's header on and off! The value from that toggle
        /// is passed in here via the showHeader field.
        ///
        UI.WindowBegin("Window", ref windowPose, new Vec2(20, 0) * Units.cm2m, showHeader);
        ///
        /// When you begin a window, all visual elements are now relative to that window! UI takes advantage
        /// of the Hierarchy class and pushes the window's pose onto the Hierarchy stack. Ending the window
        /// will pop the pose off the hierarchy stack, and return things to normal!
        ///
        /// Here's that toggle button! You'll also notice our use of 'ref' values in a lot of the UI
        /// code. UI functions typically follow the pattern of returning true/false to indicate they've
        /// been interacted with during the frame, so you can nicely wrap them in 'if' statements to
        /// react to change!
        ///
        /// Then with the 'ref' parameter, we let you pass in the current state of the UI element. The UI
        /// element will update that value for you based on user interaction, but you can also change it
        /// yourself whenever you want to!
        ///
        UI.Toggle("Show Header", ref showHeader);
        ///
        /// Here's an example slider! We start off with a label element, and tell the UI to
        /// keep the next item on the same line. The slider clamps to the range [0,1], and
        /// will step at intervals of 0.2. If you want it to slide continuously, you can just set
        /// the `step` value to 0!
        ///
        UI.Label("Slide");
        UI.SameLine();
        UI.HSlider("slider", ref slider, 0, 1, 0.2f, 72 * Units.mm2m);
        ///
        /// Here's how you use a simple button! Just check it with an 'if'. Any UI method
        /// will return true on the frame when their value or state has changed.
        ///
        if (UI.ButtonRound("Exit", powerSprite))
        {
            StereoKitApp.Quit();
        }
        ///
        /// And for every begin, there must also be an end! StereoKit will log errors when this
        /// occurs, so keep your eyes peeled for that!
        ///
        UI.WindowEnd();
        ///
        /// ## Custom Windows
        ///
        /// ![Simple UI]({{site.url}}/img/screenshots/GuideUserInterfaceCustom.jpg)
        ///
        /// Mixed Reality also provides us with the opportunity to turn objects into interfaces!
        /// Instead of using the old 'window' paradigm, we can create 3D models and apply UI
        /// elements to their surface! StereoKit uses 'affordances' to accomplish this, a grabbable
        /// area that behaves much like a window, but with a few more options for customizing
        /// layout and size.
        ///
        /// We'll load up a clipboard, so we can attach an interface to that!
        ///
        /// ```csharp
        /// Model clipboard = Model.FromFile("Clipboard.glb");
        /// ```
        ///
        /// And, similar to the window previously, here's how you would turn it into a grabbable
        /// interface! This behaves the same, except we're defining where the grabbable region is
        /// specifically, and then drawing our own model instead of a plain bar. You'll also notice
        /// we're drawing using an identity matrix. This takes advantage of how AffordanceBegin
        /// pushes the affordance's pose onto the Hierarchy transform stack!
        ///
        UI.AffordanceBegin("Clip", ref clipboardPose, clipboard.Bounds);
        Renderer.Add(clipboard, Matrix.Identity);
        ///
        /// Once we've done that, we also need to define the layout area of the model, where UI
        /// elements will go. This is different for each model, so you'll need to plan this around
        /// the size of your object!
        ///
        UI.LayoutArea(new Vec3(12, 13, 0) * Units.cm2m, new Vec2(24, 30) * Units.cm2m);
        ///
        /// Then after that? We can just add UI elements like normal!
        ///
        UI.Image(logoSprite, new Vec2(22, 0) * Units.cm2m);

        UI.Toggle("Toggle", ref clipToggle);
        UI.HSlider("Slide", ref clipSlider, 0, 1, 0, 22 * Units.cm2m);
        ///
        /// And while we're at it, here's a quick example of doing a radio button group! Not much
        /// 'radio' actually happening, but it's still pretty simple. Pair it with an enum, or an
        /// integer, and have fun!
        ///
        if (UI.Radio("Radio 1", clipOption == 1))
        {
            clipOption = 1;
        }
        UI.SameLine();
        if (UI.Radio("Radio 2", clipOption == 2))
        {
            clipOption = 2;
        }
        UI.SameLine();
        if (UI.Radio("Radio 3", clipOption == 3))
        {
            clipOption = 3;
        }
        ///
        /// As with windows, Affordances need an End call.
        ///
        UI.AffordanceEnd();
        ///
        /// And there you go! That's how UI works in StereoKit, pretty simple, huh?
        /// For further reference, and more UI methods, check out the
        /// [UI class documentation]({{site.url}}/Pages/Reference/UI.html).
        ///
        /// If you'd like to see the complete code for this sample,
        /// [check it out on Github](https://github.com/maluoi/StereoKit/blob/master/Examples/StereoKitTest/DemoUI.cs)!
        /// :End:
    }
Пример #27
0
        public void Initialize()
        {
            /// :CodeDoc: Guides Using Hands
            /// ## Accessing Joints
            ///
            /// ![Hand with joints]({{site.url}}/img/screenshots/HandAxes.jpg)
            ///
            /// Since hands are so central to interaction, accessing hand information needs
            /// to be really easy to get! So here's how you might find the fingertip of the right
            /// hand! If you ignore IsTracked, this'll give you the last known position for that
            /// finger joint.
            Hand hand = Input.Hand(Handed.Right);

            if (hand.IsTracked)
            {
                Vec3 fingertip = hand[FingerId.Index, JointId.Tip].position;
            }
            /// Pretty straightforward! And if you prefer calling a function instead of using the
            /// [] operator, that's cool too! You can call `hand.Get(FingerId.Index, JointId.Tip)`
            /// instead!
            ///
            /// If that's too granular for you, there's easy ways to check for pinching and
            /// gripping! Pinched will tell you if a pinch is currently happening, JustPinched
            /// will tell you if it just started being pinched this frame, and JustUnpinched will
            /// tell you if the pinch just stopped this frame!
            if (hand.IsPinched)
            {
            }
            if (hand.IsJustPinched)
            {
            }
            if (hand.IsJustUnpinched)
            {
            }

            if (hand.IsGripped)
            {
            }
            if (hand.IsJustGripped)
            {
            }
            if (hand.IsJustUngripped)
            {
            }
            /// These are all convenience functions wrapping the `hand.pinchState` bit-flag, so you
            /// can also use that directly if you want to do some bit-flag wizardry!
            /// :End:

            /// :CodeSample: HandMenuRadial HandRadialLayer HandMenuItem
            /// ### Basic layered hand menu
            ///
            /// The HandMenuRadial is an `IStepper`, so it should be registered with
            /// `StereoKitApp.AddStepper` so it can run by itself! It's recommended to
            /// keep track of it anyway, so you can remove it when you're done with it
            /// via `StereoKitApp.RemoveStepper`
            ///
            /// The constructor uses a params style argument list that makes it easy and
            /// clean to provide lists of items! This means you can assemble the whole
            /// menu on a single 'line'. You can still pass arrays instead if you prefer
            /// that!
            handMenu = StereoKitApp.AddStepper(new HandMenuRadial(
                                                   new HandRadialLayer("Root",
                                                                       new HandMenuItem("File", null, null, "File"),
                                                                       new HandMenuItem("Edit", null, null, "Edit"),
                                                                       new HandMenuItem("About", null, () => Log.Info(StereoKitApp.VersionName)),
                                                                       new HandMenuItem("Cancel", null, null)),
                                                   new HandRadialLayer("File",
                                                                       new HandMenuItem("New", null, () => Log.Info("New")),
                                                                       new HandMenuItem("Open", null, () => Log.Info("Open")),
                                                                       new HandMenuItem("Close", null, () => Log.Info("Close")),
                                                                       new HandMenuItem("Back", null, null, HandMenuAction.Back)),
                                                   new HandRadialLayer("Edit",
                                                                       new HandMenuItem("Copy", null, () => Log.Info("Copy")),
                                                                       new HandMenuItem("Paste", null, () => Log.Info("Paste")),
                                                                       new HandMenuItem("Back", null, null, HandMenuAction.Back))));
            /// :End:

            Tests.Hand(new HandJoint[] { new HandJoint(new Vec3(-0.529f, -0.198f, -0.126f), new Quat(-0.744f, -0.530f, 0.156f, -0.376f), 0.004f), new HandJoint(new Vec3(-0.529f, -0.198f, -0.126f), new Quat(-0.744f, -0.530f, 0.156f, -0.376f), 0.010f), new HandJoint(new Vec3(-0.533f, -0.175f, -0.090f), new Quat(-0.786f, -0.550f, 0.126f, -0.254f), 0.009f), new HandJoint(new Vec3(-0.544f, -0.158f, -0.069f), new Quat(-0.729f, -0.564f, 0.027f, -0.387f), 0.008f), new HandJoint(new Vec3(-0.557f, -0.150f, -0.065f), new Quat(-0.585f, -0.548f, -0.140f, -0.582f), 0.006f), new HandJoint(new Vec3(-0.521f, -0.182f, -0.136f), new Quat(-0.277f, -0.826f, 0.317f, -0.376f), 0.004f), new HandJoint(new Vec3(-0.550f, -0.135f, -0.102f), new Quat(-0.277f, -0.826f, 0.317f, -0.376f), 0.009f), new HandJoint(new Vec3(-0.571f, -0.112f, -0.082f), new Quat(-0.244f, -0.843f, 0.256f, -0.404f), 0.008f), new HandJoint(new Vec3(-0.585f, -0.102f, -0.070f), new Quat(-0.200f, -0.866f, 0.165f, -0.428f), 0.007f), new HandJoint(new Vec3(-0.593f, -0.098f, -0.064f), new Quat(-0.172f, -0.874f, 0.110f, -0.440f), 0.005f), new HandJoint(new Vec3(-0.527f, -0.178f, -0.144f), new Quat(-0.185f, -0.817f, 0.370f, -0.401f), 0.004f), new HandJoint(new Vec3(-0.559f, -0.132f, -0.119f), new Quat(-0.185f, -0.817f, 0.370f, -0.401f), 0.009f), new HandJoint(new Vec3(-0.582f, -0.101f, -0.104f), new Quat(-0.175f, -0.809f, 0.371f, -0.420f), 0.008f), new HandJoint(new Vec3(-0.599f, -0.089f, -0.092f), new Quat(-0.109f, -0.856f, 0.245f, -0.443f), 0.007f), new HandJoint(new Vec3(-0.608f, -0.084f, -0.086f), new Quat(-0.075f, -0.871f, 0.180f, -0.450f), 0.005f), new HandJoint(new Vec3(-0.535f, -0.178f, -0.152f), new Quat(-0.132f, -0.786f, 0.408f, -0.445f), 0.003f), new HandJoint(new Vec3(-0.568f, -0.136f, -0.137f), new Quat(-0.132f, -0.786f, 0.408f, -0.445f), 0.008f), new HandJoint(new Vec3(-0.590f, -0.106f, -0.130f), new Quat(-0.131f, -0.762f, 0.432f, -0.464f), 0.007f), new HandJoint(new Vec3(-0.607f, -0.092f, -0.122f), new Quat(-0.071f, -0.810f, 0.332f, -0.477f), 0.006f), new HandJoint(new Vec3(-0.617f, -0.086f, -0.117f), new Quat(-0.029f, -0.836f, 0.260f, -0.482f), 0.004f), new HandJoint(new Vec3(-0.544f, -0.183f, -0.159f), new Quat(-0.060f, -0.749f, 0.481f, -0.452f), 0.003f), new HandJoint(new Vec3(-0.576f, -0.143f, -0.152f), new Quat(-0.060f, -0.749f, 0.481f, -0.452f), 0.007f), new HandJoint(new Vec3(-0.594f, -0.119f, -0.154f), new Quat(-0.061f, -0.684f, 0.534f, -0.493f), 0.006f), new HandJoint(new Vec3(-0.607f, -0.108f, -0.152f), new Quat(0.002f, -0.745f, 0.444f, -0.498f), 0.005f), new HandJoint(new Vec3(-0.616f, -0.102f, -0.150f), new Quat(0.045f, -0.780f, 0.378f, -0.496f), 0.004f), new HandJoint(new Vec3(-0.548f, -0.161f, -0.137f), new Quat(-0.267f, 0.849f, 0.204f, 0.407f), 0.000f), new HandJoint(new Vec3(-0.548f, -0.161f, -0.137f), new Quat(-0.267f, 0.849f, 0.204f, 0.407f), 0.000f) });
            Tests.Screenshot(600, 600, "HandAxes.jpg", new Vec3(-0.508f, -0.082f, -0.061f), new Vec3(-1.219f, -0.651f, -0.474f));
        }
Пример #28
0
 public void Shutdown()
 {
     /// :CodeSample: HandMenuRadial HandRadialLayer HandMenuItem
     StereoKitApp.RemoveStepper(handMenu);
     /// :End:
 }
Пример #29
0
        public void Initialize()
        {
            /// :CodeDoc: Guides Using Hands
            /// ## Accessing Joints
            ///
            /// Since hands are so central to interaction, accessing hand information needs
            /// to be really easy to get! So here's how you might find the fingertip of the right
            /// hand! If you ignore IsTracked, this'll give you the last known position for that
            /// finger joint.
            Hand hand = Input.Hand(Handed.Right);

            if (hand.IsTracked)
            {
                Vec3 fingertip = hand[FingerId.Index, JointId.Tip].position;
            }
            /// Pretty straightforward! And if you prefer calling a function instead of using the
            /// [] operator, that's cool too! You can call `hand.Get(FingerId.Index, JointId.Tip)`
            /// instead!
            ///
            /// If that's too granular for you, there's easy ways to check for pinching and
            /// gripping! Pinched will tell you if a pinch is currently happening, JustPinched
            /// will tell you if it just started being pinched this frame, and JustUnpinched will
            /// tell you if the pinch just stopped this frame!
            if (hand.IsPinched)
            {
            }
            if (hand.IsJustPinched)
            {
            }
            if (hand.IsJustUnpinched)
            {
            }

            if (hand.IsGripped)
            {
            }
            if (hand.IsJustGripped)
            {
            }
            if (hand.IsJustUngripped)
            {
            }
            /// These are all convenience functions wrapping the `hand.pinchState` bit-flag, so you
            /// can also use that directly if you want to do some bit-flag wizardry!
            /// :End:

            handMenu = StereoKitApp.AddStepper(new HandMenuRadial(
                                                   new HandRadialLayer("Root",
                                                                       new HandMenuItem("One", null, null, "One"),
                                                                       new HandMenuItem("Two", null, null, "Two"),
                                                                       new HandMenuItem("Three", null, null, "Three"),
                                                                       new HandMenuItem("Four", null, null, "Four"),
                                                                       new HandMenuItem("Cancel", null, null)),
                                                   new HandRadialLayer("One",
                                                                       new HandMenuItem("a", null, () => Log.Info("a")),
                                                                       new HandMenuItem("b", null, () => Log.Info("b")),
                                                                       new HandMenuItem("back", null, null, HandMenuAction.Back)),
                                                   new HandRadialLayer("Two",
                                                                       new HandMenuItem("c", null, () => Log.Info("c")),
                                                                       new HandMenuItem("back", null, null, HandMenuAction.Back)),
                                                   new HandRadialLayer("Three",
                                                                       new HandMenuItem("d", null, () => Log.Info("d")),
                                                                       new HandMenuItem("e", null, () => Log.Info("e")),
                                                                       new HandMenuItem("f", null, () => Log.Info("f")),
                                                                       new HandMenuItem("back", null, null, HandMenuAction.Back)),
                                                   new HandRadialLayer("Four",
                                                                       new HandMenuItem("g", null, () => Log.Info("g")),
                                                                       new HandMenuItem("h", null, () => Log.Info("h")),
                                                                       new HandMenuItem("i", null, () => Log.Info("i")),
                                                                       new HandMenuItem("j", null, () => Log.Info("j")),
                                                                       new HandMenuItem("back", null, null, HandMenuAction.Back))));
        }
Пример #30
0
    public void Update()
    {
        if (Demos.TestMode)
        {
            Renderer.Screenshot(new Vec3(-0.325f, -0.025f, .075f), new Vec3(-.4f, -0.075f, 0), 600, 400, "../../../docs/img/screenshots/GuideUserInterface.jpg");
        }

        /// :CodeDoc: Guides User Interface
        /// Then we'll move over to the application step where we'll do the rest of the UI code!
        ///
        /// We'll start with a window titled "Window" that's 20cm wide, and auto-resizes on the
        /// y-axis. The Units class is pretty helpful here, as it allows us to reason more visually
        /// about the units we're using! StereoKit uses meters as its base unit, which look a little
        /// awkward, especially in the millimeter range.
        ///
        /// We'll also use a toggle to turn the window's header on and off! The value from that toggle
        /// is passed in here via the showHeader field.
        UI.WindowBegin("Window", ref windowPose, new Vec2(20, 0) * Units.cm2m, showHeader);

        /// Here's that toggle button! You'll also notice our use of 'ref' values in a lot of the UI
        /// code. UI functions typically follow the pattern of returning true/false to indicate they've
        /// been interacted with during the frame, so you can nicely wrap them in 'if' statements to
        /// react to change!
        ///
        /// Then with the 'ref' parameter, we let you pass in the current state of the UI element. The UI
        /// element will update that value for you based on user interaction, but you can also change it
        /// yourself whenever you want to!
        UI.Toggle("Show Header", ref showHeader);

        /// Here's an example slider! We start off with a label element, and tell the UI to
        /// keep the next item on the same line. The slider clamps to the range [0,1], and
        /// will step at intervals of 0.2. If you want it to slide continuously, you can just set
        /// the `step` value to 0!
        UI.Label("Slide");
        UI.SameLine();
        UI.HSlider("slider", ref slider, 0, 1, 0.2f, 72 * Units.mm2m);

        /// Here's how you use a simple button! Just check it with an 'if'. Any UI method
        /// will return true on the frame when their value or state has changed.
        if (UI.ButtonRound("Exit"))
        {
            StereoKitApp.Quit();
        }

        /// And for every begin, there must also be an end! StereoKit will log errors when this
        /// occurs, so keep your eyes peeled for that!
        UI.WindowEnd();

        /// And there you go! That's how UI works in StereoKit, pretty simple, huh?
        /// For further reference, and more UI methods, check out the
        /// [UI class documentation]({{site.url}}/Pages/Reference/UI.html).
        ///
        /// If you'd like to see the complete code for this sample,
        /// [check it out on Github](https://github.com/maluoi/StereoKit/blob/master/Examples/StereoKitTest/DemoUI.cs)!
        /// :End:

        UI.AffordanceBegin("Clip", ref clipboardPose, new Vec3(-15, 20, 0) * Units.cm2m, new Vec3(30, 40, 5) * Units.cm2m, false);
        UI.LayoutArea(new Vec3(-12, 15, 0) * Units.cm2m, new Vec2(24, 30) * Units.cm2m);
        UI.Label("Application 'Settings'");
        UI.Toggle("Subtitles", ref subtitles); UI.SameLine();
        UI.Toggle("Butts", ref clipButts);
        UI.HSlider("Slide", ref clipSlider, 0, 1, 0, 22 * Units.cm2m);
        UI.ButtonRound("Press");
        UI.Button("Squeeze");
        UI.AffordanceEnd();
        clipboard.Draw(clipboardPose.ToMatrix());
    }