KlassischeKeplerKriege/game/state/trace.hpp

60 lines
1.8 KiB
C++
Raw Normal View History

2016-09-27 17:32:12 +00:00
#pragma once
#include <glm/vec2.hpp>
2016-09-27 17:43:40 +00:00
#include <vector>
2016-09-27 17:32:12 +00:00
namespace game {
2016-09-27 17:43:40 +00:00
class Missile;
2016-09-27 21:07:11 +00:00
class Player;
2016-09-27 17:43:40 +00:00
2016-09-27 17:32:12 +00:00
/*
* Trace of a missile through the space.
* Useful for rendering sth. like a smoke trail to follow the rocket.
*/
class Trace {
public:
2016-09-29 09:43:00 +00:00
Trace(Missile *missile, float maxAge=3.0);
2016-09-27 21:07:11 +00:00
~Trace();
2016-09-27 17:43:40 +00:00
// 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);
2016-09-27 20:35:16 +00:00
// 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
2016-09-27 17:43:40 +00:00
/*
* Trace point data to be used when rendering.
*/
struct TracePoint {
TracePoint(const Missile *missile);
2016-09-27 17:32:12 +00:00
glm::vec2 position;
float speed;
2016-09-27 17:43:40 +00:00
};
2016-09-27 17:32:12 +00:00
2016-09-27 17:43:40 +00:00
std::vector<TracePoint> points;
2016-09-27 21:07:11 +00:00
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;
2016-09-27 21:07:11 +00:00
// age of the trace. if too old, it can be removed to save
// space/power
2016-09-29 07:32:56 +00:00
// ageing starts when the trace is finished.
2016-09-27 21:07:11 +00:00
float age;
2016-09-29 07:32:56 +00:00
float maxAge;
2016-09-27 17:32:12 +00:00
};
}