From 9a40f89fe8fe1f5e45b525f18cb5cbe03f3b3c74 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 30 Jan 2021 04:23:10 +0100 Subject: [PATCH] Model is now transformable --- examples/model/main.cpp | 6 +++++- examples/model/shaders/vertexShader.vert | 8 +++++--- include/model/model.hpp | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/model/main.cpp b/examples/model/main.cpp index a9fe70e..7d3375a 100644 --- a/examples/model/main.cpp +++ b/examples/model/main.cpp @@ -131,7 +131,7 @@ int main(int argc, char** argv) flashlight.linear = 0.022f; flashlight.quadratic = 0.0019f; flashlight.angle = 18.0f; - flashlight.outerAngle = 25.0f; + flashlight.outerAngle = 24.9f; while (!glfwWindowShouldClose(window)) { @@ -143,6 +143,8 @@ int main(int argc, char** argv) shader->Use(); + shader->SetUniformMatrix3fv("normal", 1, GL_FALSE, glm::value_ptr(model.GetNormalMatrix())); + shader->SetUniformMatrix4fv("model", 1, GL_FALSE, glm::value_ptr(model.GetMatrix())); shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(camera.GetMatrix())); shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(camera.GetProjection())); @@ -155,6 +157,8 @@ int main(int argc, char** argv) shader->SetUniform("flashlight.quadratic", flashlight.quadratic); model.Render(shader); + + model.Rotate(1.0f, glm::vec3(0.0f, 1.0f, 0.0f)); glfwSwapBuffers(window); glfwPollEvents(); diff --git a/examples/model/shaders/vertexShader.vert b/examples/model/shaders/vertexShader.vert index d6a3e62..ac45c33 100644 --- a/examples/model/shaders/vertexShader.vert +++ b/examples/model/shaders/vertexShader.vert @@ -8,14 +8,16 @@ out vec3 oNormal; out vec2 oUV; out vec3 oFragPos; +uniform mat3 normal; +uniform mat4 model; uniform mat4 view; uniform mat4 projection; void main() { - oNormal = aNormal; + oNormal = normal * aNormal; oUV = aUV; - gl_Position = projection * view * vec4(aPos, 1.0); - oFragPos = aPos; + gl_Position = projection * view * model * vec4(aPos, 1.0); + oFragPos = vec3(model * vec4(aPos, 1.0)); } \ No newline at end of file diff --git a/include/model/model.hpp b/include/model/model.hpp index 7baf097..c9faba4 100644 --- a/include/model/model.hpp +++ b/include/model/model.hpp @@ -5,13 +5,14 @@ #include #include +#include #include #include namespace oglu { - class OGLU_API Model + class OGLU_API Model : public Transformable { public: Model(const std::string& path);