projection matrix, modelview matrix, and ortho view
Could someone explain to me projection matrix, modelview, and ortho view? It''s all so confusing and I''ve read alot of the tutorials on the website and cant seem to find where they are explained.
Also, could someone explain what the following functions do?
glMatrixMode
glPushMatrix
glPopMatrix
glOrtho
glTranslated
thanks
quote:
Original post by murdoth99
Could someone explain to me projection matrix, modelview, and ortho view? It''s all so confusing and I''ve read alot of the tutorials on the website and cant seem to find where they are explained.
ok, first, projection matrix is the view most people use for 3D games, because it is just like viewing in real life: things get smaller as they get farther away.
second, ortho view is just the opposite of the projection matrix, in ortho view, everything is the same size, no matter where you put it on the z-plane. (this is usually used for 2D games)
and modelview is just another mode that you can enter, by going in to modelview mode, all of the translations and rotations affect the current polygons you are working with, whereas matrixmode will change the view, with either ortho or perspective, here''s an example:
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window{ if (height==0) height=1; glViewport(0,0,width,height); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,600.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); // Reset The Modelview Matrix}
quote:
Also, could someone explain what the following functions do?
glMatrixMode
glPushMatrix
glPopMatrix
glOrtho
glTranslated
thanks
glMatrixMode, Matrix mode changes the current view, whether it be ortho or perspective
glPushMatrix, this takes the current matrix settings, and puts them in to a thing called a "stack", if you don''t know what the stack is, that''s ok, i won''t get in to detail about it, but when you push something on the stack, it''s like layering pancakes. When you put one pancake on the plate, it''s there, but once you start putting more of them on, you have to pile them. When you want to take a pancake off, you have to take one from the top, and you can only get to the bottom once all of the other pancakes are gone, you get what I mean?
so, with pushMatrix, you can take the current matrix settings and push them on to this stack
now, popmatrix does just the opposite, for every push, there is a pop, when you pop a matrix, you are taking the last pushed matrix back in to the matrix mode.....arg, confusing i know, but it''s hard to explain....
glOrtho is the code you use to set up your ortho view, you can find out more about this from one of NeHe''s tuts, it''s really easy to figure out
and, well, gltranslate.....lol, this is one of the basic commands you need in OpenGL, glTranslated translates whatever polygons you draw after that to those positions:
glTranslated(10,5,-10);
that will translate (translate=move) the polygon 10 units to the right, 5 units up, and 10 units in to the screen (might be different for you)
so, if you don''t get anything, or you need more of an explanation, I''d advise either replying to this post, or go through the NeHe tutorials, and if you still don''t get it...I''d advise you try and make sure you understand the concept of 3D a bit better....
When you submit a vertex to OpenGL, eg. by rendering a face, then it will be transformed by a series of matrices, before being handed over to the rasterizer (the part of your 3D card that actually draws the face).
First, the vertex will pass through the modelview matrix. This matrix will apply all rotations and translations you typically do to an object. Imagine a car. The wheels are turning, that is done through a special modelview matrix. The car itself moves around, and that is done with a second modelview matrix, which is set 'above' the wheel one (that's called 'concatenation'). Now, you also have a camera, that can look at the scene from different angles. This is a third matrix, which is again combined with the first two modelview matrices.
If you want to change the modelview matrix, you first have to select it: glMatrixMode(GL_MODELVIEW); This will simply tell OpenGL: from now on, all matrix commands will affect the modelview matrix !
glRotatef/d() and glTranslatef/d() are examples of commands that combine a new matrix (a rotation and a translation matrix) with the current one.
Once the vertex is past the modelview matrix, it will reach a second one: the projection matrix. This one actually tells OpenGL how to transform the 3D point to your 2D screenspace. This transformation is called 'projection', hence the name projection matrix. Typically, two different projection modes are used: perspective projection (a simulation how we see things in real life, further objects get smaller), or an orthographic projection (where distance does not affect object size). More, sometimes very weird, projection modes can also be used by changing the projection matrix manually.
To tell OpenGL which projection mode you want to use, you first need to select the projection matrix: glMatrixMode(GL_PROJECTION); Now, all subsequent matrix commands will affect the projection matrix.
To load a perspective matrix, you use either gluPerspective(), or glFrustum() (or if you know what you are doing, you can also load it manually). To load an orthographic matrix, you use the glOrtho() command. All three functions will load their respective matrix onto the projection matrix stack.
Note that when I said that the matrices are loaded onto the stack, that's not actually the full truth. In reality they are multiplied with the current one. But that's pretty complicated to explain, and you should get a good introduction into matrix math first.
For a more thorough explanation, I would suggest reading the OpenGL redbook, which is basically a large OpenGL tutorial. You can download it here.
[edited by - Yann L on February 11, 2003 7:42:09 PM]
First, the vertex will pass through the modelview matrix. This matrix will apply all rotations and translations you typically do to an object. Imagine a car. The wheels are turning, that is done through a special modelview matrix. The car itself moves around, and that is done with a second modelview matrix, which is set 'above' the wheel one (that's called 'concatenation'). Now, you also have a camera, that can look at the scene from different angles. This is a third matrix, which is again combined with the first two modelview matrices.
If you want to change the modelview matrix, you first have to select it: glMatrixMode(GL_MODELVIEW); This will simply tell OpenGL: from now on, all matrix commands will affect the modelview matrix !
glRotatef/d() and glTranslatef/d() are examples of commands that combine a new matrix (a rotation and a translation matrix) with the current one.
Once the vertex is past the modelview matrix, it will reach a second one: the projection matrix. This one actually tells OpenGL how to transform the 3D point to your 2D screenspace. This transformation is called 'projection', hence the name projection matrix. Typically, two different projection modes are used: perspective projection (a simulation how we see things in real life, further objects get smaller), or an orthographic projection (where distance does not affect object size). More, sometimes very weird, projection modes can also be used by changing the projection matrix manually.
To tell OpenGL which projection mode you want to use, you first need to select the projection matrix: glMatrixMode(GL_PROJECTION); Now, all subsequent matrix commands will affect the projection matrix.
To load a perspective matrix, you use either gluPerspective(), or glFrustum() (or if you know what you are doing, you can also load it manually). To load an orthographic matrix, you use the glOrtho() command. All three functions will load their respective matrix onto the projection matrix stack.
Note that when I said that the matrices are loaded onto the stack, that's not actually the full truth. In reality they are multiplied with the current one. But that's pretty complicated to explain, and you should get a good introduction into matrix math first.
For a more thorough explanation, I would suggest reading the OpenGL redbook, which is basically a large OpenGL tutorial. You can download it here.
[edited by - Yann L on February 11, 2003 7:42:09 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement