This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/synthetic/SyntheticWalker.h
frank 55061ef0da minor changes to floorplan
fixed some compile issues
worked on nav-meshes
added some tests
2018-01-16 12:41:05 +01:00

84 lines
1.8 KiB
C++

#ifndef SYNTHETICWALKER_H
#define SYNTHETICWALKER_H
#include "SyntheticPath.h"
/** walk along a path using a known walking speed */
class SyntheticWalker {
public:
enum class Type {
FLOOR,
NON_FLOOR,
};
class Listener {
public:
virtual void onWalk(Timestamp walkedTime, float walkedDistance, const Point3 curPos, const Type type) = 0;
};
private:
/** the path to walk along */
SyntheticPath path;
/** walking-speed in meter per sec */
float walkSpeed_meterPerSec = 1.2;
/** adjusted while walking */
float walkedDistance = 0;
/** adjusted while walking */
Timestamp walkedTime;
/** the listener to inform */
std::vector<Listener*> listeners;
const char* name = "SynWalker";
public:
/** ctor */
SyntheticWalker(SyntheticPath path) : path(path) {
;
}
/** attach a new listener */
void addListener(Listener* l) {
this->listeners.push_back(l);
}
bool done() {
return path.doneAtDistance(this->walkedDistance);
}
/** increment the walk */
Point3 tick(const Timestamp timePassed) {
// update time
this->walkedTime += timePassed;
// update the walked distance using the walking speed
this->walkedDistance += walkSpeed_meterPerSec * timePassed.sec();
// get the current position along the path
const Point3 curPosOnPath = path.getPosAfterDistance(this->walkedDistance);
const bool isPlainPart = path.isPlain(this->walkedDistance);
const Type type = (isPlainPart) ? (Type::FLOOR) : (Type::NON_FLOOR);
Log::add(name, "walkTime: " + std::to_string(walkedTime.sec()) + " walkDistance: " + std::to_string(walkedDistance) + " -> " + curPosOnPath.asString() );
// inform listener
for (Listener* l : listeners) {l->onWalk(walkedTime, walkedDistance, curPosOnPath, type);}
return curPosOnPath;
}
};
#endif // SYNTHETICWALKER_H