Exemple #1
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();
        }
Exemple #2
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);
 }
Exemple #3
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);
 }
Exemple #4
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));
        }
Exemple #5
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))));
        }
Exemple #6
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:

            /// :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:
        }