]> git.localhorst.tv Git - blank.git/commitdiff
begun extracting model class
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 12 Feb 2015 16:39:44 +0000 (17:39 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 12 Feb 2015 19:44:28 +0000 (20:44 +0100)
src/app.cpp
src/app.hpp
src/model.cpp [new file with mode: 0644]
src/model.hpp [new file with mode: 0644]

index 7ecbb744ac65ce5be365e8548fac7ef13788a275..038aa1aebbcd16a7ad4a1ae4a50830e4b41b59d1 100644 (file)
@@ -7,9 +7,9 @@
 namespace {
 
 constexpr GLfloat vtx_coords[] = {
-       -1.0f, -1.0f, -5.0f,
-        1.0f, -1.0f, -5.0f,
-        0.0f,  1.0f, -5.0f,
+       -1.0f, -1.0f, 0.0f,
+        1.0f, -1.0f, 0.0f,
+        0.0f,  1.0f, 0.0f,
 };
 
 }
@@ -25,6 +25,7 @@ Application::Application()
 , init_glew()
 , program()
 , cam()
+, model()
 , vtx_buf(0)
 , mvp_handle(0)
 , running(false) {
@@ -61,6 +62,8 @@ Application::Application()
        glBindBuffer(GL_ARRAY_BUFFER, vtx_buf);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vtx_coords), vtx_coords, GL_STATIC_DRAW);
 
+       model.Position(glm::vec3(0, 0, -4));
+
        mvp_handle = program.UniformLocation("MVP");
 
        glClearColor(0.0, 0.0, 0.0, 1.0);
@@ -115,8 +118,7 @@ void Application::Render() {
 
        program.Use();
 
-       glm::mat4 model(1.0f); // identity: no transformation
-       glm::mat4 mvp(cam.MakeMVP(model));
+       glm::mat4 mvp(cam.MakeMVP(model.Transform()));
        glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &mvp[0][0]);
 
        glEnableVertexAttribArray(0);
index e525ec632e6459a8612539b6807cfad32549b89c..4e381a2a2fa6d7e388ab3884ad7dc33f0227eaf5 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "camera.hpp"
 #include "init.hpp"
+#include "model.hpp"
 #include "shader.hpp"
 
 
@@ -36,6 +37,7 @@ private:
        Program program;
 
        Camera cam;
+       Model model;
 
        GLuint vtx_buf;
        GLuint mvp_handle;
diff --git a/src/model.cpp b/src/model.cpp
new file mode 100644 (file)
index 0000000..4ee621a
--- /dev/null
@@ -0,0 +1,26 @@
+#include "model.hpp"
+
+#include <glm/gtc/matrix_transform.hpp>
+#include <glm/gtx/euler_angles.hpp>
+#include <glm/gtx/transform.hpp>
+
+
+namespace blank {
+
+Model::Model()
+: position(0, 0, 0)
+, pitch(0)
+, yaw(0) {
+
+}
+
+Model::~Model() {
+
+}
+
+
+glm::mat4 Model::Transform() const {
+       return glm::translate(position) * glm::eulerAngleYX(yaw, pitch);
+}
+
+}
diff --git a/src/model.hpp b/src/model.hpp
new file mode 100644 (file)
index 0000000..c0bda41
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef BLANK_MODEL_HPP_
+#define BLANK_MODEL_HPP_
+
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class Model {
+
+public:
+       Model();
+       ~Model();
+
+       glm::mat4 Transform() const;
+
+       void Position(glm::vec3 pos) { position = pos; }
+       void Move(glm::vec3 delta) { position += delta; }
+
+       // all angles in radians (full circle = 2π)
+       void Pitch(float p) { pitch = p; }
+       void RotatePitch(float delta) { pitch += delta; }
+       void Yaw(float y) { yaw = y; }
+       void RotateYaw(float delta) { yaw += delta; }
+
+private:
+       glm::vec3 position;
+       float pitch;
+       float yaw;
+
+};
+
+}
+
+#endif