Chapter 3
Mathematical Foundations
Computer Graphics
Programming in OpenGL with
Java
3rd edition
V. Scott Gordon and John
Clevenger
3D Coordinate Systems
In Direct3D In OpenGL
3D Point or Vector: [xyz1]
“homogeneous notation”
Matrices used in 3D graphics are typically 4x4:
Identity Matrix
multiplying a matrix by a matrix:
*
Aa+Be+Ci+Dm Ab+Bf+Cj+Dn Ac+Bg+Ck+Do Ad+Bh+Cl+Dp
Ea+Fe+Gi+Hm Eb+Ff+Gj+Hn Ec+Fg+Gk+Ho Ed+Fh+Gl+Hp
= Ia+Je+Ki+Lm
Ma+Ne+Oi+Pm
Ib+Jf+Kj+Ln Ic+Jg+Kk+Lo
Mb+Nf+Oj+Pn Mc+Ng+Ok+Po
Id+Jh+Kl+Lp
Md+Nh+Ol+Pp
multiplying a matrix by a matrix:
*
Aa+Be+Ci+Dm Ab+Bf+Cj+Dn Ac+Bg+Ck+Do Ad+Bh+Cl+Dp
= Ea+Fe+Gi+Hm
Ia+Je+Ki+Lm
Ma+Ne+Oi+Pm
Eb+Ff+Gj+Hn Ec+Fg+Gk+Ho
Ib+Jf+Kj+Ln Ic+Jg+Kk+Lo
Mb+Nf+Oj+Pn Mc+Ng+Ok+Po
Ed+Fh+Gl+Hp
Id+Jh+Kl+Lp
Md+Nh+Ol+Pp
2 3 3 2 2*3+3*4 2*2+3*4 18 7
1 5
* 4 1
= 1*3+5*4 1*2+5*1
= 23 7
3 2 2 3 ? ? 8 19
4 1
* 1 5
= ? ?
= 9 17
Matrix Multiplication
multiplying a vector (or point) by a matrix:
*
Matrix multiplication is associative
(this will become useful later)
New Point = Matrix1 * (Matrix2 * (Matrix3 * Point))
New Point = (Matrix1 * Matrix2 * Matrix3) * Point
and thus, equivalently:
MatrixC = Matrix1 * Matrix2 * Matrix3
New Point = MatrixC * Point
In this example, MatrixC is often called the
concatenation of Matrix1, Matrix2, and Matrix3
Inverse of a matrix
Inverse of A is A-1 s.t.
A*A-1 = A-1*A = identity matrix
Example:
Matrix Transforms
Useful for us:
● Translation
● Rotation
● Scale
● Projection
● Look-At
Translation Matrix
in JOML:
• Matrix4f.settranslation(x,y,z)
• Vector4f.mul(Matrix4f)
• Vector4f.mulPosition(Matrix4f)
Scale Matrix
in JOML:
• Matrix4f.scaling(x,y,z)
• Vector3f.mul(Matrix4f)
Rotation Matrix
Rotation around
X by θ degrees
Rotation around
Y by θ degrees
Rotation around
Z by θ degrees
in JOML:
• Matrix4f.rotateX(radians)
• Matrix4f.rotateY(radians)
• Matrix4f.rotateZ(radians)
• Matrix4f.rotateXYZ(θx,θy,θz)
• Vector3f.mul(Matrix4f)
In the mid-1700s, the mathematician Leonhard Euler
showed that a rotation around any desired axis could
be specified instead as a combination of rotations
around the X,Y, and Z axes.
These three rotation angles, around the respective
axes, have come to be known as Euler angles.