Forum Discussion
CaliberMengsk
13 years agoExplorer
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.
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
- CapyvaraExplorerI believe you can use the Unity integration to get a proper C# wrapper.
- CaliberMengskExplorerThat may work! Thanks for the suggestion!
- CaliberMengskExplorerNope. Nevermind, OculusPlugin.dll is not valid for C#. When adding it as a reference, it says it's not a valid assembly or com component. So that's a no go.
- kingtutHonored GuestIt wouldn't be hard to do - but what would you like the API to look like? For example, having a 1:1 mapping of C++ to C# would be a lot of work. If you only wanted a small number of specific events/methods/classes then that would likely be easier.
I've no time to do this myself (and no OR to test on) yet - but C# is my preferred language so would likely end up doing it at some point.
All you need to do is in Visual Studio create a C# classlibrary, add the oculus dll as a reference, and then DllImport(). See http://msdn.microsoft.com/en-us/library ... 68(v=vs.71).aspx for more information. - EntroperHonored GuestYou can dllimport C functions (as static C# methods), but not a C++ class.
When I have a Rift (hopefully quite soon, order fifteen-hundred-and-something), I do plan to investigate this. There are a number of steps to even determine how much effort is required, though. - ChargeExplorerHave you looked at Swig (www.swig.org). It's very good at wrapping C, but C++ is also supported. I've not looked into this at all for the Rift dev kit yet - still waiting for mine to arrive, but we use SWIG to wrap into python and C# at work for our API (admittedly C)
- newvetHonored GuestI think the recommended way to write a c# wrapper is c++/cli. I tried to initialize the sdk and let it write some log messages to Diagnostics.Trace. It worked pretty well. At the moment i have no device to get some true values from the sdk, but as soon as one arrives i will continue my efforts.
- EntroperHonored Guest
"newvet" wrote:
I think the recommended way to write a c# wrapper is c++/cli. I tried to initialize the sdk and let it write some log messages to Diagnostics.Trace. It worked pretty well. At the moment i have no device to get some true values from the sdk, but as soon as one arrives i will continue my efforts.
Yeah, you can make a C++/CLI class with a pointer to the real C++ class, and wrap all the methods individually. It's just a heck of a lot of boilerplate to set it up. - EntroperHonored Guest
"Entroper" wrote:
Yeah, you can make a C++/CLI class with a pointer to the real C++ class, and wrap all the methods individually. It's just a heck of a lot of boilerplate to set it up.
So I got home and had another look at the SDK code, and I have to agree with this thread. There's a lot of structure here that I don't think I'm interested in duplicating or wrapping in C#. I'm saying it's not useful or that it's poorly designed, but it definitely isn't suited to making this an easy port.
I have gotten a look at the core functionality, i.e. enumerating devices and getting the K-values and stuff, and I think it may be within my free time budget to try and get that done in C#. Those appear to be just Win32 calls. - CaliberMengskExplorerYeah, 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)
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago
- 13 years ago
- 13 years ago