Course list http://www.cjump.com/bcc/


For vertices OpenGL is using 4component vectors, which are sets of four numbers:
( x, y, z, w )
where x, y, z are coordinates, and w serves two purposes:
If w == 1, then the vector ( x, y, z, 1 ) is a position in space
If w == 0, then the vector ( x, y, z, 0 ) is a direction
Why use homogeneous coordinates?
They allow to apply the same mathematical formulas to deal with all matrix transformations in 3D graphics.
An ( x, y, z, w ) vector in homogeneous coordinates actually means ( x/w, y/w, z/w ) in a 3D space.
Read more: http://www.opengltutorial.org/beginnerstutorials/tutorial3matrices/ matrices tutorial from www.opengltutorial.org


In 2D we use a lot of trigonometry
In 3D we use a lot of linear algebra
In physics calculation for 3D games we begin to use calculus
A matrix can:
Translate (move) a vertex
Rotate a vertex
Scale a vertex
Math libraries cover up these details, but we need to learn matrix math to understand 3D modeling and animation.
We can multiply a matrix by a vector, which yields another vector:
Note: we can also multiply a matrix by another matrix, which yields a matrix (more on this later.)
Multiplying a point (represented by a vector) by a matrix (representing a transformation) yields a new transformed point (another vector.)
Points are always stored with a 1 for the 4th element of the vector.
Suppose we want to rotate point [1 0 0] around z axis by 90 degrees:
 cos(90) sin(90) 0 0   1   ?   sin(90) cos(90) 0 0  .  0  =  ?   0 0 1 0   0   ?   0 0 0 1   1   ? 
We could take 4 steps to find the solution:
 cos(90) sin(90) 0 0   1   0  cos(90)*1 + sin(90)*0 + 0*0 + 0*1  sin(90) cos(90) 0 0  .  0  =  ?   0 0 1 0   0   ?   0 0 0 1   1   ?   cos(90) sin(90) 0 0   1   0   sin(90) cos(90) 0 0  .  0  =  1  sin(90)*1 + cos(90)*0 + 0*0 + 0*1  0 0 1 0   0   ?   0 0 0 1   1   ?   cos(90) sin(90) 0 0   1   0   sin(90) cos(90) 0 0  .  0  =  1   0 0 1 0   0   0  0*1 + 0*0 + 1*0 + 0*1  0 0 0 1   1   ?   cos(90) sin(90) 0 0   1   0   sin(90) cos(90) 0 0  .  0  =  1   0 0 1 0   0   0   0 0 0 1   1   1  0*1 + 0*0 + 0*0 + 1*1 Answer:  cos(90) sin(90) 0 0   1   0   sin(90) cos(90) 0 0  .  0  =  1   0 0 1 0   0   0   0 0 0 1   1   1 
An identity matrix is a matrix that, when performing matrix multiplication, will return the unmodified matrix (or vector) it was multiplied with. It is sort of like the number 1 with regular multiplication:
1 * X = X
Transformation matrices are matrices representing operations on 3D points and objects.
The typical operations are translation, rotation, and scaling:
See also: http://www.opengltutorial.org/beginnerstutorials/tutorial3matrices/ matrices tutorial from www.opengltutorial.org


See also: Chapter 6. Objects in Motion, Translation article from Learning Modern 3D Graphics Programming tutorial


See also: Chapter 6. Objects in Motion, Rotation article from Learning Modern 3D Graphics Programming tutorial
Another kind of transformation is scaling: making objects bigger or smaller:
See also: Chapter 6. Objects in Motion, Scale article from Learning Modern 3D Graphics Programming tutorial
We can also multiply a matrix by another matrix.
The multiplication of two 3x3 matrices forms a 3x3 matrix, calculated as follows:
The multiplication of two 4x4 matrices forms a 4x4 matrix, calculated as follows:
Note: matrix order matters! We multiply them left to right, otherwise the results are drastically different:
AB ≠ BA
Av ≠ vA
Matrix by matrix multiplication, as well as matrix by vector multiplication, can be combined into a series of transformations. For example,
A · B · v
where A and B are matrices, and v is a vector representing a point in space.
Due to the associativity rules of multiplication (which applies similarly to C/C++ arithmetic operators), the above expression is interpreted as
( A · B ) · v
and is also equivalent to
A · ( B · v )
The form ( A · B ) · v is preferred because it allows multiple transformations to be stored in a single matrix.
See also: Chapter 6. Objects in Motion, Fun with Matrices article from Learning Modern 3D Graphics Programming tutorial
Consider: TransformedVector = TranslationMatrix * RotationMatrix * ScaleMatrix * OriginalVector;
In this example,
scaling takes place FIRST
THEN the rotation, and
THEN the translation
Model Space (aka Object Space)
World Space
Camera Space (aka Eye Space or View Space)
Screen Space (aka Clip Space)
Object Space (also known as Object Coordinates)
In these conventional coordinates, the objects are described relative to a local origin,
typically [0 0 0].
For example, a cube can be placed at the origin in one of its vertices, or at the center of the cube.
Next, we may rotate and scale ther cube to adjust its initial appearance.
World Space
We may now need to move our cube relative to some global origin, which represents our 3D world.
View Space (Camera Space)
We shall now decide where the observer of our world is positioned. For this we can scale, rotate, and move around the entire world.
(Image from matrix44.net)
See also: Chapter 7. World in Motion article from Learning Modern 3D Graphics Programming tutorial






Projection matrix places all visible objects in a perfect view volume cube (shown on the right) with coordinates between 1 and 1 on all axes:
This cube defines our view volume.
Projection transformation yields (x, y, z, w) coordinates such that
1.0 <= x/w <= +1.0 1.0 <= y/w <= +1.0 1.0 <= z/w <= +1.0
These coordinates are called homogeneous clip coordinates, which define the clip space.
For more info, read http://www.opengltutorial.org/beginnerstutorials/tutorial3matrices/ matrices tutorial, which details how the projection matrix works.
When vertex shader writes into gl_Position, the resulting coordinate is considered to be in clip space. What this means is that the vertex becomes a subject for clipping.
Thus, OpenGL clipping takes place in clip space as follows:
Any geometrical primitives outside the top, bottom, left and right of the view volume cube are clipped.
Anything in front near plane or behind the far plane is discarded:
if a triangle has at least one vertex in front or behind the view volume, the entire triangle is removed from the view.
all four coordinates (x, y, z, w) are divided by w
z is translated into the range between 0.0 and 0.1
w is set to 1.0. The result is considered to be the normalized device space, or screen space:
1.0 <= x <= +1.0 1.0 <= y <= +1.0 0.0 <= z <= +1.0 w = 1.0
Everything inside the NDC space is shown on screen.
Projection from eye coordinates to clip space, followed by the normalized device space:
Note that most lighting calculations are done in eye space (camera space)  that is  before projection transformation
Before NDC volume is projected to a window, positions of the vertices are adjusted in proportion to the window on the computer screen, and the final image is rendered:
Normals are unitlength vectors pointing perpendicular to a surface.
Translating a surface does not change its normal.
While objects undergo rotations (and sometimes isometric, shape nonpreserving scaling), we need to construct a 3x3 matrix that includes all rotations and isomertric scaling transformations to eye coordinates.
Perspective transformations should not be applied to normals.