OpenGL ModelView for head movement & scale.
I'm working with JOGL, JOVR, SDK based rendering.
In my OpenGL gl init method I added some pretty standard lighting. What I've found though is that the lighting of my scene adjusts as I move my head! Like using the rift isnt freaky enough already :)
I'm guessing that is because I am transforming the whole scene rather than the camera. I've done some OpenGL long ago using gluLookAt. But I was hoping to find a modern example of how to do this that I can play around with to understand. The only Rift style example I found, and that I have been trying to get working is below. I'm OpenGL 2.1 based btw.
My math is bad, and it's the sort of code I got working once a long time ago, and never touched again, so please be patient with me. I'm having a read of my RED book, and I get the impression I might need a two step approach. So that I apply a model transform, do all my drawing, and then apply the view transform?
Related to this issue. I tried to render just a floor underneath. I did a transform on the y axis based on eye height. Drew a flat plane (which I finally managed to texture, yay!) in the X and Z plane. Using the following code I can look around the scene fine, but if I lower my head slightly I can already see under the 'floor'.
So I saw a note about scene scale in the developers guide. My plan was that 1 unit in OpenGL would be 1 meter, which would tie nicely into eye height. Is that a sensible approach, and if so where am I going wrong please?
At least this exercise has made me realise why in my old projects my blender exports where always 90 deg rotated. I always pictured z as being up in my game world vs y which seems to be more of a standard. oops.
Any help / code :) much appreciated!
In my OpenGL gl init method I added some pretty standard lighting. What I've found though is that the lighting of my scene adjusts as I move my head! Like using the rift isnt freaky enough already :)
I'm guessing that is because I am transforming the whole scene rather than the camera. I've done some OpenGL long ago using gluLookAt. But I was hoping to find a modern example of how to do this that I can play around with to understand. The only Rift style example I found, and that I have been trying to get working is below. I'm OpenGL 2.1 based btw.
My math is bad, and it's the sort of code I got working once a long time ago, and never touched again, so please be patient with me. I'm having a read of my RED book, and I get the impression I might need a two step approach. So that I apply a model transform, do all my drawing, and then apply the view transform?
Related to this issue. I tried to render just a floor underneath. I did a transform on the y axis based on eye height. Drew a flat plane (which I finally managed to texture, yay!) in the X and Z plane. Using the following code I can look around the scene fine, but if I lower my head slightly I can already see under the 'floor'.
So I saw a note about scene scale in the developers guide. My plan was that 1 unit in OpenGL would be 1 meter, which would tie nicely into eye height. Is that a sensible approach, and if so where am I going wrong please?
At least this exercise has made me realise why in my old projects my blender exports where always 90 deg rotated. I always pictured z as being up in my game world vs y which seems to be more of a standard. oops.
Any help / code :) much appreciated!
MatrixStack.PROJECTION.set(projections[eye]);
eyeRenderPose[eye].Orientation = pose[eye].Orientation;
eyeRenderPose[eye].Position = pose[eye].Position;
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, fboIds[eye]);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
//draw HUD here?
MatrixStack mv = MatrixStack.MODELVIEW;
mv.push();
{
mv.preTranslate(RiftUtils.toVector3f(eyeRenderPose[eye].Position).mult(-1));
mv.preRotate(RiftUtils.toQuaternion(eyeRenderPose[eye].Orientation).inverse());
mv.preTranslate(RiftUtils.toVector3f(eyeRenderDescs[eye].ViewAdjust));
mv.translate(new Vector3f(0, eyeHeight, 0 )).scale(ipd);
FloatBuffer mvBuffer = ByteBuffer.allocateDirect(16*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
MatrixStack.MODELVIEW.top().fillFloatBuffer(mvBuffer, true);
mvBuffer.rewind();
gl.glLoadMatrixf(mvBuffer);
// translate on the y axis -eyeHeight
//draw floor
// translate on the y axis +eyeHeight
//draw cube
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0);
}
mv.pop();
