diff --git a/src/camera.cpp b/src/camera.cpp new file mode 100644 index 0000000..a457f05 --- /dev/null +++ b/src/camera.cpp @@ -0,0 +1,8 @@ +#include "camera.hpp" + +#include + +glm::mat4 Camera::transformation() const +{ + return projection * glm::inverse(Transformation::transformation()); +} diff --git a/src/camera.hpp b/src/camera.hpp new file mode 100644 index 0000000..1ace04e --- /dev/null +++ b/src/camera.hpp @@ -0,0 +1,15 @@ +#ifndef _CAMERA_HPP_ +#define _CAMERA_HPP_ + +#include "transformation.hpp" + +class Camera : + public Transformation +{ +public: + glm::mat4 transformation() const; + + glm::mat4 projection; +}; + +#endif // _CAMERA_HPP_ diff --git a/src/main.cpp b/src/main.cpp index 93ab383..66d84fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include "gl.hpp" #include "program.hpp" #include "object.hpp" -#include "transformation.hpp" +#include "camera.hpp" #include @@ -25,7 +25,7 @@ static GLuint texture_uniform; static bool keys[GLFW_KEY_LAST]; -static Transformation camera; +static Camera camera; static Model *suzanne; static Model *teapot; @@ -65,6 +65,7 @@ int main() texture_uniform = program.get_uniform_location("texture"); glUniform1i(texture_uniform, 0); + camera.projection = glm::perspective(45.0f, (float)640 / (float)480, 0.1f, 10.0f); camera.position.z = 4; camera.position.y = 2; @@ -145,9 +146,7 @@ void iterate() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - const glm::mat4 projection = glm::perspective(45.0f, (float)640 / (float)480, 0.1f, 10.0f); - - const glm::mat4 mvp = projection * glm::inverse(camera.transformation()); + const glm::mat4 mvp = camera.transformation(); suzanne1->draw(mvp); teapot1->draw(mvp);