Oculus Rift Support

@cristianvillalba said: Hey monkeys! Sorry that I didn't properly introduce myself. I'm from Argentina and I'm actually playing a little bit with the Oculus VR.

You are amazing! =D

I download the code and try and found that I had the same problem that someone here has: I couldn’t get the splitted display (both images were on top of each other).

I was debugging a little bit to find out that I think it has to do with the material definition. I guess is related with the shader version.

I changed “BarrelDistortion.j3md” a bit:

and now It’s working!

Hope this help someone,

Regards,

Thanks!
I’ll make sure to update the repo.

Sorry I forgot to mention that I also created the barreldistortion15.frag file:
[java]
#import “Common/ShaderLib/MultiSample.glsllib”

uniform COLORTEXTURE m_Texture;
in vec2 texCoord;

uniform vec2 m_LensCenter;
uniform vec2 m_ScreenCenter;
uniform vec2 m_Scale;
uniform vec2 m_ScaleIn;
uniform vec4 m_HmdWarpParam;

vec2 HmdWarp(vec2 texIn){
vec2 theta = (texIn - m_LensCenter) * m_ScaleIn;
float rSq= theta.x * theta.x + theta.y * theta.y;
vec2 theta1 = theta * (m_HmdWarpParam.x + m_HmdWarpParam.y * rSq +
m_HmdWarpParam.z * rSq * rSq + m_HmdWarpParam.w * rSq * rSq * rSq);
return m_LensCenter + m_Scale * theta1;
}

void main(){
vec2 tc = HmdWarp(texCoord);
if (any(notEqual(clamp(tc, m_ScreenCenter-vec2(0.5,0.5), m_ScreenCenter+vec2(0.5, 0.5)) - tc, vec2(0.0, 0.0)))){
discard;
}
else{
gl_FragColor = texture2D(m_Texture, tc);
}
//gl_FragColor = texture2D(m_Texture, texCoord);
}
[/java]

Hey All,

First off I have to say that this project is awesome. I’m currently working with a group of friends at my university on research with the Oculus Rift and this project has helped us tremendously so far. We do have a question though that we can’t seem to solve as we’re not that familiar with the JMonkeyEngine.

Essentially we are trying to set a static background image to the scene, and we’re attempting to use a previewport as seen here: http://hub.jmonkeyengine.org/forum/topic/setting-a-stationary-background-image-in-jme3/

However, when we use the barreldistortion material, it is overlaying on top of this image, and we assume that even if we got this to work that the material wouldn’t actually be warped correctly for the Oculus Rift.

Can any of you point us in the right direction on where to go with this? Again all we’re looking to do is have the scene actually appear in front of a (dynamic) background image and it be properly distorted for the OR.

Thanks!

@twisterxiz said: Hey All,

First off I have to say that this project is awesome. I’m currently working with a group of friends at my university on research with the Oculus Rift and this project has helped us tremendously so far. We do have a question though that we can’t seem to solve as we’re not that familiar with the JMonkeyEngine.

Essentially we are trying to set a static background image to the scene, and we’re attempting to use a previewport as seen here: http://hub.jmonkeyengine.org/forum/topic/setting-a-stationary-background-image-in-jme3/

However, when we use the barreldistortion material, it is overlaying on top of this image, and we assume that even if we got this to work that the material wouldn’t actually be warped correctly for the Oculus Rift.

Can any of you point us in the right direction on where to go with this? Again all we’re looking to do is have the scene actually appear in front of a (dynamic) background image and it be properly distorted for the OR.

Thanks!

Hi.

I’m not sure a previewport would be the best option (or rather, i can’t guarantee compatibility). In general i had some problems with some of the post filters too. I made some work arounds but i don’t think i ever got around to checking them in?

Anyway.

I know that skyboxes work fine, and they’re sort of “static”.
My suggestion is, if you can’t use a skybox, to;
make a quad,
apply the texture,
place it in front of the camera (not necessarily far away),
and make sure it’s in the Sky bucket (Spatial.setQueueBucket(RenderQueue.Bucket.Sky);

This way it should always be rendered first, and stay inside the scene where the distortion would be applied correctly.

Hope it works!

@ljugtomten said:

Unfortunately I’m getting:

java.lang.Exception: Oculus Rift could not be initialized
at oculusvr.input.OculusRiftReader.<init>(OculusRiftReader.java:36)
at oculusvr.TestOculus.simpleInitApp(TestOculus.java:41)

…when trying to run one of the examples. Is that the same init problem you where experiencing? Any progress on that?

/Henrik

Did either of you guys ever solve this? I am getting the same error, both on a Windows XP 32-bit machine and a Windows 8.1 64-bit one.

@ryan.gilbert said: Did either of you guys ever solve this? I am getting the same error, both on a Windows XP 32-bit machine and a Windows 8.1 64-bit one.

Actually, no. I realized i’m facing the same problem when using the libs outside my oculus rift project. Do you get it if you check out the source as well?
I think it must have to do with the classpath, or in combination with the generated libs. Any help on the subject is appreciated.

I have been testing with my own code and your code. I actually built the Oculus dll myself because I was running into issues with yours, and have come through numerous problems to get to this. Could you provide the C++ code that you are using for the dll so I could compare that as well?

@ryan.gilbert said: I have been testing with my own code and your code. I actually built the Oculus dll myself because I was running into issues with yours, and have come through numerous problems to get to this. Could you provide the C++ code that you are using for the dll so I could compare that as well?

Checked in under “cpp”. I’m leaning more towards the project setup, but i could be wrong.

See, when I used your code, I got a different error.

java.lang.UnsatisfiedLinkError: Invalid access to memory location

I figured out that the problem was coming from the fact that FusionResult was not declared as a pointer, as it was in the MinimalOculus Demo. There also was no declaration for FusionResult. Here’s what is in the MinimalOculus tutorial:

SensorFusion* pFusionResult;

and in Init():

pFusionResult = new SensorFusion();

Changing FusionResult to a pointer results in changes where it is used:

FusionResult->AttachToSensor(pSensor);

Vector3f acc=FusionResult->GetAcceleration();

FusionResult->GetOrientation().GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&data[2], &data[1], &data[0]);

