diff --git a/src/main.cc b/src/main.cc index 9462527..fe0bed5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -230,6 +230,18 @@ int main() { shader.activate(); + // the model matrix. this rotates the plane on the x axis by -55 degrees. + glm::mat4 model(1.0f); + model = glm::rotate(model, glm::radians(-55.0f), glm::vec3(1.0f, 0.0f, 0.0f)); + + // the view matrix. this moves the "camera" back by 3 units. + glm::mat4 view(1.0f); + view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f)); + + // the projection matrix. the fov is 45 degrees. the aspect is 800/600 (4:3). the near plane is 0.1 units. the far plane is 100 units. + glm::mat4 projection; + projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f); + // create the identity matrix glm::mat4 trans(1); // translate it by this vector3 @@ -237,7 +249,9 @@ int main() { // rotate by the z axis with the angle being controlled by time trans = glm::rotate(trans, (float)glfwGetTime(), glm::vec3(0.0f, 0.0f, 1.0f)); - shader.setMat4("transform", trans); + shader.setMat4("model", model); + shader.setMat4("view", view); + shader.setMat4("projection", projection); if (!rectangleToggled) { // Bind the state to use the vertexArrayObject object so OpenGL knows what to do with the verticies. diff --git a/src/vertex.glsl b/src/vertex.glsl index 18dbccf..49d5b4a 100644 --- a/src/vertex.glsl +++ b/src/vertex.glsl @@ -7,10 +7,13 @@ layout (location = 2) in vec2 aTexCoord; out vec3 ourColor; out vec2 TexCoord; -uniform mat4 transform; +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; void main() { - gl_Position = transform * vec4(aPos, 1.0); + // matrix multiplication goes from right to left. + gl_Position = projection * view * model * vec4(aPos, 1.0); ourColor = aColor; TexCoord = aTexCoord; }