KlassischeKeplerKriege/game/state/trace.hpp
2016-09-27 23:07:11 +02:00

56 lines
1.7 KiB
C++

#pragma once
#include <glm/vec2.hpp>
#include <vector>
namespace game {
class Missile;
class Player;
/*
* Trace of a missile through the space.
* Useful for rendering sth. like a smoke trail to follow the rocket.
*/
class Trace {
public:
Trace(Missile *missile);
~Trace();
// Add the current position of the missile as a new point on the
// trace.
// Parameters:
// forceAdd: set to true to add this point (good for the endpoint of
// the missile) in case the fidelityCounter would skip the current position.
void addPointFromMissile(bool forceAdd=false);
// call this to mark the trace as finish and disconnect it from the
// missile.
void finish();
// TODO: add extendLastPointToPosition() method for saving points /
// optimization later on
/*
* Trace point data to be used when rendering.
*/
struct TracePoint {
TracePoint(const Missile *missile);
glm::vec2 position;
float speed;
};
std::vector<TracePoint> points;
Missile *missile; // missile which creates this path.
Player *player;
// counter which is incremented each time addPointFromMissile() is called.
// when reaching a certain value the point is saved for
// optimization.
int fidelityCounter;
// age of the trace. if too old, it can be removed to save
// space/power
float age;
};
}