With these changes, I can now get your TestOculus demo running and it seems to be getting tracking data, but I still get the error in my own code.

1 Like

I solved my issue. Though I’m not sure that I fully understand how. I reworked the code so that it would initialize the Oculus during the main function of my starting class, and then passed that to the StereoCamAppState, and now it initializes properly. My guess is that the issue has something to do with how jMonkey and Oculus interact with threads… but beyond that I’m clueless. I’d love to hear about if you figure out why this happens and manage to work it out.

@ryan.gilbert said: I solved my issue. Though I'm not sure that I fully understand how. I reworked the code so that it would initialize the Oculus during the main function of my starting class, and then passed that to the StereoCamAppState, and now it initializes properly. My guess is that the issue has something to do with how jMonkey and Oculus interact with threads.. but beyond that I'm clueless. I'd love to hear about if you figure out why this happens and manage to work it out.

That sounds like the problem i had when not statically linking the libraries in visual studio. Does that make sense? If not, i can dig up my project (it’s on another machine) and look for a description of how to do it. It might also be described earlier in this thread.

Edit: Oh, and your previous post looks interesting, although i thought i had followed the MinimalOculus example precisely. I have to check that out.

I read through this whole thread and followed the tutorial on the Oculus site for setting up my project, and I thought I had followed everything properly. I’ll admit, I’m not entirely sure what you mean by statically linking the libraries, but I’m willing to try stuff out. Either way, I have it working perfectly now, I just had to alter your code a little bit and its probably not the cleanest way it could be done, but its working

Updated the c++ code with your suggestions (actually i went to the tutorial to check). I may have missed the declaration, but the pointer stuff must be new since i wrote it. I’m not too well-versed with c++, so i just copy the code :stuck_out_tongue:
Tried building with the latest SDK but now i seem to get the same issue as you.

Dug into this a bit more. No solution yet, but i’m pretty sure it has to do with threading.
Initializing the jni object outside of the application (in a static context) seems to work.
A hint is that the c++ initialize method returns false, but doesn’t actually output anything until the application has stopped.

Thanks a lot for making your code available, this is really fun! I have one question though. When I added the StereoCamAppState class, my game could no longer move the camera around. I’m using a CameraNode attached to a playerNode. How am I supposed to move the stereo camera? Am I missing something here?

Edit: Sorry, I just found the answer to my question in the TestStereoCams class. Still, pretty frustrated after fiddling with this problem for a couple of days.

I’ll hijack this thread for another Oculus market penetration guesswork thing:
They just got their funding sixtupled by Andreesen Horowitz (Co-Founder of Netscape, investor in Twitter and Skype).
Current main goal: get the thing to work flawlessly on all platforms (Windows, Linux, Mac, Android).

Looks like they’re on the path to making the Rift mass-marketable.
Which is good for everybody working on integrating it, because that just increased the chances of reaping rewards for that work.

(Source: http://www.gamestar.de/hardware/tft-monitore/oculus-rift/oculus_rift,584,3031074.html , Google might find English and/or more in-depth articles.)

Hey all,

Sorry for not responding to the question we had a while back. We ended up solving the issue by using a billboard control that was manually placed in front of the camera on every update.

Here is our semi-completed research: http://www.youtube.com/watch?v=E2oLsSSCZ4A

Essentially what we have done is use the Kinect to feed video and depth data through the jmonkey engine, which is displayed back out to users. Then we can do things such as enable night vision mode, use basic physics for bouncing objects/lasers, and can simulate color-blindness. There is a ton more of work to be done on this, but it’s just a quick demo video.

Long overdue update with OVR 0.2.5c support.
Major refactoring of the OculusRift object to static.
Support for many filter types.
One gotcha with this update is that you also need to initialize the Oculus in a new way.
[java]public static void main(String[] args) {
OculusRiftReader.initialize();
MyApp app = new MyApp();
app.start();
}[/java]
It has to be called before the application, or it won’t work. Still trying to find out why this is, since i’m using other JNI based peripherals with jme3 without having to resort to this.

Cheers,
Rickard

My knee-jerk reaction: “Oh my god static!” … followed by the realization that I don’t know how the software works so there.

So, here’s my question: Will this still support scenarios where multiple Rift displays are connected to one computer?
I guess the native library itself would need to be represented by a single, static object alright, but it would be nice if there were a separate, nonstatic object per Rift display connected to the computer (assuming the native lib can handle more than one Rift display, that is).

My knee-jerk reaction: “Oh my god static!”

Common reaction :slight_smile:

However, as you suggest, the native lib only supports one rift, which I realized when reading up on it a bit. I made it as an experiment to try to solve the problem I had, and it made some things easier. It’s also the way the Razer Hydra java lib i use did it, so I thought it was worth a shot.