47 lines
870 B
C++
47 lines
870 B
C++
#include "../include/segment.h"
|
|
#include "../parameters.h"
|
|
|
|
Segment::Segment()
|
|
{
|
|
//ctor
|
|
}
|
|
|
|
|
|
Segment::Segment( uint16_t n_seg )
|
|
{
|
|
wX = 0;
|
|
wY = 0;
|
|
wZ = fixdouble((400 + n_seg * SEGMENT_LENGTH));
|
|
}
|
|
|
|
|
|
Segment::~Segment()
|
|
{
|
|
//dtor
|
|
}
|
|
|
|
|
|
void Segment::Project3DFP( camera* c )
|
|
{
|
|
fixed_t DX = (wX - c->cX);
|
|
fixed_t DY = (wY - c->cY);
|
|
fixed_t divDZ = fdiv( fix(1), (wZ - c->cZ));
|
|
fixed_t RW = fix(ROAD_WIDTH);
|
|
|
|
fixed_t divAR = fdiv(fix(1), fixdouble(ASPECT_RATIO));
|
|
|
|
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);
|
|
|
|
sX=fmul(fix(SCREEN_CX), (fix(1)+tempx));
|
|
sY=fmul(fix(SCREEN_CY), (fix(1)-tempy));
|
|
sW=fmul(fix(SCREEN_CX), tempw);
|
|
|
|
X=fround(sX);
|
|
Y=fround(sY);
|
|
W=fround(sW);
|
|
}
|