What are exactly Model Coordinates and how OF handles them?

Hi everybody,
I’m diving right now into the transforms applied by OpenGL when a vertex is created.
I have some problem with the model coordinates, because I don’t really understand to what they relate.
I mean, there’s something like some “world coordinates” to which they are relative?
I was thinking that after the ModelView matrix transform, Model Coordinates become just relative to the view point (which is the new 0,0,0, right?).
Then there’s my second question:
when I give some coordinates for a polygon to oF I’m just giving them in window coordinates.
So, what, oF converts them to Model Coordinates and apply the transformations to get them back to window coordinates?
I’m sorry if this post is quite confused, but any help would be really appreciated.

Thank you!


Hopefully someone will come in and correct me if I’m lying here, but as far as I understand the reason you can issue drawing commands for a polygon in window coordinates is that unless you set your own camera, a default view is set up based on your window size in such a way that as long as your polygon vertices come with a Z = 0 it will end up where you expect it.

This is the best tutorial I’ve seen on the different spaces, the part with the monkey head really helped me:

Most of the time you see a combined modelView matrix, to take you straight to camera/view space.


1 Like

what hahakid says is correct. OF sets by default a perspective where the camera is positioned at the exact distance from 0 to make the origin be at the top left of the screen and the world coordinates at Z==0 match the screen coordinates.

the exact way it works is by setting 2 main matrices:

the projection which is the matrix that projects any point from the 3D space into the 2D space of the screen

the view which is the inverse of matrix that defines the position of the camera.

in opengl 2.1 or less there where by default only projection and modelview. OF by default uses that same paradigm. From 0.9 on though, you can access the view matrix separately too, which is useful to calculate lighting…

so when you do calls like translate, rotate… you are modifying the modelview matrix. when you pass coordinates to a polygon there’s usually no model matrix involved at all: we just generate the vertices of the polygon at that location.

you can check the code that sets the projection and view matrices in the setupPerspective function in ofGLRenderer and ofGLProgrammableRenderer

Thank you both for your preciuos answers.
I have not checked the code yet, but if I understand correctly: the eye coordinates are set in a way that the 0,0,0 is on the top left of the screen and the view is the same size as the window. But still there is a conversion in normalized device coordinates, right? And a successive conversion back in window coordinates.
Correct me please if I’m wrong.

yes that’s it, the workflow is the same as in any other typical openGL application.

1 Like

Thank you very much.