From 07437fac3c79a7061fc586bd77c95781d4512c4c Mon Sep 17 00:00:00 2001 From: Andreas Ortmann Date: Wed, 28 Sep 2016 15:10:57 +0200 Subject: [PATCH] try to get rotation model matrix working. --- game/game.cpp | 10 ++++--- game/renderer_polygon_3d/polygon_model.hpp | 3 ++- .../renderer_polygon_3d.cpp | 26 ++++++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/game/game.cpp b/game/game.cpp index 8931b37..26224b8 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -15,11 +15,16 @@ Game::Game() m_state = new game::State(); m_state->init(); + // XXX + // one dummy ship for testing +#ifdef QUICK_TEST + m_state->addPlayer(); +#endif } bool Game::cycle(float dt) { -#if 0 +#ifdef QUICK_TEST // XXX the following is just testing code to do things static float total = 0.0; @@ -33,12 +38,11 @@ bool Game::cycle(float dt) // m_state->players[0]->addCommand(new game::ShootCommand(a)); // } //} - m_state->addPlayer(); acc += dt; total += dt; - float spawnInterval = 0.1; + float spawnInterval = 1.0; while (acc > spawnInterval) { acc -= spawnInterval; diff --git a/game/renderer_polygon_3d/polygon_model.hpp b/game/renderer_polygon_3d/polygon_model.hpp index 41fc799..70e751b 100644 --- a/game/renderer_polygon_3d/polygon_model.hpp +++ b/game/renderer_polygon_3d/polygon_model.hpp @@ -202,7 +202,8 @@ class PolygonModel { } size_t totalBytes = 3*m_numVertices*sizeof(float); - std::cout<<"[polygonmodel] loaded " << m_numVertices << " vertices (" + std::cout<<"[polygonmodel] loaded file " << m_filename + << " with " << m_numVertices << " vertices (" << totalBytes << " bytes)" << std::endl; return true; diff --git a/game/renderer_polygon_3d/renderer_polygon_3d.cpp b/game/renderer_polygon_3d/renderer_polygon_3d.cpp index 77ec48f..8c35370 100644 --- a/game/renderer_polygon_3d/renderer_polygon_3d.cpp +++ b/game/renderer_polygon_3d/renderer_polygon_3d.cpp @@ -3,6 +3,7 @@ #include #include "glm/gtc/type_ptr.hpp" +#include #include "polygon_model.hpp" @@ -38,6 +39,9 @@ namespace endofthejedi { "}\n" ; + //"uniform mat4 model;\n" + //" vec3 p = position + scale*(model*vec4(gl_Vertex.xyz, 0.0));\n" + std::string vss_game_objects = "#version 120\n" "uniform vec3 position;\n" @@ -45,10 +49,9 @@ namespace endofthejedi { "varying vec3 vertex;\n" "void main()\n" "{\n" - " vec3 p = scale*gl_Vertex.xyz;\n" - " p += position;\n" + " vec3 p = position + scale*gl_Vertex.xyz;\n" " gl_Position = vec4(p, gl_Vertex.w);\n" - " vertex = p;\n" + " vertex = p.xyz;\n" "}\n" ; @@ -85,11 +88,13 @@ namespace endofthejedi { // TODO :Z? + glm::mat4 model(1.0f); + glUniformMatrix3fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model)); + renderPlanets(state); renderShips(state); renderMissiles(state); - //glColor3f(1.0, 0.0, 0.0); //glBegin(GL_QUADS); //glVertex2f(-1.0f, -1.0f); @@ -124,9 +129,18 @@ namespace endofthejedi { glm::vec3 c = glm::vec3(1.0, 1.0, 0.3); const auto &p = missile->position; + glm::mat4 model(1.0f); + + static float a = 0.0; + a += 2.0*M_PI * 0.1; + + model = glm::rotate(model, a, glm::vec3(0.0f, 1.0f, 0.0f)); + glUniform3f(m_shader.location("position"), p.x, p.y, 0.0); glUniform3f(m_shader.location("color"), c.x, c.y, c.z); - glUniform1f(m_shader.location("scale"), 1.0); + glUniform1f(m_shader.location("scale"), 0.05); + + glUniformMatrix3fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model)); m_missileModel->render(); } @@ -151,7 +165,7 @@ namespace endofthejedi { void RendererPolygon3d::addModel(const std::string &filename, PolygonModel **dest) { - std::cout<<"adding a model: " << filename << std::endl; + //std::cout<<"adding a model: " << filename << std::endl; *dest = new PolygonModel(filename); if (!(*dest)->import()) {