University of Wales Trinity Saint David
ACCA6021 - Graphics and Games Programming

Lab REF - Matrix and Trig Reference Card

Overview

This card is designed to be printed and kept alongside your lab worksheet. It covers trig values at standard angles, the standard transformation matrices in column-major layout, and the GLM function calls that correspond to each matrix operation.

Learning Objectives

By the end of this lab you will be able to:

Concept

This reference card contains no exercises. Use it alongside worksheets WS-M02 through WS-M07 and the Transformations lab (Lab 07) onward. All matrices are written in the row-reading convention used on paper: each row is displayed left to right. GLM stores them in column-major order internally (first column occupies memory indices 0-3, second column 4-7, and so on), but the mathematical content is identical. You do not need to rearrange these matrices when writing GLM code. Refer to the Column-Major Convention lab (WS-M04) if you need a reminder of the storage layout.

Tasks

Task 1 - Reference Tables

Section 1 - Trigonometric Values at Standard Angles

Angle (deg)Angle (rad)sincostan
00010
30π/61/2√3/2 ≈ 0.8661/√3 ≈ 0.577
45π/4√2/2 ≈ 0.707√2/2 ≈ 0.7071
60π/3√3/2 ≈ 0.8661/2√3 ≈ 1.732
90π/210undefined

Section 2 - Translation Matrix T(tx, ty, tz)

Column-major layout (tx, ty, tz appear in column 3, GLM memory indices 12-14):

| 1  0  0  tx |
| 0  1  0  ty |
| 0  0  1  tz |
| 0  0  0   1 |

GLM: glm::translate(mat, glm::vec3(tx, ty, tz))

Section 3 - Rotation Matrices (angle t in radians, abbreviated)

R_x(t) - rotation around X axis:

| 1    0       0    0 |
| 0  cos(t)  -sin(t) 0 |
| 0  sin(t)   cos(t) 0 |
| 0    0       0    1 |

GLM: glm::rotate(mat, t, glm::vec3(1,0,0))

R_y(t) - rotation around Y axis (note sign swap: -sin at row 2, col 0):

|  cos(t)  0  sin(t)  0 |
|    0     1    0     0 |
| -sin(t)  0  cos(t)  0 |
|    0     0    0     1 |

GLM: glm::rotate(mat, t, glm::vec3(0,1,0))

R_z(t) - rotation around Z axis:

| cos(t)  -sin(t)  0  0 |
| sin(t)   cos(t)  0  0 |
|   0        0     1  0 |
|   0        0     0  1 |

GLM: glm::rotate(mat, t, glm::vec3(0,0,1))

Section 4 - Perspective Projection Matrix

Parameters: f = 1/tan(fov/2), a = aspect ratio, n = near, z = far.

| f/a   0       0            0         |
|  0    f       0            0         |
|  0    0   -(z+n)/(z-n)  -2zn/(z-n)  |
|  0    0      -1            0         |

M[2][3] = -1 copies -z_view into w_clip, enabling the perspective divide. After dividing clip coords by w, NDC values land in [-1, 1] for visible geometry.

GLM: glm::perspective(glm::radians(fov_degrees), aspect, near, far)

Section 5 - GLM Function Reference

PurposeGLM Call
Identity matrixglm::mat4(1.0f)
Translationglm::translate(mat, glm::vec3(tx, ty, tz))
Rotationglm::rotate(mat, glm::radians(degrees), axis)
Uniform scaleglm::scale(mat, glm::vec3(s, s, s))
Perspective projectionglm::perspective(glm::radians(fov), aspect, near, far)
Orthographic projectionglm::ortho(left, right, bottom, top, near, far)
Look-at / view matrixglm::lookAt(eye, centre, worldUp)
Normal matrix (C++)glm::mat3(glm::transpose(glm::inverse(model)))
Normal matrix (GLSL)mat3(transpose(inverse(model)))