Giter VIP home page Giter VIP logo

openvr.net's Introduction

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.

openvr.net's People

Contributors

flutterish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

openvr.net's Issues

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.