OutRun/src/src/segment.cc

74 lines
1.3 KiB
C++
Raw Normal View History

2022-03-04 21:58:14 +01:00
#include "../include/segment.h"
#include "../parameters.h"
Segment::Segment()
{
//ctor
}
Segment::Segment( uint16_t n_seg )
{
wX = 0;
wY = 0;
2022-03-11 22:44:47 +01:00
wZ = (double) (n_seg * SEGMENT_LENGTH);
Curve = 0;
Slope = 0;
2022-03-06 20:21:22 +01:00
}
2022-03-11 22:44:47 +01:00
Segment::Segment( int16_t x, int16_t y, double z, int8_t c, int8_t s )
2022-03-06 20:21:22 +01:00
{
wX = x;
wY = y;
wZ = z;
Curve = c;
2022-03-11 22:44:47 +01:00
Slope = s;
2022-03-06 22:06:48 +01:00
LDeco = -1;
RDeco = -1;
2022-03-06 20:21:22 +01:00
}
2022-03-11 22:44:47 +01:00
Segment::Segment( int16_t x, int16_t y, double z, int8_t c, int8_t s, int8_t left, int8_t right )
2022-03-06 20:21:22 +01:00
{
wX = x;
wY = y;
wZ = z;
Curve = c;
2022-03-11 22:44:47 +01:00
Slope = s;
2022-03-06 22:06:48 +01:00
LDeco = left;
2022-03-06 20:21:22 +01:00
RDeco = right;
2022-03-04 21:58:14 +01:00
}
Segment::~Segment()
{
//dtor
}
void Segment::Project3DFP( camera* c )
{
2022-03-06 20:21:22 +01:00
fixed_t DX = (fix(wX) - c->cX);
fixed_t DY = (fix(wY) - c->cY);
fixed_t divDZ = fdiv( fix(1), (fixdouble(wZ) - c->cZ));
2022-03-04 21:58:14 +01:00
fixed_t RW = fix(ROAD_WIDTH);
fixed_t divAR = fdiv(fix(1), fixdouble(ASPECT_RATIO));
2022-03-06 20:21:22 +01:00
fixed_t Scale = fmul(fixdouble(DISTANCE_SCREEN), divDZ);
2022-03-04 21:58:14 +01:00
fixed_t tempx = fmul(fmul(DX,Scale), divAR);
fixed_t tempy = fmul(DY, Scale);
fixed_t tempw = fmul(fmul(RW,Scale), divAR);
2022-03-06 20:21:22 +01:00
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);
2022-03-04 21:58:14 +01:00
X=fround(sX);
Y=fround(sY);
W=fround(sW);
}