I am trying to understand the opengl mechanism of vertice coordinates transformation.
I have read the opengl specification about the matrix, but the explanation about the fourth coordinate of vertice,w is very brief! In fact there is no explanation, just a matrix…

Someone can explain why opengl need four coordinates in a 3 dimensions world?

Originally posted by dletozeun: Someone can explain why opengl need four coordinates in a 3 dimensions world?

The fourth coordinate is used to create perspective look. For example, a straight train railroad becomes narrower while it is further from your eye. Now, consider how we produce such perspective view in computer graphics.

In 3D Cartesian coords with (x,y,z), two parallel lines cannot meet (intersect) each other. Therefore, Cartesian coords cannot be used to create a perspective look.

However, we have a solution by adding additional coordinate, w, and it is called Homogeneous coordinates, (x,y,z,w). With Homogeneous coords, two parallel lines are met at the infinity where w=0. Homogeneous coordinates are fundamental concept in computer graphics, such as projecting a 3D scene onto a 2D screen.

I didn’t know the homogeneous coordinates, I had an approach more “physician” of the persopective in 3D rendering…

I will search more information about this in order to understand how perspective is set up through this coordinate system…
But I don’t understand everything, because in this article: homogeneous coordinates

they don’t speak about 3D coordinates but 2D cartesian coordinates and 2D homogeneous coordinates…
What does the z coordinate become in opengl??

dletozeun,
Homogeneous coordinates are a way of representing N-dimensional coordinates with N+1 components. For example, a physical 3D space can be represented with (x,y,z) in Cartesian space which most people are well familiar with, but (x,y,z,w) in Homogeneous coordinates. In a same way, 2D plane is now (x,y,w) in homogeneous coords.

Homogeneous coords makes the perspective mathatically possible in computer graphics.

Search fine art paintings in Renaissance period (with “perspective” keyword). You may find out amazing works with the perspective concept and genius works using irregular viewing frustum. Artists at that time already knew about two parallel lines can intercept. :eek:

You’re almost there. The screen coordinate is not 2 dimensions, but 3; x and y to determine it’s position on the screen, and z for the depth (used for the z-buffer).

So (x, y, z, w) is transformed by the modelview and projection matrix. This coordinate is then normalized in the perspective division to (x/w, y/w, z/w, w/w) = (x/w, y/w, z/w, 1). (x/w, y/w, z/w) is then transformed by the viewport transform to (sx, sy, sz), which is pixel (sx, sy) with depth value sz.