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
#include <glm/vec2.hpp>
#include <vector>
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<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;
};
}