Skip to content

A thin C# object-oriented wrapper around openxr using Valve openvr implementation

License

Notifications You must be signed in to change notification settings

Flutterish/OpenVR.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenVR.NET

OpenVR.NET is a set of C# bindings to openxr via the Valve openvr implementation. It encapsulates openvr in an object-oriented and event driven way. This is a library, not a framework, if you wish to incorporate it into your project, you will need to call the "heartbeat" methods of OpenVR.NET yourself.

This project was originally a part of osu!xr (a VR port of osu!lazer), but I deemed it useful for other creators, and as such it was split into its own thing.

OpenVR.NET currently allows you to render to VR, set the VR manifest at runtime and handle inputV2 as well as legacy input.

Using OpenVR.NET is as simple as this:

// init
VR VR = new();
VR.DeviceDetected += device => { ... };
VR.TryStart();
VR.InstallApp( new VrManifest { ... } );
VR.SetActionManifest( new ActionManifest<GameAction, ActionCategory> { ... } );
...
// loop ( the 3 update methods can and should run on separate threads! )
VR.UpdateInput();
VR.Update();
var drawContext = VR.UpdateDraw();

if ( drawContext != null ) {
    var projectionMatrix = drawContext.GetProjectionMatrix( EVREye.Eye_Left, 0.01f, 1000f ) 
        * drawContext.GetEyeToHeadMatrix( EVREye.Eye_Left ).Inverted()
        * ( Matrix4x4.FromQuaternion( VR.Headset.RenderRotation ) * Matrix4x4.Translate( VR.Headset.RenderPosition ) ).Inverted();
    drawScene( projectionMatrix, drawContext.Resolution );
    drawContext.SubmitFrame( EVREye.Eye_Left, new() { eType = ..., handle = ... } );
    // repeat for right eye
}

Additional sample code, implemented with OpenTK (OpenGL) can be found in the VisualTests project. Notice how the coordinate system and matrix operations could need to be done in reverse order. OpenVR.NET uses a left handed coordinate system and System.Numerics to represent matrices.

About

A thin C# object-oriented wrapper around openxr using Valve openvr implementation

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages