Skip to main content
Up and Coming
April 2, 2013

C# Wrapper?

So after looking through the SDK a bit, it seems everything is C++ based. While that's all fine and dandy for being the more efficient language, it's much more complex then I am use to working with, and is a lot harder to follow. I have very little experience with C++ and while I know about wrappers (a way for something like c# to call functions from a C++ script and get data back) I don't have a clue how to make them myself.

Is there a wrapper for c# already made, and if not, can someone either make one, or at least tell me where I can get started on writing my own?

I'm currently going to be writing a c# interface with unity that will be able to take data from my own vr glove thing to unity (already can send/receive data to/from unity), and I could build on top of that support for the oculus with the free version of unity. The only thing I wouldn't be able to do is distort the image properly for video, but could be a simple way to get the oculus' data.

I should also note that I don't have an oculus yet (waiting for it to be shipped since november T_T) so I can't test anything until mine comes in.

Anyway, any help with this would be much appreciated.

    25 replies

    Up and Coming
    April 3, 2013
    "CaliberMengsk" wrote:
    Yeah, at the moment, all that's really needed is yaw, pitch, and roll. It wouldn't be a perfect implementation as you wouldn't have any of the predictive stuff, but that can be done internally in the software as well. It'd just be nice to not have to have Unity pro, since I don't have $1.5k to spend on it. (and probably won't for a very long time T_T)


    Well, the sensor fusion stuff isn't that much code, it's probably portable. :) No need for me to re-implement threads and mutexes though.
    New Participant
    April 3, 2013
    After a quick look at the project from the SDK, it seems to me that the way forward would be to use something like this :

    http://www.developerfusion.com/article/84338/making-usb-c-friendly/

    to get the HID device then just implement the code in OVR_Wind32_HMDDevice and OVR_Win32_Sensor.
    Up and Coming
    April 4, 2013
    How is Unity Pro supporting the Oculus? Last I checked Unity supports JavaScript, C# but I don't believe it supports C++ so if it will have Oculus support they likely already managed the C# wrapper.
    Up and Coming
    April 4, 2013
    See this post for a Unity sample ...

    viewtopic.php?f=37&t=204
    Up and Coming
    April 4, 2013
    "Sularus" wrote:
    After a quick look at the project from the SDK, it seems to me that the way forward would be to use something like this :

    http://www.developerfusion.com/article/84338/making-usb-c-friendly/

    to get the HID device then just implement the code in OVR_Wind32_HMDDevice and OVR_Win32_Sensor.


    I found this on github: https://github.com/mikeobrien/HidLibrar ... Methods.cs

    Which imports the native HID interface into C#. I'll need to do something similar to import the GDI stuff (enumerating displays). Unless someone knows of another library that's already done it. :)
    Up and Coming
    April 4, 2013
    So, it doesn't do anything yet other than enumerate HID and Display devices, but here's the project so far. I can run the console app in the debugger and hover over the device lists, and they appear to contain descriptions of my devices. :)
    Up and Coming
    April 4, 2013
    Thanks for all the help Entroper. I would help, but like I said, I know practically nothing about c++, and even less about making a wrapper. I'll just work on the other end, the program to transfer data back and forth. Hopefully we can get this up and running soon. T_T Just sad I can't test it until I get my rift XD.
    Current Project: Virtual Reality Glove project
    Up and Coming
    April 5, 2013
    Alright, I got the necessary Win32 calls marshaled over. I should be able to start building HMDDevice descriptions next. I don't know that I'm going to follow the factory/visitor pattern that they used; it seems so much easier to make an IEnumerable. :)
    Up and Coming
    April 8, 2013
    The plus is, this is for us. :P So make it however you would like. Personally, I've been reading that a fair amount of people don't like how the rift outputs data. If we find a better way to do it that more people like, then they can implement it in the sdk so everyone can use it easier.

    Did you happen to get any farther with it over the weekend? I got the pipeline system working pretty good at this point. I need to do a few error checks on the c# end, and I also need to do some force stops on the unity end. (It's not stopping the thread when you hit the play button to stop the game, so when you start the game a second time, unity freezes. Don't know how easy this will be to fix. May have to somehow use the C# program to somehow force close the thread somehow.)

    It sends data extremely fast on my system. I was getting around 7,500 data sends per second when not screen recording. While screen recording, I was still getting over 5,000 data sends per second, so pretty darn fast since generally speaking we only really "need" 60 or so. Unity is working a lot better with threading then I thought it would. A few quirks (like not stopping the thread on close) but meh.

    I'm hoping this ends up working like I intend it to, and works fast enough to actually use. Getting unity to work with it for free, even in a jenky hacky way still let's people not have to buy the $1500 to get pro. (mainly effecting me, as I don't have the money even if I wanted, and just "figured" that the rift would just work like a joystick or something, not require a full sdk built specifically for each different game and engine. Just doesn't seem that... useable from a developer standpoint as it is.)
    Current Project: Virtual Reality Glove project
    Up and Coming
    April 9, 2013
    Nah, I've been holding off working on it until my Rift arrives. Should be tomorrow. I'm also kicking around ideas of what I want to do with it once I have it ported over. I have an itch for something using either vector (wireframe) graphics or flat-shaded polygons, as a throwback to some of the first 3D games from 20 years ago.