mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Update GLM to latest version (0.9.9.3). This includes GLM's change of matrices no longer default initializing to the identity matrix. This commit thus also includes the update of all of LearnOpenGL's code to reflect this: all matrices are now constructor-initialized to the identity matrix where relevant.
This commit is contained in:
@@ -220,22 +220,22 @@ int main()
|
||||
void renderScene(const Shader &shader)
|
||||
{
|
||||
// floor
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
shader.setMat4("model", model);
|
||||
glBindVertexArray(planeVAO);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
// cubes
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(0.0f, 1.5f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(2.0f, 0.0f, 1.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-1.0f, 0.0f, 2.0));
|
||||
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
|
||||
model = glm::scale(model, glm::vec3(0.25));
|
||||
|
||||
@@ -243,22 +243,22 @@ int main()
|
||||
void renderScene(const Shader &shader)
|
||||
{
|
||||
// floor
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
shader.setMat4("model", model);
|
||||
glBindVertexArray(planeVAO);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
// cubes
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(0.0f, 1.5f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(2.0f, 0.0f, 1.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-1.0f, 0.0f, 2.0));
|
||||
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
|
||||
model = glm::scale(model, glm::vec3(0.25));
|
||||
|
||||
@@ -251,22 +251,22 @@ int main()
|
||||
void renderScene(const Shader &shader)
|
||||
{
|
||||
// floor
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
shader.setMat4("model", model);
|
||||
glBindVertexArray(planeVAO);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
// cubes
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(0.0f, 1.5f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(2.0f, 0.0f, 1.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-1.0f, 0.0f, 2.0));
|
||||
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
|
||||
model = glm::scale(model, glm::vec3(0.25));
|
||||
|
||||
@@ -206,7 +206,7 @@ int main()
|
||||
void renderScene(const Shader &shader)
|
||||
{
|
||||
// room cube
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::scale(model, glm::vec3(5.0f));
|
||||
shader.setMat4("model", model);
|
||||
glDisable(GL_CULL_FACE); // note that we disable culling here since we render 'inside' the cube instead of the usual 'outside' which throws off the normal culling methods.
|
||||
@@ -215,27 +215,27 @@ void renderScene(const Shader &shader)
|
||||
shader.setInt("reverse_normals", 0); // and of course disable it
|
||||
glEnable(GL_CULL_FACE);
|
||||
// cubes
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(4.0f, -3.5f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(2.0f, 3.0f, 1.0));
|
||||
model = glm::scale(model, glm::vec3(0.75f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-3.0f, -1.0f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-1.5f, 1.0f, 1.5));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-1.5f, 2.0f, -3.0));
|
||||
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
|
||||
model = glm::scale(model, glm::vec3(0.75f));
|
||||
|
||||
@@ -206,7 +206,7 @@ int main()
|
||||
void renderScene(const Shader &shader)
|
||||
{
|
||||
// room cube
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::scale(model, glm::vec3(5.0f));
|
||||
shader.setMat4("model", model);
|
||||
glDisable(GL_CULL_FACE); // note that we disable culling here since we render 'inside' the cube instead of the usual 'outside' which throws off the normal culling methods.
|
||||
@@ -215,27 +215,27 @@ void renderScene(const Shader &shader)
|
||||
shader.setInt("reverse_normals", 0); // and of course disable it
|
||||
glEnable(GL_CULL_FACE);
|
||||
// cubes
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(4.0f, -3.5f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(2.0f, 3.0f, 1.0));
|
||||
model = glm::scale(model, glm::vec3(0.75f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-3.0f, -1.0f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-1.5f, 1.0f, 1.5));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-1.5f, 2.0f, -3.0));
|
||||
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
|
||||
model = glm::scale(model, glm::vec3(0.75f));
|
||||
|
||||
@@ -121,7 +121,7 @@ int main()
|
||||
shader.setMat4("projection", projection);
|
||||
shader.setMat4("view", view);
|
||||
// render normal-mapped quad
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::rotate(model, glm::radians((float)glfwGetTime() * -10.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0))); // rotate the quad to show normal mapping from multiple directions
|
||||
shader.setMat4("model", model);
|
||||
shader.setVec3("viewPos", camera.Position);
|
||||
@@ -133,7 +133,7 @@ int main()
|
||||
renderQuad();
|
||||
|
||||
// render light source (simply re-renders a smaller plane at the light's position for debugging/visualization)
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, lightPos);
|
||||
model = glm::scale(model, glm::vec3(0.1f));
|
||||
shader.setMat4("model", model);
|
||||
|
||||
@@ -127,7 +127,7 @@ int main()
|
||||
shader.setMat4("projection", projection);
|
||||
shader.setMat4("view", view);
|
||||
// render parallax-mapped quad
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::rotate(model, glm::radians((float)glfwGetTime() * -10.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0))); // rotate the quad to show parallax mapping from multiple directions
|
||||
shader.setMat4("model", model);
|
||||
shader.setVec3("viewPos", camera.Position);
|
||||
@@ -143,7 +143,7 @@ int main()
|
||||
renderQuad();
|
||||
|
||||
// render light source (simply re-renders a smaller plane at the light's position for debugging/visualization)
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, lightPos);
|
||||
model = glm::scale(model, glm::vec3(0.1f));
|
||||
shader.setMat4("model", model);
|
||||
|
||||
@@ -127,7 +127,7 @@ int main()
|
||||
shader.setMat4("projection", projection);
|
||||
shader.setMat4("view", view);
|
||||
// render parallax-mapped quad
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::rotate(model, glm::radians((float)glfwGetTime() * -10.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0))); // rotate the quad to show parallax mapping from multiple directions
|
||||
shader.setMat4("model", model);
|
||||
shader.setVec3("viewPos", camera.Position);
|
||||
@@ -143,7 +143,7 @@ int main()
|
||||
renderQuad();
|
||||
|
||||
// render light source (simply re-renders a smaller plane at the light's position for debugging/visualization)
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, lightPos);
|
||||
model = glm::scale(model, glm::vec3(0.1f));
|
||||
shader.setMat4("model", model);
|
||||
|
||||
@@ -127,7 +127,7 @@ int main()
|
||||
shader.setMat4("projection", projection);
|
||||
shader.setMat4("view", view);
|
||||
// render parallax-mapped quad
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::rotate(model, glm::radians((float)glfwGetTime() * -10.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0))); // rotate the quad to show parallax mapping from multiple directions
|
||||
shader.setMat4("model", model);
|
||||
shader.setVec3("viewPos", camera.Position);
|
||||
@@ -143,7 +143,7 @@ int main()
|
||||
renderQuad();
|
||||
|
||||
// render light source (simply re-renders a smaller plane at the light's position for debugging/visualization)
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, lightPos);
|
||||
model = glm::scale(model, glm::vec3(0.1f));
|
||||
shader.setMat4("model", model);
|
||||
|
||||
@@ -173,7 +173,7 @@ int main()
|
||||
}
|
||||
shader.setVec3("viewPos", camera.Position);
|
||||
// render tunnel
|
||||
glm::mat4 model = glm::mat4();
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(0.0f, 0.0f, 25.0));
|
||||
model = glm::scale(model, glm::vec3(2.5f, 2.5f, 27.5f));
|
||||
shader.setMat4("model", model);
|
||||
|
||||
@@ -196,7 +196,7 @@ int main()
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||
glm::mat4 view = camera.GetViewMatrix();
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
shader.use();
|
||||
shader.setMat4("projection", projection);
|
||||
shader.setMat4("view", view);
|
||||
@@ -210,7 +210,7 @@ int main()
|
||||
}
|
||||
shader.setVec3("viewPos", camera.Position);
|
||||
// create one large cube that acts as the floor
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(0.0f, -1.0f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(12.5f, 0.5f, 12.5f));
|
||||
shader.setMat4("model", model);
|
||||
@@ -218,38 +218,38 @@ int main()
|
||||
renderCube();
|
||||
// then create multiple cubes as the scenery
|
||||
glBindTexture(GL_TEXTURE_2D, containerTexture);
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(0.0f, 1.5f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(2.0f, 0.0f, 1.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-1.0f, -1.0f, 2.0));
|
||||
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(0.0f, 2.7f, 4.0));
|
||||
model = glm::rotate(model, glm::radians(23.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
|
||||
model = glm::scale(model, glm::vec3(1.25));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-2.0f, 1.0f, -3.0));
|
||||
model = glm::rotate(model, glm::radians(124.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
|
||||
shader.setMat4("model", model);
|
||||
renderCube();
|
||||
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(-3.0f, 0.0f, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
shader.setMat4("model", model);
|
||||
@@ -262,7 +262,7 @@ int main()
|
||||
|
||||
for (unsigned int i = 0; i < lightPositions.size(); i++)
|
||||
{
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(lightPositions[i]));
|
||||
model = glm::scale(model, glm::vec3(0.25f));
|
||||
shaderLight.setMat4("model", model);
|
||||
|
||||
@@ -190,13 +190,13 @@ int main()
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||
glm::mat4 view = camera.GetViewMatrix();
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
shaderGeometryPass.use();
|
||||
shaderGeometryPass.setMat4("projection", projection);
|
||||
shaderGeometryPass.setMat4("view", view);
|
||||
for (unsigned int i = 0; i < objectPositions.size(); i++)
|
||||
{
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, objectPositions[i]);
|
||||
model = glm::scale(model, glm::vec3(0.25f));
|
||||
shaderGeometryPass.setMat4("model", model);
|
||||
@@ -247,7 +247,7 @@ int main()
|
||||
shaderLightBox.setMat4("view", view);
|
||||
for (unsigned int i = 0; i < lightPositions.size(); i++)
|
||||
{
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, lightPositions[i]);
|
||||
model = glm::scale(model, glm::vec3(0.125f));
|
||||
shaderLightBox.setMat4("model", model);
|
||||
|
||||
@@ -190,13 +190,13 @@ int main()
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||
glm::mat4 view = camera.GetViewMatrix();
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
shaderGeometryPass.use();
|
||||
shaderGeometryPass.setMat4("projection", projection);
|
||||
shaderGeometryPass.setMat4("view", view);
|
||||
for (unsigned int i = 0; i < objectPositions.size(); i++)
|
||||
{
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, objectPositions[i]);
|
||||
model = glm::scale(model, glm::vec3(0.25f));
|
||||
shaderGeometryPass.setMat4("model", model);
|
||||
@@ -251,7 +251,7 @@ int main()
|
||||
shaderLightBox.setMat4("view", view);
|
||||
for (unsigned int i = 0; i < lightPositions.size(); i++)
|
||||
{
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, lightPositions[i]);
|
||||
model = glm::scale(model, glm::vec3(0.125f));
|
||||
shaderLightBox.setMat4("model", model);
|
||||
|
||||
@@ -241,12 +241,12 @@ int main()
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 50.0f);
|
||||
glm::mat4 view = camera.GetViewMatrix();
|
||||
glm::mat4 model;
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
shaderGeometryPass.use();
|
||||
shaderGeometryPass.setMat4("projection", projection);
|
||||
shaderGeometryPass.setMat4("view", view);
|
||||
// room cube
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(0.0, 7.0f, 0.0f));
|
||||
model = glm::scale(model, glm::vec3(7.5f, 7.5f, 7.5f));
|
||||
shaderGeometryPass.setMat4("model", model);
|
||||
@@ -254,7 +254,7 @@ int main()
|
||||
renderCube();
|
||||
shaderGeometryPass.setInt("invertedNormals", 0);
|
||||
// nanosuit model on the floor
|
||||
model = glm::mat4();
|
||||
model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(0.0f, 0.0f, 5.0));
|
||||
model = glm::rotate(model, glm::radians(-90.0f), glm::vec3(1.0, 0.0, 0.0));
|
||||
model = glm::scale(model, glm::vec3(0.5f));
|
||||
|
||||
Reference in New Issue
Block a user