PDA

View Full Version : Difference between view and Model Transformation

swetha
09-30-2009, 04:25 AM
Hello,
I am learning Opengl.I am confused with the view transformation and model transformation.

glTranslatef(0.0f,0.0f,-8.0f);
glBegin(GL_POLYGON);
glVertex3f(1.0f,0.0f,-8.0f);
glVertex3f(3.0f,0.0f,-8.0f);
glVertex3f(2.0f,2.0f,-8.0f);
glEnd();
I understood the above code as view transformation,setting the camera position at (0,0,-8) and viewing the triangle.

glBegin(GL_POLYGON);
glVertex3f(1.0f,0.0f,-8.0f);
glVertex3f(3.0f,0.0f,-8.0f);
glVertex3f(2.0f,2.0f,-8.0f);
glEnd();
glTranslatef(0.0f,0.0f,-8.0f);

I understand this as Model transformation,translating the object by (0,0,-8).

Both gives the same output. Have i understood correctly?
-swetha

DmitryM
09-30-2009, 06:54 AM

k_szczech
09-30-2009, 07:08 AM
No, totally wrong.

All matrix operations affect currently selected matrix (look at glMatrixMode).

So:

glMatrixMode(GL_PROJECTION);
glFrustum(...);
This changes current projection matrix.

glMatrixMode(GL_MODELVIEW);
glTranslatef(...);
This changes current modelview matrix.

In OpenGL you have model and view matrices combined into one modelview matrix. You should know such things before you start programming.

As for vertex operations - all vertices are processed using current state of matrices. Changing your matrix after you passed vertices makes no sense.
This is another thing you should know before writting OpenGL programs.

Read how OpenGL works before you learn programming it. There is no other way.

Clarence
09-30-2009, 01:47 PM
Conceptually view matrix affects all objects in your scene (your camera), and model matrix affects individual objects. In OpenGL they are combined into one modelview matrix, so here is what you could do:

glMatrixMode(GL_MODELVIEW);
// specify view matrix
gluLookAt(...);
glRotate(...);
// save view matrix
glPushMatrix();
// specify model matrix #1
glRotate(...);
// define object #1. The view matrix and the model matrix #1 affect this object
glBegin(...);
...
glEnd();
// restore view matrix
glPopMatrix();
// specify model matrix #2
glRotate(...);
// define object #2. The view matrix and the model matrix #2 affect this object
glBegin(...);
...
glEnd();
// restore view matrix
glPopMatrix();
// more objects
...