true isometric projection with opengl
999999

Hello,

I am a newbie in OpenGL programming and not very good at mathematics. Is there a simple way to have isometric projection?

I mean the true isometric projection, not the general orthogonal projection.

(http://en.wikipedia.org/wiki/Isometric_projection)

Isometric projection happens only when projections of unit X, Y and Z vectors are equally long and angles between them are exactly 120 degrees.

(Also this is kind of a follow up for the thread: http://www.allegro.cc/forums/thread/592722)

Code snippets are highly appreciated..

Thanks in advance..

Thomas Harte

Definitely possible. It'll be a job of twizzling the projection matrix after you've set up whatever you'd like as an orthogonal projection (for example, to set up what proportion of the screen 1 unit is), then something like:

#SelectExpand
1GLfloat isoMatrix[16] = 2{ 3 sinf(2*M_PI/3), cosf(2*M_PI/3), 0, 0, 4 sinf(4*M_PI/3), cosf(4*M_PI/3), 0, 0, 5 0, 1, 1, 0, 6 0, 0, 0, 1 7}; 8 9isoMatrix[0] = 10 11glMatrixMode(GL_PROJECTION); 12glMultMatrixf(isoMatrix); 13 14glMatrixMode(GL_MODELVIEW); 15...

Might not be right, but is intended to map the x axis to an angle 1/3 of the way around a circle, the y axis to an angle 2/3 of the way around a circle and the z axis to straight up, with 'distance' preserved (but still ignored) so that depth buffering works. This is really dashed off very quickly, without much thought at all. I'm sure someone smarter or with time to actually fire up a compiler will be able to fix it up almost immediately.

SiegeLord

Err... why not just use a camera matrix to apply those rotations to the model matrix while using standard orthogonal projection? I was told that touching the projection matrix is a bad idea.

Indeterminatus
SiegeLord said:

I was told that touching the projection matrix is a bad idea.

Could you elaborate on that?

Tobias Dammers
999999 said:

I mean the true isometric projection, not the general orthogonal projection.

1. Set ortho projection
2. Rotate the scene 45 degrees about the up axis
3. Rotate the scene 60 degrees about the x axis

The actual angles are a wild guess, so you might have to check them... the 45 degrees should be correct though.
If axis orientations don't match with what you want, you need to throw in the appropriate 90 or 180 degree rotations.

Thomas Harte

Could you elaborate on that?

Yep, same question from me. The request is to set up a particular type of projection — I can't see any reason why it would be a bad idea to put it on the projection stack, since that's what it's there for.

Quite probably my maths is broken though; I'm free this evening so will try to fix it then.

Tobias Dammers

I'm not exactly sure, but I think some implementations may rely on certain characteristics (axis orientation and such) of the projection transform in order to correctly do things like clipping, z-buffering, etc.

tobing

I had played with this some time ago, seems that glOrtho does what you need: It sets up an orthogonal projection, which gives you the isometric view of your choice.

Thomas Harte

I'm not exactly sure, but I think some implementations may rely on certain characteristics (axis orientation and such) of the projection transform in order to correctly do things like clipping, z-buffering, etc.

I don't think that is compatible with the OpenGL specification, which provides this diagram of the transform pipeline:

{"name":"img55.gif","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/8\/584dba8bc5248e49c8f723667da994e0.gif","w":519,"h":217,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/8\/584dba8bc5248e49c8f723667da994e0"}img55.gif

Per the spec:

Quote:

Figure 2.6 diagrams the sequence of transformations that are applied to vertices. The vertex coordinates that are presented to the GL are termed object coordinates. The model-view matrix is applied to these coordinates to yield eye coordinates. Then another matrix, called the projection matrix, is applied to eye coordinates to yield clip coordinates. A perspective division is carried out on clip coordinates to yield normalized device coordinates. A final viewport transformation is applied to convert these coordinates into window coordinates.

Obviously if you collapse the z coordinates down to a single point then z-buffering isn't going to work, but it should be impossible to break clipping. It's just one more matrix stage. The main functional reason that modelview and projection are separate is that the lighting model includes specular lighting, which is a function of light position, object position and camera position — so the latter two need to be distinguishable.

Tobias Dammers

Hm, yes, lighting. That makes more sense. Still a good reason for using the projection matrix for just that, projection, and nothing else.

SiegeLord

That sounds in line with what I remember being told. That must be what I have meant then.

Thomas Harte

Still a good reason for using the projection matrix for just that, projection, and nothing else.

But this is using it for projection. Modelview to align objects with each other and with the camera, projection to map from the camera to the screen.

It's all slightly academic if the code I posted doesn't work however — must check that out...

Thread #600737. Printed from Allegro.cc