PDA

View Full Version : Oblique projection

novitas
06-19-2011, 10:44 AM
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. :)

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

ZbuffeR
06-19-2011, 11:20 AM
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.

novitas
06-19-2011, 02:38 PM
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. :P

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();

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.

ZbuffeR
06-21-2011, 03:41 AM
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 :