OutRun/src/src/segment.cc

70 lines
1.2 KiB
C++

#include "../include/segment.h"
#include "../parameters.h"
Segment::Segment()
{
//ctor
}
Segment::Segment( uint16_t n_seg )
{
wX = 0;
wY = 0;
wZ = (double) (400.0 + (double) (n_seg * SEGMENT_LENGTH));
}
Segment::Segment( int16_t x, int16_t y, double z, int8_t c )
{
wX = x;
wY = y;
wZ = z;
Curve = c;
LDeco = -1;
RDeco = -1;
}
Segment::Segment( int16_t x, int16_t y, double z, int8_t c, int8_t left, int8_t right )
{
wX = x;
wY = y;
wZ = z;
Curve = c;
LDeco = left;
RDeco = right;
}
Segment::~Segment()
{
//dtor
}
void Segment::Project3DFP( camera* c )
{
fixed_t DX = (fix(wX) - c->cX);
fixed_t DY = (fix(wY) - c->cY);
fixed_t divDZ = fdiv( fix(1), (fixdouble(wZ) - c->cZ));
fixed_t RW = fix(ROAD_WIDTH);
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 tempw = fmul(fmul(RW,Scale), divAR);
fixed_t sX=fmul(fix(SCREEN_CX), (fix(1)+tempx));
fixed_t sY=fmul(fix(SCREEN_CY), (fix(1)-tempy));
fixed_t sW=fmul(fix(SCREEN_CX), tempw);
X=fround(sX);
Y=fround(sY);
W=fround(sW);
}