From 3b5b5da02f7b09596f83e13085c4f3da6b61636a Mon Sep 17 00:00:00 2001 From: Andreas Ortmann Date: Wed, 28 Sep 2016 15:22:16 +0200 Subject: [PATCH] rotations working :) --- game/game.cpp | 4 +++- .../renderer_polygon_3d.cpp | 24 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/game/game.cpp b/game/game.cpp index 26224b8..b8da6a7 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -6,6 +6,8 @@ #include +#define QUICK_TEST + Game::Game() { // advance simulation in fixed steps with 100 Hz @@ -46,7 +48,7 @@ bool Game::cycle(float dt) while (acc > spawnInterval) { acc -= spawnInterval; - float angle = 2.0 * M_PI * util::randf_0_1(); + float angle = 360.0 * util::randf_0_1(); float speed = 0.005; m_state->players[0]->addCommand(new game::SetSpeedCommand(speed)); diff --git a/game/renderer_polygon_3d/renderer_polygon_3d.cpp b/game/renderer_polygon_3d/renderer_polygon_3d.cpp index 8c35370..7f54c85 100644 --- a/game/renderer_polygon_3d/renderer_polygon_3d.cpp +++ b/game/renderer_polygon_3d/renderer_polygon_3d.cpp @@ -39,18 +39,17 @@ 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" "uniform float scale;\n" "varying vec3 vertex;\n" + "uniform mat4 model;\n" "void main()\n" "{\n" - " vec3 p = position + scale*gl_Vertex.xyz;\n" - " gl_Position = vec4(p, gl_Vertex.w);\n" + //" vec3 p = position + scale*gl_Vertex.xyz;\n" + " vec3 p = position + scale*(model*gl_Vertex).xyz;\n" + " gl_Position = vec4(p, 1.0);\n" " vertex = p.xyz;\n" "}\n" ; @@ -88,9 +87,6 @@ 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); @@ -112,6 +108,9 @@ namespace endofthejedi { glm::vec3 c = glm::vec3(0.7, 0.2, 0.1); const auto &p = planet->position; + glm::mat4 model(1.0f); + glUniformMatrix4fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model)); + 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"), planet->radius); @@ -132,15 +131,15 @@ namespace endofthejedi { glm::mat4 model(1.0f); static float a = 0.0; - a += 2.0*M_PI * 0.1; + a += 2.0*M_PI * 0.01; - model = glm::rotate(model, a, glm::vec3(0.0f, 1.0f, 0.0f)); + model = glm::rotate(model, a, glm::vec3(0.0f, 0.0f, 1.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"), 0.05); - glUniformMatrix3fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model)); + glUniformMatrix4fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model)); m_missileModel->render(); } @@ -155,6 +154,9 @@ namespace endofthejedi { glm::vec3 c = glm::vec3(0.1, 1.0, 0.2); const auto &p = ship->position; + glm::mat4 model(1.0f); + glUniformMatrix4fv(m_shader.location("model"), 1, GL_FALSE, glm::value_ptr(model)); + 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"), 0.02);