From: Daniel Karbach Date: Thu, 12 Feb 2015 16:39:44 +0000 (+0100) Subject: begun extracting model class X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=d18be10ef3f0a7b61c6f5c4c4096ca2b776c75b3;p=blank.git begun extracting model class --- diff --git a/src/app.cpp b/src/app.cpp index 7ecbb74..038aa1a 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -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); diff --git a/src/app.hpp b/src/app.hpp index e525ec6..4e381a2 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -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 index 0000000..4ee621a --- /dev/null +++ b/src/model.cpp @@ -0,0 +1,26 @@ +#include "model.hpp" + +#include +#include +#include + + +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 index 0000000..c0bda41 --- /dev/null +++ b/src/model.hpp @@ -0,0 +1,35 @@ +#ifndef BLANK_MODEL_HPP_ +#define BLANK_MODEL_HPP_ + +#include + + +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