Git Product home page Git Product logo

Comments (3)

Abdul-Mukit avatar Abdul-Mukit commented on May 23, 2024 1

Thank you very much for the comment. That motivated me to test my understanding of StereoKit again.

I did some very simple tests. Only SK.Input-based rendering works with Psi without pushing world hierarchy or inheriting from StereoKitRenderer. I have figured out why we couldn't render things with Input.Head.Forward while using Psi. It has nothing to do with Psi. Our understanding of Input.Head.Forward was incorrect.

Input.Head.Forward (or Pose.Forward) only calculates the direction vector. It doesn't provide the actual location wrt to head position in that forward direction. The direction is always calculated wrt to (0,0,0) and the direction vector's values are always bound between -1 to 1. Checking Input.Head.Forward, I saw that the values always stayed in the -1 to 1 range no matter where I stood in the room.
So when we were trying to display a menu using:
_menuPose = new Pose(Input.Head.Forward, Quat.LookAt(Input.Head.Forward, Input.Head.position));

It didn't work once we walked away wearing the headset from the initial position where we started the app. The reason it worked if we didn't walk away was that the (0,0,0) of SK basis was initialized at the initial position where the device was. Psi also mentions this in the documentation.

The correct solution is:
_menuPose = new Pose(Input.Head.position + Input.Head.Forward, Quat.LookAt(Input.Head.position + Input.Head.Forward, Input.Head.position));

As a result, we don't need the PsiInput.Head or WordHiarchy anymore. We can directly render simple stuff using pure SK even if we had initialized Psi's MixedReality.InitializeAsync().
I tried this out on today and it worked. The following is a simple code snipped that I tried.

internal class Program
    {
        static void Main(string[] args)
        {
            // Initialize StereoKit
            SKSettings settings = new SKSettings
            {
                appName = "StereoKitPsiMenuRendering",
                assetsFolder = "Assets",
            };
            if (!SK.Initialize(settings))
                Environment.Exit(1);

            MixedReality.InitializeAsync().GetAwaiter().GetResult(); // Initialize Psi MixedReality statics

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

            Pose menuPose = new Pose(Input.Head.Forward, Quat.LookAt(Input.Head.Forward, Input.Head.position));
            
            // Core application loop
            while (SK.Step(() =>
            {
                if (SK.System.displayType == Display.Opaque)
                    Default.MeshCube.Draw(floorMaterial, floorTransform);

                //Lines.AddAxis(new Pose(Input.Head.Forward, Quat.Identity) , 0.2f);  // Uncomment to see the problem
                Lines.AddAxis(new Pose(Input.Head.position + Input.Head.Forward, Quat.Identity) , 0.1f);
                Lines.AddAxis(Pose.Identity, 0.1f);
                

                UI.WindowBegin("Input.Head.Forward", ref menuPose);
                UI.Label($"Head: {Input.Head.position.ToString()}");
                UI.Label($"Head forward: {Input.Head.Forward.ToString()}");
                UI.WindowEnd();

            })) ;
            SK.Shutdown();
        }
    }

from psi.

sandrist avatar sandrist commented on May 23, 2024

We could consider opening up some of these APIs to be public, but I'd like to understand a bit better what you'd like to achieve. A couple points given what you described:

  1. It should still be possible to do pure StereoKit input and rendering, even if you are using Psi as well. Positioning a UI menu using StereoKit.Input.Head.Forward and Quat.LookAt should work as normal if you do not want to use a Psi renderer component. Does this seem to not be true for you?
  2. The PsiInput.Head CoordinateSystem uses its XAxis as "Forward". Does that help?

In general, PsiInput simply gets you the StereoKit inputs in the Psi "world". If you would like to compute StereoKit things, you should simply use the StereoKit inputs. There shouldn't be a reason to convert StereoKit -> Psi -> back to StereoKit, unless I'm missing something.

from psi.

sandrist avatar sandrist commented on May 23, 2024

Great, glad you got it working! I'll mark this issue as closed for now, but feel free to open it back up if you have any follow-up questions.

from psi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.