4.1.1 Add Modelling, View, Projecton Matrices

We know that a model's transformation from 3D to 2D can be represented as PVMPVM.

To deal with modelling, viewing and projection, we use three global variables in main.cpp : matModelRoot, matView, and matProj to repsent the modelling matrix, view matrix and the projection matrix repectively.

Add their declaration after the declaration of the shader variable in main.cpp, initialise matModelRoot and matView to identity matrix. Intialise the projection matrix to a default orthographic projection.

// main.cpp
static Shader shader;

// add the following decalarations
glm::mat4 matModelRoot = glm::mat4(1.0);
glm::mat4 matView = glm::mat4(1.0);
glm::mat4 matProj = glm::ortho(-2.0f,2.0f,-2.0f,2.0f, -2.0f,2.0f);

Last updated