From 1b6c8d4fbac2f872653480fdb0f1a38cdb92ee5f Mon Sep 17 00:00:00 2001 From: Andreas Ortmann Date: Tue, 27 Sep 2016 19:43:40 +0200 Subject: [PATCH] added trace implemention --- game/state/trace.cpp | 22 ++++++++++++++++++++++ game/state/trace.hpp | 28 +++++++++++++++++++--------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/game/state/trace.cpp b/game/state/trace.cpp index e69de29..16f6a4f 100644 --- a/game/state/trace.cpp +++ b/game/state/trace.cpp @@ -0,0 +1,22 @@ +#include "trace.hpp" + +#include + +#include "missile.hpp" + +namespace game { + Trace::TracePoint::TracePoint(const Missile *missile) + : position(missile->position), speed(glm::length(missile->velocity)) + { + } + + Trace::Trace(const Missile *missile) + { + points.push_back(TracePoint(missile)); + } + + void Trace::addPointFromMissile(const Missile *missile) + { + points.push_back(TracePoint(missile)); + } +} diff --git a/game/state/trace.hpp b/game/state/trace.hpp index 5c7f050..0ceb0b3 100644 --- a/game/state/trace.hpp +++ b/game/state/trace.hpp @@ -1,24 +1,34 @@ #pragma once #include +#include namespace game { + class Missile; + /* * Trace of a missile through the space. * Useful for rendering sth. like a smoke trail to follow the rocket. */ class Trace { public: - Trace(const glm::vec2 &startPoint) - { - points.push_back(startPoint); - } + Trace(const Missile *missile); - void addPoint(const glm::vec2 &p) - { - points.push_back(p); - } + // TODO: add velocity of the rocket or age at the points too becasue + // that enables nice rendering of speed etc. at different points + // TODO: give missile to this + void addPointFromMissile(const Missile *missile); - std::vector points; + /* + * Trace point data to be used when rendering. + */ + struct TracePoint { + TracePoint(const Missile *missile); + + const glm::vec2 position; + const float speed; + }; + + std::vector points; }; }