Oblique projection

Hello!

I’ve been trying to draw my scene using cabinet projection. Though I was able to get something resembling the desired result, it has become pretty clear that I’m doing something wrong. For this reason, I decided to start from scratch, and this time ask people who actually know what they’re doing first. :slight_smile:

How exactly do I implement cabinet projection using OpenGL? I’m working with Java and LWJGL.

Did your try loading this transformation matrix as the GL projection matrix ?
http://en.wikipedia.org/wiki/Oblique_projection#Cabinet_projection
Make sure the object is facing the camera, and it should be ok.

Thanks for the quick reply!

My primary talent is as an artist, and as a mathematician I’m completely inept. Sorry in advance for the stupidity that will no doubt follow. :stuck_out_tongue:

My matrix looks like this (it’s a double array):

1, 0, 0.5*Math.cos(45), 0,
0, 1, 0.5*Math.sin(45), 0,
0, 0, 0,                0,
0, 0, 0,                1

Then in my render method, I do this:

GL11.glMatrixMode(GL11.GL_PROJECTION);
DoubleBuffer mat = BufferUtils.createDoubleBuffer(16);
mat.put(Useful.m).flip();
GL11.glLoadMatrix(mat);

The problem is, there’s a lot of what appears to be z-fighting. I think this makes sense, because that matrix I loaded pretty much gets rid of depth entirely, right? As soon as I set the number at 3,3 to 1, for instance, everything disappears, though.

The image appears too wide, but I guess that’s because the projection matrix doesn’t take the window’s dimensions into account or something? I really don’t know, I’m doing way more guesswork here than I’d like. :S

What am I doing wrong?

EDIT: I somehow forgot to mention that the scene doesn’t resemble cabinet projection at all.

I gave it a go, and in fact this oblique matrix should be applied on top of a standard glOrtho projection.
I added two missing 1.0s in the diagonal so that it will not delete depth information, I had to transpose the matrix too (OpenGL convention), and it worked :


// C code
glMatrixMode(GL_PROJECTION);
glOrtho(-10,10,-10,10,-10,10); // to see a scene inside a cube centered on origin and 20 units wide
GLdouble projOblique[] =
{1.0, 0.0, 0.0, 0.0,
 0.0, 1.0, 0.0, 0.0,
 -.5, -.5, 1.0, 0.0,
 0.0, 0.0, 0.0, 1.0};
glMultMatrixd(projOblique);

// draw here in oblique projection

This thread helped, even if not that good :
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=235384

Thanks ZbuffeR. I actually read through that thread and managed to get a pretty terrible oblique projection going before posting this thread. I’ll give your code a try as soon as possible. :slight_smile:

EDIT: Works beautifully. Thank you very much! :smiley: