diff --git a/CMakeLists.txt b/CMakeLists.txt index bf91817..c4a6318 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,14 +19,18 @@ set(SOURCES ) set(ASSETS_cg -# assets-cg/traffic/car1.png -# assets-cg/traffic/car2.png -# assets-cg/traffic/car3.png -# assets-cg/traffic/car4.png -# assets-cg/traffic/car5.png -# assets-cg/traffic/car6.png -# assets-cg/traffic/car7.png -# assets-cg/traffic/car8.png + assets-cg/traffic/car1.png + assets-cg/traffic/car2.png + assets-cg/traffic/car3.png + assets-cg/traffic/car4.png + assets-cg/traffic/car5.png + assets-cg/traffic/car6.png + assets-cg/traffic/car7.png + assets-cg/traffic/car8.png + assets-cg/trees/tree1.png + assets-cg/trees/tree2.png + assets-cg/trees/tree3.png + assets-cg/player/player.png ) fxconv_declare_assets(${ASSETS_cg} WITH_METADATA) @@ -37,6 +41,6 @@ target_link_libraries(myaddin LibProf::LibProf Gint::Gint -lustl -lc) target_link_options(myaddin PRIVATE -Wl,-Map=Build_Addin.map) if("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) - generate_g3a(TARGET myaddin OUTPUT "OutRunFP.g3a" VERSION 00.100.0000 + generate_g3a(TARGET myaddin OUTPUT "OutRunFP.g3a" VERSION 00.150.0000 NAME "OutRunFP" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png) endif() diff --git a/CppOutRun.layout b/CppOutRun.layout index 03b2e38..c7a55ba 100644 --- a/CppOutRun.layout +++ b/CppOutRun.layout @@ -2,44 +2,14 @@ - + - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + @@ -47,4 +17,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets-cg/player/fxconv-metadata.txt b/assets-cg/player/fxconv-metadata.txt new file mode 100644 index 0000000..7e05b58 --- /dev/null +++ b/assets-cg/player/fxconv-metadata.txt @@ -0,0 +1,5 @@ +*.png: + type: bopti-image + profile: p4 + name_regex: (.*)\.png \1 + diff --git a/assets-cg/player/player.png b/assets-cg/player/player.png new file mode 100644 index 0000000..a6690fb Binary files /dev/null and b/assets-cg/player/player.png differ diff --git a/assets-cg/trees/fxconv-metadata.txt b/assets-cg/trees/fxconv-metadata.txt new file mode 100644 index 0000000..7e05b58 --- /dev/null +++ b/assets-cg/trees/fxconv-metadata.txt @@ -0,0 +1,5 @@ +*.png: + type: bopti-image + profile: p4 + name_regex: (.*)\.png \1 + diff --git a/assets-cg/trees/tree1.png b/assets-cg/trees/tree1.png new file mode 100644 index 0000000..0d09464 Binary files /dev/null and b/assets-cg/trees/tree1.png differ diff --git a/assets-cg/trees/tree2.png b/assets-cg/trees/tree2.png new file mode 100644 index 0000000..f9c50af Binary files /dev/null and b/assets-cg/trees/tree2.png differ diff --git a/assets-cg/trees/tree3.png b/assets-cg/trees/tree3.png new file mode 100644 index 0000000..8f0e971 Binary files /dev/null and b/assets-cg/trees/tree3.png differ diff --git a/src/fixed.h b/src/fixed.h index 3568d11..e4b00e3 100644 --- a/src/fixed.h +++ b/src/fixed.h @@ -3,9 +3,8 @@ //--- #pragma once #include -typedef int64_t fixed_t; -//extended from initial int32_t +typedef int64_t fixed_t; /* Standard arithmetic. */ static inline fixed_t fmul(fixed_t left, fixed_t right) @@ -24,7 +23,7 @@ static inline fixed_t fdiv(fixed_t left, fixed_t right) #define fix(x) ((int)((x) * 65536)) -static inline fixed_t fixdouble(long double constant) +static inline fixed_t fixdouble(double constant) { return (fixed_t)(constant * 65536); } diff --git a/src/include/circuit.h b/src/include/circuit.h index 6816b7f..7e3938a 100644 --- a/src/include/circuit.h +++ b/src/include/circuit.h @@ -1,4 +1,41 @@ #include +#include "../fixed.h" + +enum Length +{ + L_VERYSHORT = 50, + L_SHORT = 100, + L_MEDIUM = 200, + L_LONG = 400, + L_VERYLONG = 1000 +}; + +enum HillSize +{ + H_SMALL = 10, + H_MEDIUM = 20, + H_BIG = 40 +}; + +enum HillType +{ + UP_HILL = +1, + DOWN_HILL = -1 +}; + +enum CurveStrength +{ + C_EASY = 2, + C_MEDIUM = 4, + C_HARD = 6 +}; + +enum CurveType +{ + LEFT_CURVE = -1, + RIGHT_CURVE = +1 +}; + void initData( void ); void createCircuit( void ); @@ -10,3 +47,11 @@ void printCircuit( void ); void printCircuit( int i ); void drawCircuitSegment( uint16_t index ); + +void addStraightLine( Length l ); +void addCurve( Length l, CurveStrength s, CurveType t ); +void addHill( Length l, HillSize s, HillType t ); + +fixed_t interpolatePositionX( double currentZ ); +fixed_t interpolatePositionY( double currentZ ); + diff --git a/src/include/drawstuff.h b/src/include/drawstuff.h index 5bb4992..fabdac5 100644 --- a/src/include/drawstuff.h +++ b/src/include/drawstuff.h @@ -2,8 +2,8 @@ #include void gint_dhline(int x1, int x2, int y, uint16_t color); -void drawPolygon( int x1min, int x1max, int y1, int x2min, int x2max, int y2, uint8_t R, uint8_t G, uint8_t B, uint8_t A ); -void drawGrass( int y1, int y2, uint8_t R, uint8_t G, uint8_t B, uint8_t A ); +void drawPolygon( int x1min, int x1max, int y1, int x2min, int x2max, int y2, uint8_t R, uint8_t G, uint8_t B ); +void drawGrass( int y1, int y2, uint8_t R, uint8_t G, uint8_t B ); void drawSky( void ); void drawSky( int ymin, int ymax ); diff --git a/src/include/segment.h b/src/include/segment.h index c6e507a..501445a 100644 --- a/src/include/segment.h +++ b/src/include/segment.h @@ -10,17 +10,29 @@ class Segment public: Segment(); Segment( uint16_t n_seg ); + Segment( int16_t x, int16_t y, double z, int8_t c ); + Segment( int16_t x, int16_t y, double z, int8_t c, int8_t left, int8_t right ); ~Segment(); void Project3DFP( camera* c ); - uint16_t Index=0; - uint8_t Curve=0; - fixed_t wX=0, wY=0, wZ=0; - fixed_t sX=0, sY=0, sW=0; - fixed_t Scale=0; - int X=0,Y=0,W=0; + int8_t Curve=0; + int16_t CumulatedCurve=0; + + // World Coordinates (X,Y,Z) + int16_t wX=0; + int16_t wY=0; + double wZ=0.0; + + // Screen Coordinates (X, Y) + width of the projected Road + int16_t X=0; + int16_t Y=0; + int16_t W=0; + + // Decorations on the Road (Left and Right) + int8_t Ldeco=0; + int8_t RDeco=0; }; #endif // SEGMENT_H diff --git a/src/main.cc b/src/main.cc index 52d81c9..127f6b6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -23,16 +23,22 @@ -//extern bopti_image_t car1, car2, car3, car4, car5, car6, car7, car8; +extern bopti_image_t car1, car2, car3, car4, car5, car6, car7, car8; +extern bopti_image_t tree1, tree2, tree3; +extern bopti_image_t player; std::vector circuit; +int MAX_SEGMENT=0; camera *cam; + bool stop = false; bool record = false; bool screenshot = false; +bool ShowDebug1 = false; +bool ShowDebug2 = false; uint16_t currentcurve=0; uint8_t shiftcolor=0; @@ -101,6 +107,17 @@ static void get_inputs( float dt ) if(keydown(KEY_EXIT)) stop = true; + if(keydown(KEY_F1)) + { + ShowDebug1 = !ShowDebug1; + ShowDebug2 = false; + } + if(keydown(KEY_F2)) + { + ShowDebug2 = !ShowDebug2; + ShowDebug1 = false; + } + if(keydown(KEY_F6)) record = !record; if(keydown(KEY_F4)) screenshot = true; @@ -146,8 +163,11 @@ int main(void) time_create = prof_time(perf_create); //-------------- + MAX_SEGMENT = circuit.size(); int indexstart = 0; + int indexend = 0; + uint32_t maxDistance = (MAX_SEGMENT-nbInterestingSegments-5)*SEGMENT_LENGTH; uint32_t dt=0; @@ -162,12 +182,14 @@ int main(void) if (fround(cam->cZ)<=0) cam->cZ=fixdouble(0.0); if (fround(cam->cZ)>=maxDistance) cam->cZ=fixdouble(maxDistance); - indexstart = (fround(cam->cZ) - 400) / SEGMENT_LENGTH; + indexstart = fround(cam->cZ) / SEGMENT_LENGTH; + indexend = indexstart+nbInterestingSegments+1; + // there is an offset equals to 400 on z position // this is to compute the first index of segment to be projected to screen if (indexstart<0) indexstart=0; - if (indexstart>MAX_SEGMENT-nbInterestingSegments-5-1) indexstart=MAX_SEGMENT-nbInterestingSegments-5-1; + if (indexstart>MAX_SEGMENT-nbInterestingSegments-1-2) indexstart=MAX_SEGMENT-nbInterestingSegments-1-2; //-------------- @@ -175,8 +197,15 @@ int main(void) perf_project = prof_make(); prof_enter(perf_project); - for (int k=indexstart; kcY = fix( 300 + interpolatePositionY(fround(cam->cZ)) ); + uint16_t cumulCurve=0; + for (int k=indexstart; k<=indexend; k++) // Need to project 1 more segment than actual drawing + { + projectCircuitFP( k ); + circuit[k]->CumulatedCurve = cumulCurve; + cumulCurve += circuit[k]->Curve; + } + prof_leave(perf_project); time_project = prof_time(perf_project); @@ -186,35 +215,61 @@ int main(void) perf_render = prof_make(); prof_enter(perf_render); - drawSky( ); + drawSky( ); - for (int k=indexstart; kcX = interpolatePositionX(fround(cam->cZ)); + cam->cY = fix( 300 ) + interpolatePositionY(fround(cam->cZ)); - //r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT); + //currentcurve = 0; - dprint( 1, 1, C_RED, "Circuit Creation = %.3D ms", time_create ); - dprint( 1, 15, C_RED, "Segments Projection = %.3D ms", time_project ); - dprint( 1, 29, C_RED, "Rendering = %.3D ms", time_render ); + //for (int k=indexstart; k=indexstart; k--) + { + currentcurve = circuit[k]->CumulatedCurve; + drawCircuitSegment( k ); + //currentcurve += circuit[k]->Curve; + } - dprint( 1, 55, C_WHITE, "Iteration = %d", l); - dprint( 1, 69, C_GREEN, "Indexstart = %d ", indexstart ); - dprint( 1, 83, C_GREEN, "Indexend = %d", indexstart+nbInterestingSegments+1 ); - dprint( 1, 97, C_RED, "Circuit Size = %d", circuit.size() ); + //r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT); + if (ShowDebug1) + { + Segment* currentSeg = circuit[indexstart]; - dprint( 300, 1, C_WHITE, "CamX= %d", fround( cam->cX ) ); - dprint( 300, 15, C_WHITE, "CamY= %d", fround( cam->cY ) ); - dprint( 300, 29, C_WHITE, "CamZ= %d", fround( cam->cZ ) ); + dprint( 1, 1, C_RED, "Cra=%.3D ms", time_create ); + dprint( 1, 15, C_RED, "Prj=%.3D ms", time_project ); + dprint( 1, 29, C_RED, "Rdr=%.3D ms", time_render ); - dprint( 280, 55, C_WHITE, "Dir = %d", direction ); - dprint( 280, 69, C_WHITE, "Spd = %.1f", speed ); - dprint( 280, 83, C_WHITE, "Dz = %.1f", speed*dt ); - dprint( 280, 97, C_WHITE, "dt = %.3D ms", dt ); + dprint( 1, 55, C_WHITE, "It=%d", l); + dprint( 1, 69, C_GREEN, "St=%d ", indexstart ); + dprint( 1, 83, C_GREEN, "En=%d", indexend ); + dprint( 1, 97, C_RED, "Sz= %d", circuit.size() ); + + dprint( 100, 55, C_WHITE, "SzSgmt=%d bytes", sizeof(Segment) ); + dprint( 100, 69, C_WHITE, ">XYZc=(%d,%d,%.0lf,%d)", circuit[indexstart]->wX, circuit[indexstart]->wY, circuit[indexstart]->wZ, circuit[indexstart]->Curve ); + dprint( 100, 83, C_WHITE, ">XYZc=(%d,%d,%.0lf,%d)", circuit[indexend]->wX, circuit[indexend]->wY, circuit[indexend]->wZ, circuit[indexstart]->Curve ); + dprint( 100, 97, C_WHITE, "C[i]Adr= %p", ¤tSeg), + + dprint( 320, 1, C_WHITE, "CamX=%d", fround( cam->cX ) ); + dprint( 320, 15, C_WHITE, "CamY=%d", fround( cam->cY ) ); + dprint( 320, 29, C_WHITE, "CamZ=%d", fround( cam->cZ ) ); + + dprint( 320, 55, C_WHITE, "Dir=%d", direction ); + dprint( 320, 69, C_WHITE, "Spd=%.1f", speed ); + dprint( 320, 83, C_WHITE, "Dz =%.1f", speed*dt ); + dprint( 320, 97, C_WHITE, "dt =%.3D ms", dt ); + } + if (ShowDebug2) + { + dprint( 1, 1, C_RED, "Cra=%.3D ms", time_create ); + dprint( 1, 15, C_RED, "Prj=%.3D ms", time_project ); + dprint( 1, 29, C_RED, "Rdr=%.3D ms", time_render ); + } + + dsubimage( SCREEN_CX-36, SCREEN_HEIGHT-48, &player, 257,1,72,46, DIMAGE_NONE); + + //dupdate(); + r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT); - //r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT); - dupdate(); prof_leave(perf_render); time_render = prof_time(perf_render); diff --git a/src/parameters.h b/src/parameters.h index 8f1f6f4..e4717c1 100644 --- a/src/parameters.h +++ b/src/parameters.h @@ -14,9 +14,7 @@ #define ASPECT_RATIO 1.767 #define DISTANCE_SCREEN 0.83444 -#define MAX_RENDER_DISTANCE 1500 - -#define MAX_SEGMENT 10000 +#define MAX_RENDER_DISTANCE 2500 #define std ustl diff --git a/src/src/circuit.cc b/src/src/circuit.cc index dbf5eab..8849840 100644 --- a/src/src/circuit.cc +++ b/src/src/circuit.cc @@ -11,7 +11,8 @@ extern std::vector circuit; extern camera *cam; extern uint16_t currentcurve; extern uint8_t shiftcolor; - +extern int MAX_SEGMENT; +extern bool ShowDebug1; void initData( void ) { @@ -24,14 +25,81 @@ void initData( void ) void createCircuit( void ) { - for( int i=0; iwY; + lastZ=circuit[circuit.size()-1]->wZ; + } + + for( int i=0; iwY; + lastZ=circuit[circuit.size()-1]->wZ; + } + + for( int i=0; iwY; + lastZ=circuit[circuit.size()-1]->wZ; + } + + for( int i=0; iX, circuit[i]->Y, circuit[i]->W ); - //dprint(1, 1+10*(i), C_GREEN, "%d-(_sY,Y,W)=(%.0f,%.0f,%.0f)", i, circuit[i]->_sX, circuit[i]->_sY, circuit[i]->_sW ); + //dprint(1, 1+10*(i), C_GREEN, "%d-(_sY,Y,W)=(%.0f,%.0f,%.0f)", i, circuit[i]->_wX, circuit[i]->_wY, circuit[i]->_sW ); } }; @@ -78,40 +146,85 @@ void drawCircuitSegment( uint16_t index ) if (index%2==0) { - drawGrass( Y2, Y1, 0, 255-shiftcolor, 45-shiftcolor, 255 ); + drawGrass( Y2, Y1, 0, 255-shiftcolor, 45-shiftcolor ); // route - drawPolygon( X2-W2+currentcurve, X2+W2+currentcurve, Y2, X1-W1+currentcurve, X1+W1+currentcurve, Y1, 196-shiftcolor, 196-shiftcolor, 196-shiftcolor, 255 ); + drawPolygon( X2-W2+currentcurve, X2+W2+currentcurve, Y2, X1-W1+currentcurve, X1+W1+currentcurve, Y1, 196-shiftcolor, 196-shiftcolor, 196-shiftcolor ); // ligne blanche centrale - drawPolygon( X2-W2/50+currentcurve, X2+W2/50+currentcurve, Y2, X1-W1/50+currentcurve, X1+W1/50+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor, 255 ); + drawPolygon( X2-W2/50+currentcurve, X2+W2/50+currentcurve, Y2, X1-W1/50+currentcurve, X1+W1/50+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor ); // ligne blanche gauche - drawPolygon( X2-W2/16-W2+currentcurve, X2-W2+currentcurve, Y2, X1-W1/16-W1+currentcurve, X1-W1+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor, 255 ); + drawPolygon( X2-W2/16-W2+currentcurve, X2-W2+currentcurve, Y2, X1-W1/16-W1+currentcurve, X1-W1+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor ); // ligne blanche centrale gauche - drawPolygon( X2-W2/50-W2/2+currentcurve, X2+W2/50-W2/2+currentcurve, Y2, X1-W1/50-W1/2+currentcurve, X1+W1/50-W1/2+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor, 255 ); + drawPolygon( X2-W2/50-W2/2+currentcurve, X2+W2/50-W2/2+currentcurve, Y2, X1-W1/50-W1/2+currentcurve, X1+W1/50-W1/2+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor ); // ligne blanche centrale - drawPolygon( X2-W2/50+currentcurve, X2+W2/50+currentcurve, Y2, X1-W1/50+currentcurve, X1+W1/50+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor, 255 ); + drawPolygon( X2-W2/50+currentcurve, X2+W2/50+currentcurve, Y2, X1-W1/50+currentcurve, X1+W1/50+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor ); // ligne blanche centrale droite - drawPolygon( X2-W2/50+W2/2+currentcurve, X2+W2/50+W2/2+currentcurve, Y2, X1-W1/50+W1/2+currentcurve, X1+W1/50+W1/2+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor, 255 ); + drawPolygon( X2-W2/50+W2/2+currentcurve, X2+W2/50+W2/2+currentcurve, Y2, X1-W1/50+W1/2+currentcurve, X1+W1/50+W1/2+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor ); // ligne blanche droite - drawPolygon( X2+W2+currentcurve, X2+W2+W2/16+currentcurve, Y2, X1+W1+currentcurve, X1+W1+W1/16+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor, 255 ); + drawPolygon( X2+W2+currentcurve, X2+W2+W2/16+currentcurve, Y2, X1+W1+currentcurve, X1+W1+W1/16+currentcurve, Y1, 255-shiftcolor, 255-shiftcolor, 255-shiftcolor ); } else { - drawGrass( Y2, Y1, 0, 255-shiftcolor, 0, 255 ); + drawGrass( Y2, Y1, 0, 255-shiftcolor, 0 ); - drawPolygon( X2-W2+currentcurve, X2+W2+currentcurve, Y2, X1-W1+currentcurve, X1+W1+currentcurve, Y1, 180-shiftcolor, 180-shiftcolor, 180-shiftcolor, 255 ); + drawPolygon( X2-W2+currentcurve, X2+W2+currentcurve, Y2, X1-W1+currentcurve, X1+W1+currentcurve, Y1, 180-shiftcolor, 180-shiftcolor, 180-shiftcolor ); // ligne rouge gauche - drawPolygon( X2-W2/16-W2+currentcurve, X2-W2+currentcurve, Y2, X1-W1/16-W1+currentcurve, X1-W1+currentcurve, Y1, 255-shiftcolor, 0, 0, 255 ); + drawPolygon( X2-W2/16-W2+currentcurve, X2-W2+currentcurve, Y2, X1-W1/16-W1+currentcurve, X1-W1+currentcurve, Y1, 255-shiftcolor, 0, 0 ); // ligne rouge droite - drawPolygon( X2+W2+currentcurve, X2+W2+W2/16+currentcurve, Y2, X1+W1+currentcurve, X1+W1+W1/16+currentcurve, Y1, 255-shiftcolor, 0, 0, 255 ); + drawPolygon( X2+W2+currentcurve, X2+W2+W2/16+currentcurve, Y2, X1+W1+currentcurve, X1+W1+W1/16+currentcurve, Y1, 255-shiftcolor, 0, 0 ); } - currentcurve += circuit[index]->Curve; +} + + +fixed_t interpolatePositionX( double currentZ ) +{ + int index = (int) (currentZ / SEGMENT_LENGTH); + fixed_t x1 = fix(circuit[index]->wX); + fixed_t x2 = fix(circuit[index+1]->wX); + fixed_t dZ = fixdouble(currentZ-index*SEGMENT_LENGTH); + + fixed_t result = x1 + fmul( x2-x1, fdiv( dZ, fix(SEGMENT_LENGTH))); + + if(ShowDebug1) + { + dprint( 120, 1, C_WHITE, "CZ=%.0lf", f2double(currentZ) ); + dprint( 120, 15, C_WHITE, "y1=%d", fround(x1) ); + dprint( 120, 29, C_WHITE, "y2=%d", fround(x2) ); + + dprint( 240, 15, C_WHITE, "Dz=%d", fround(dZ) ); + dprint( 240, 29, C_GREEN, "CX=%d", fround(result) ); + } + + return result; +} + + +fixed_t interpolatePositionY( double currentZ ) +{ + int index = (int) (currentZ / SEGMENT_LENGTH); + fixed_t y1 = fix(circuit[index]->wY); + fixed_t y2 = fix(circuit[index+1]->wY); + fixed_t dZ = fixdouble(currentZ-index*SEGMENT_LENGTH); + + fixed_t result = y1 + fmul( y2-y1, fdiv( dZ, fix(SEGMENT_LENGTH))); + + if(ShowDebug1) + { + dprint( 120, 1, C_WHITE, "CZ=%.0lf", f2double(currentZ) ); + dprint( 120, 15, C_WHITE, "y1=%d", fround(y1) ); + dprint( 120, 29, C_WHITE, "y2=%d", fround(y2) ); + + dprint( 240, 15, C_WHITE, "Dz=%d", fround(dZ) ); + dprint( 240, 43, C_GREEN, "CY=%d", fround(result) ); + } + + return result; } diff --git a/src/src/drawstuff.cc b/src/src/drawstuff.cc index 9fd1786..b553983 100644 --- a/src/src/drawstuff.cc +++ b/src/src/drawstuff.cc @@ -27,31 +27,16 @@ void gint_dhline(int x1, int x2, int y, uint16_t color) }; -void drawGrass( int y1, int y2, uint8_t R, uint8_t G, uint8_t B, uint8_t A ) +void drawGrass( int y1, int y2, uint8_t R, uint8_t G, uint8_t B ) { uint16_t color = C_RGB(R,G,B); for (int y=y1; y<=y2; y++) gint_dhline( 0, SCREEN_WIDTH, y, color ); }; -void drawPolygon( int x1min, int x1max, int y1, int x2min, int x2max, int y2, uint8_t R, uint8_t G, uint8_t B, uint8_t A ) +void drawPolygon( int x1min, int x1max, int y1, int x2min, int x2max, int y2, uint8_t R, uint8_t G, uint8_t B ) { -/* - uint16_t color = C_RGB(R,G,B); - float Ddeltay = 1.0f / (float) (y2-y1); - float deltay=0.0f; - for (int y=y1; y<=y2; y++) - { - if (y>0 && ycX); - fixed_t DY = (wY - c->cY); - fixed_t divDZ = fdiv( fix(1), (wZ - c->cZ)); + 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)); - Scale = fmul(fixdouble(DISTANCE_SCREEN), divDZ); + 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); - sX=fmul(fix(SCREEN_CX), (fix(1)+tempx)); - sY=fmul(fix(SCREEN_CY), (fix(1)-tempy)); - sW=fmul(fix(SCREEN_CX), tempw); + 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);