Blob Blame Raw

#ifndef TRACK_H
#define TRACK_H


#include <cmath>
#include <vector>

#include <string>


typedef double Real;

class Vector3 {
public:
    union {
        struct { Real x, y, z; };
        struct { Real r, g, b; };
        struct { Real c[3]; };
    };
    
    explicit Vector3(Real x = 0, Real y = 0, Real z = 0):
        x(x), y(y), z(z) { }
};


class Vector4 {
public:
    union {
        struct { Real x, y, z, w; };
        struct { Real r, g, b, a; };
        struct { Real c[4]; };
    };
    
    explicit Vector4(Real x = 0, Real y = 0, Real z = 0, Real w = 0):
        x(x), y(y), z(z), w(w) { }
};



class Point {
public:
    Vector3 position;
    Real angle;
    Real speed;

    Real l;
    Real time;
    Real length;
    Real duration;
    Vector3 real_pos;
    
    Point(): angle(), speed(), l(), time(), length() { }

    static Vector3 calc_real_pos(const Point &point) {
        Real a = point.angle*(M_PI/180);
        Real s = sin(a);
        Real c = cos(a);
        return Vector3(
            point.position.x,
            point.position.y*c - point.position.z*s,
            point.position.y*s + point.position.z*c );
    }
    
    static Point median(Real l, const Point &p0, const Point &p1) {
        Real k = 1 - l;
        Point p;
        p.position.x = p0.position.x*k + p1.position.x*l;
        p.position.y = p0.position.y*k + p1.position.y*l;
        p.position.z = p0.position.z*k + p1.position.z*l;
        p.angle      = p0.angle     *k + p1.angle     *l;
        p.speed      =                   p1.speed       ;
        p.l          = p0.l         *k + p1.l         *l;
        p.time       = p0.time      *k + p1.time      *l;
        p.length     =                   p1.length    *l;
        p.duration   =                   p1.duration  *l;
        p.real_pos.x = p0.real_pos.x*k + p1.real_pos.x*l;
        p.real_pos.y = p0.real_pos.y*k + p1.real_pos.y*l;
        p.real_pos.z = p0.real_pos.z*k + p1.real_pos.z*l;
        return p;
    }
};

typedef std::vector<Point> PointList;

class Track {
public:
    PointList points;

    void split(Real da, Real dl, Real dt);
    void calc_length();
    
    int index_by_l(Real l) const;
    int index_by_time(Real t) const;
};


#endif