KlassischeKeplerKriege/game/state/trace.cpp
2016-09-29 09:32:56 +02:00

45 lines
949 B
C++

#include "trace.hpp"
#include <glm/gtx/norm.hpp>
#include "missile.hpp"
#include <iostream>
namespace game {
Trace::TracePoint::TracePoint(const Missile *missile)
: position(missile->position)
, speed(glm::length(missile->velocity))
{
}
Trace::Trace(Missile *missile, float maxAge)
: missile(missile)
, player(missile->player)
, fidelityCounter(0)
, age(0.0)
, maxAge(maxAge)
{
points.push_back(TracePoint(missile));
}
Trace::~Trace()
{
//std::cout<<"~Trace()" << std::endl;
}
void Trace::addPointFromMissile(bool forceAdd)
{
fidelityCounter++;
if (forceAdd || fidelityCounter >= 20) {
fidelityCounter = 0;
points.push_back(TracePoint(missile));
}
}
void Trace::finish()
{
//std::cout<<"trace finished now!" << std::endl;
missile = nullptr;
}
}