added trace implemention

This commit is contained in:
Andreas Ortmann 2016-09-27 19:43:40 +02:00
parent 64428d2068
commit 1b6c8d4fba
2 changed files with 41 additions and 9 deletions

View file

@ -0,0 +1,22 @@
#include "trace.hpp"
#include <glm/gtx/norm.hpp>
#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));
}
}

View file

@ -1,24 +1,34 @@
#pragma once #pragma once
#include <glm/vec2.hpp> #include <glm/vec2.hpp>
#include <vector>
namespace game { namespace game {
class Missile;
/* /*
* Trace of a missile through the space. * Trace of a missile through the space.
* Useful for rendering sth. like a smoke trail to follow the rocket. * Useful for rendering sth. like a smoke trail to follow the rocket.
*/ */
class Trace { class Trace {
public: public:
Trace(const glm::vec2 &startPoint) Trace(const Missile *missile);
{
points.push_back(startPoint);
}
void addPoint(const glm::vec2 &p) // TODO: add velocity of the rocket or age at the points too becasue
{ // that enables nice rendering of speed etc. at different points
points.push_back(p); // TODO: give missile to this
} void addPointFromMissile(const Missile *missile);
std::vector<glm::vec2> points; /*
* Trace point data to be used when rendering.
*/
struct TracePoint {
TracePoint(const Missile *missile);
const glm::vec2 position;
const float speed;
};
std::vector<TracePoint> points;
}; };
} }