Allegro.cc Forums » Programming Questions » true isometric projection with opengl

 true isometric projection with opengl
 999999 Member #10,357 November 2008 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.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 Member #33 April 2000 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. [My site] [Tetrominoes]
 SiegeLord Member #7,827 October 2006 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. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]
 Indeterminatus Member #737 November 2000 SiegeLord said:I was told that touching the projection matrix is a bad idea. Could you elaborate on that? _______________________________Indeterminatus. [Atomic Butcher]si tacuisses, philosophus mansisses
 Tobias Dammers Member #2,604 August 2002 999999 said: I mean the true isometric projection, not the general orthogonal projection. 1. Set ortho projection2. Rotate the scene 45 degrees about the up axis3. Rotate the scene 60 degrees about the x axisThe 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. ---Me make music: Triofobie---"We need Tobias and his awesome trombone, too." - Johan Halmén
 Thomas Harte Member #33 April 2000 Indeterminatus said: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. [My site] [Tetrominoes]
 Tobias Dammers Member #2,604 August 2002 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. ---Me make music: Triofobie---"We need Tobias and his awesome trombone, too." - Johan Halmén
 tobing Member #5,213 November 2004 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 Member #33 April 2000 Tobias Dammers said: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"}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. [My site] [Tetrominoes]
 Tobias Dammers Member #2,604 August 2002 Hm, yes, lighting. That makes more sense. Still a good reason for using the projection matrix for just that, projection, and nothing else. ---Me make music: Triofobie---"We need Tobias and his awesome trombone, too." - Johan Halmén
 SiegeLord Member #7,827 October 2006 That sounds in line with what I remember being told. That must be what I have meant then. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]
 Thomas Harte Member #33 April 2000 Tobias Dammers said: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... [My site] [Tetrominoes]
 Go to: Allegro Development Installation, Setup & Configuration Allegro.cc Comments Off-Topic Ordeals The Depot Game Design & Concepts Programming Questions Recent Threads