#include "../include/cars.h"
#include "../include/camera.h"

#include <stdint.h>
#include <vector>
#include "../include/segment.h"
#include "../parameters.h"
#include "../include/circuit.h"


extern std::vector<Segment*> circuit;


Cars::Cars()
{
    //ctor
}

Cars::~Cars()
{
    //dtor
}

Cars::Cars( float x, double z, uint8_t s, uint8_t t )
{
    wX = x;
    wZ = z;
    Speed = s;
    Type = t;
    X = 0;
}


void Cars::Project3DFP( camera* c, uint16_t index )
{
    fixed_t DX = fix(wX*ROAD_WIDTH) - c->cX;
    fixed_t DY = interpolatePositionY(wZ) - c->cY;

    fixed_t divDZ = fdiv( fix(1), (fixdouble(wZ) - c->cZ));
    fixed_t divAR = fdiv(fix(1), fixdouble(ASPECT_RATIO));
    fixed_t Scale = fmul(fixdouble(DISTANCE_SCREEN), divDZ);

    fixed_t tempx = fmul(fmul(DX,Scale), divAR);
    fixed_t tempy = fmul(DY, Scale);

    fixed_t sX=fmul(fix(SCREEN_CX), (fix(1)+tempx));
    fixed_t sY=fmul(fix(SCREEN_CY), (fix(1)-tempy));

    X = fround(sX) + circuit[ index ]->CumulatedCurve;
    Y = fround(sY);
}


