From 2b85397674216977526f853c5af0dd083213c4cf Mon Sep 17 00:00:00 2001 From: Andreas Ortmann Date: Tue, 27 Sep 2016 20:23:33 +0200 Subject: [PATCH] traces working and nice (on simple renderer) --- game/game.cpp | 2 +- game/game_window.hpp | 16 +++++++++++++++- game/opengl.cpp | 2 +- game/renderer.cpp | 16 ++++++++-------- game/state/trace.cpp | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/game/game.cpp b/game/game.cpp index 36ffc64..38fcc0c 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -32,7 +32,7 @@ bool Game::cycle(float dt) acc -= spawnInterval; float a = 2.0 * M_PI * util::randf_0_1(); - float speed = 0.002; + float speed = 0.005; m_state->players[0]->addCommand(new game::ShootCommand(a, speed)); } diff --git a/game/game_window.hpp b/game/game_window.hpp index b3072ce..8bd7c4f 100644 --- a/game/game_window.hpp +++ b/game/game_window.hpp @@ -5,6 +5,7 @@ #include "game.hpp" +#include "state/trace.hpp" #include "state/object.hpp" #include "state/missile.hpp" #include "state/player.hpp" @@ -41,6 +42,10 @@ protected: drawPlanet(planet->position, planet->radius); } + for (const game::Trace *trace : m_game.state()->traces) { + drawTrace(trace); + } + for (const game::Ship *ship : m_game.state()->ships) { drawShip(ship->position); } @@ -73,9 +78,18 @@ protected: } void drawMissile(const glm::vec2 &pos) + { glm::vec3 color = glm::vec3(1.0, 1.0, 0.3); - m_renderer.drawCircle(pos.x, pos.y, 0.005, color.x, color.y, color.z, 5); + m_renderer.drawCircle(pos.x, pos.y, 0.01, color.x, color.y, color.z, 6); + } + + void drawTrace(const game::Trace *trace) + { + for (const game::Trace::TracePoint &p : trace->points) { + glm::vec3 color = glm::vec3(0.1, 0.3, 1.0) / (1.0f + 500.0f*p.speed); + m_renderer.drawCircle(p.position.x, p.position.y, 0.005, color.x, color.y, color.z, 3); + } } public: diff --git a/game/opengl.cpp b/game/opengl.cpp index 7eecce7..fde9da1 100644 --- a/game/opengl.cpp +++ b/game/opengl.cpp @@ -130,7 +130,7 @@ void endofthejedi::GLWindow::loop() { prev = current; if(delta > 0.0) { m_fps = (1000000000.0/delta); - std::cout << m_fps << "\n"; + //std::cout << m_fps << "\n"; } } } diff --git a/game/renderer.cpp b/game/renderer.cpp index 862b9f3..6a7b4ba 100644 --- a/game/renderer.cpp +++ b/game/renderer.cpp @@ -6,13 +6,13 @@ endofthejedi::Renderer::Renderer() { endofthejedi::Renderer::~Renderer() {} -void endofthejedi::Renderer::drawCircle(float x, float y, float radius, float r, - float g, float b, int numSides) { - glBegin(GL_TRIANGLE_FAN); - glVertex2f(x, y); // center of circle - for (int i = 0; i <= numSides; i++) { +void endofthejedi::Renderer::drawCircle(float x, float y, float radius, float r, float g, float b, int numSides) +{ + glBegin(GL_TRIANGLE_FAN); glColor3f(r,g,b); - glVertex2f(x + (radius * cos(i * 2 * M_PI / numSides)), y + (radius * sin(i * 2 * M_PI / numSides))); - } - glEnd(); + glVertex2f(x, y); // center of circle + for (int i = 0; i <= numSides; i++) { + glVertex2f(x + (radius * cos(i * 2 * M_PI / numSides)), y + (radius * sin(i * 2 * M_PI / numSides))); + } + glEnd(); } diff --git a/game/state/trace.cpp b/game/state/trace.cpp index 1509967..4d93d2c 100644 --- a/game/state/trace.cpp +++ b/game/state/trace.cpp @@ -19,7 +19,7 @@ namespace game { void Trace::addPointFromMissile(bool forceAdd) { fidelityCounter++; - if (forceAdd || fidelityCounter >= 20) { + if (forceAdd || fidelityCounter >= 10) { fidelityCounter = 0; points.push_back(TracePoint(missile)); }