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,
};
}
, init_glew()
, program()
, cam()
+, model()
, vtx_buf(0)
, mvp_handle(0)
, running(false) {
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);
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);
--- /dev/null
+#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);
+}
+
+}
--- /dev/null
+#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