|
|
57bda0 |
|
|
|
57bda0 |
#ifndef TRACK_H
|
|
|
57bda0 |
#define TRACK_H
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
57bda0 |
#include <cmath></cmath>
|
|
|
57bda0 |
#include <vector></vector>
|
|
|
57bda0 |
|
|
|
57bda0 |
#include <string></string>
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
57bda0 |
typedef double Real;
|
|
|
57bda0 |
|
|
|
57bda0 |
class Vector3 {
|
|
|
57bda0 |
public:
|
|
|
57bda0 |
union {
|
|
|
57bda0 |
struct { Real x, y, z; };
|
|
|
57bda0 |
struct { Real r, g, b; };
|
|
|
57bda0 |
struct { Real c[3]; };
|
|
|
57bda0 |
};
|
|
|
57bda0 |
|
|
|
57bda0 |
explicit Vector3(Real x = 0, Real y = 0, Real z = 0):
|
|
|
57bda0 |
x(x), y(y), z(z) { }
|
|
|
57bda0 |
};
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
57bda0 |
class Vector4 {
|
|
|
57bda0 |
public:
|
|
|
57bda0 |
union {
|
|
|
57bda0 |
struct { Real x, y, z, w; };
|
|
|
57bda0 |
struct { Real r, g, b, a; };
|
|
|
57bda0 |
struct { Real c[4]; };
|
|
|
57bda0 |
};
|
|
|
57bda0 |
|
|
|
57bda0 |
explicit Vector4(Real x = 0, Real y = 0, Real z = 0, Real w = 0):
|
|
|
57bda0 |
x(x), y(y), z(z), w(w) { }
|
|
|
57bda0 |
};
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
57bda0 |
class Point {
|
|
|
57bda0 |
public:
|
|
|
57bda0 |
Vector3 position;
|
|
|
57bda0 |
Real angle;
|
|
|
57bda0 |
Real speed;
|
|
|
57bda0 |
|
|
|
57bda0 |
Real l;
|
|
|
57bda0 |
Real time;
|
|
|
57bda0 |
Real length;
|
|
|
57bda0 |
Real duration;
|
|
|
57bda0 |
Vector3 real_pos;
|
|
|
57bda0 |
|
|
|
57bda0 |
Point(): angle(), speed(), l(), time(), length() { }
|
|
|
57bda0 |
|
|
|
57bda0 |
static Vector3 calc_real_pos(const Point &point) {
|
|
|
57bda0 |
Real a = point.angle*(M_PI/180);
|
|
|
57bda0 |
Real s = sin(a);
|
|
|
57bda0 |
Real c = cos(a);
|
|
|
57bda0 |
return Vector3(
|
|
|
57bda0 |
point.position.x,
|
|
|
57bda0 |
point.position.y*c - point.position.z*s,
|
|
|
57bda0 |
point.position.y*s + point.position.z*c );
|
|
|
57bda0 |
}
|
|
|
57bda0 |
|
|
|
57bda0 |
static Point median(Real l, const Point &p0, const Point &p1) {
|
|
|
57bda0 |
Real k = 1 - l;
|
|
|
57bda0 |
Point p;
|
|
|
57bda0 |
p.position.x = p0.position.x*k + p1.position.x*l;
|
|
|
57bda0 |
p.position.y = p0.position.y*k + p1.position.y*l;
|
|
|
57bda0 |
p.position.z = p0.position.z*k + p1.position.z*l;
|
|
|
57bda0 |
p.angle = p0.angle *k + p1.angle *l;
|
|
|
57bda0 |
p.speed = p1.speed ;
|
|
|
57bda0 |
p.l = p0.l *k + p1.l *l;
|
|
|
57bda0 |
p.time = p0.time *k + p1.time *l;
|
|
|
57bda0 |
p.length = p1.length *l;
|
|
|
57bda0 |
p.duration = p1.duration *l;
|
|
|
57bda0 |
p.real_pos.x = p0.real_pos.x*k + p1.real_pos.x*l;
|
|
|
57bda0 |
p.real_pos.y = p0.real_pos.y*k + p1.real_pos.y*l;
|
|
|
57bda0 |
p.real_pos.z = p0.real_pos.z*k + p1.real_pos.z*l;
|
|
|
57bda0 |
return p;
|
|
|
57bda0 |
}
|
|
|
57bda0 |
};
|
|
|
57bda0 |
|
|
|
57bda0 |
typedef std::vector<point> PointList;</point>
|
|
|
57bda0 |
|
|
|
57bda0 |
class Track {
|
|
|
57bda0 |
public:
|
|
|
57bda0 |
PointList points;
|
|
|
57bda0 |
|
|
|
57bda0 |
void split(Real da, Real dl, Real dt);
|
|
|
57bda0 |
void calc_length();
|
|
|
57bda0 |
|
|
|
57bda0 |
int index_by_l(Real l) const;
|
|
|
57bda0 |
int index_by_time(Real t) const;
|
|
|
57bda0 |
};
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
57bda0 |
#endif
|