Cleaning Up Coordinate Systems.
Just a quick review.
We start off by building an object.
I'm going to build a person. I like working on the 10x10 grid.
So I build a head
centered at (5,5)
I didn't communicate clearly with Bruce
so when he built the body
he built it centered at the origin
inside of the box (-3,-3,-3) to (3,3,3)
Mason points out that it would be best to have the entire thing in the box (-1,-1,-1) to (1,1,1)
So he scales the body by (2/3, 2/3, 2/3) $S_1$
And the head by (1/20,1/20,1/20) $S_2$
But the head is still needs to move the head to the right place, so he translates it by (-1/2, 1/6, 0) $T_1$
These are really three different sets of modeling coordinates.
$T_1S_2$ head
$S_1$ body
Happy with this James decides to use our great model in his scene
He scales the entire thing by (20,20,20) $S_3$
And rotates it about the z axis by 90° $R_1$
And translates it to (40, 30, 0), $T_2$
This moves the figure to world coordinates.
$T_2R_1S_3T_1S_2$ head
$T_2R_1S_3S_1$ body
We have one more world transformation
Alex decides to make the guy fly
So the entire scene is translated by $T_3$
This makes the final world transformation matrix
$T_3T_2R_1S_3T_1S_2$ head
$T_3T_2R_1S_3S_1$ body
Mike wants to render this with a camera
placed at (0, 50, -30),
looking at (0,0,0)
with a up vector of (0,0,1). $C$
So we need to move the scene from world coordinates to the camera coordinates.
$C_1T_3T_2R_1S_3T_1S_2$ head
$C_1T_3T_2R_1S_3S_1$ body
Finally, Michele defines the frustum as marked in green.
This will be $P_1$
It will both move the frustum to the default clipping volume for the vertex shader.
But after the vertex shader exits, it will project the image to normalized device coordinates (-1, -1) to (1,1)
$P_1C_1T_3T_2R_1S_3T_1S_2$ head
$P_1C_1T_3T_2R_1S_3S_1$ body
Notice we have several parts to this
$P_1C_1$ happens to everything and only changes if
The camera changes
The frustum changes.
$T_3$ is sort of the final world transformation
This probably changes once per scene.
$T_2R_1S_3$ is the transformation on the entire "person"
This probably does not change.
Each part of the person has a transformation as well.
So set the projection/camera transformation globally (send this over)
Reset the world transformation (send this over)
To draw each item in the world
Start with the top level transformation for the item.
Multiply in any modeling transformations (for each step if necessary)
When you get down to the object send this over
Draw the object.
My code in the vertex shader might become
gl_Position = uniformProject * uniformTransform * uniformWorld * uniformModel * attributePosition;
We have one last piece to take care of in the transformation world.
Normalized device coordinates to Device coordinates.
The process we have discussed so far puts all vertexes in NDC space.
(-1,1) to (1,1).
But in general $(dx_{min}, dy_{min}), (dx_{max}, dy_{max}) $
I want to move the point to the unit cube.
So I need to scale by $(\frac{1}{dx_{max}-dx_{min}}, \frac{1}{dy_{max}-dy_{min}})$
And translate by $(-dx_{min},-dy_{min})$
Finally I need to move this to DC, which will be
(0,0) to (width, height) in most cases
But remember, we can set the viewport.
But in general $(wx_{min}, wy_{min}), (wx_{max}, wy_{max}) $
So I need to scale by $(wx_{max}-wx_{min}, wy_{max}-wy_{min})$
And translate by $(wx_{min},wy_{min})$
Fortunately this is done automatically by OpenGL.
We might also need to reflect about the y axis (remember this from a long time ago)
So there is one more thing, rotation in 3d.
But that needs to wait for another lecture.