added curves/hills

This commit is contained in:
Sylvain PILLOT 2022-03-06 20:21:22 +01:00
parent e3bdbaf171
commit ddc326403f
17 changed files with 380 additions and 129 deletions

View File

@ -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()

View File

@ -2,44 +2,14 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="src/include/camera.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/src/drawstuff.cc" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="221" topLine="0" />
</Cursor>
</File>
<File name="src/include/segment.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="265" topLine="0" />
</Cursor>
</File>
<File name="src/src/circuit.cc" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="406" topLine="54" />
<Cursor1 position="953" topLine="0" />
</Cursor>
</File>
<File name="src/fixed.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="597" topLine="44" />
</Cursor>
</File>
<File name="src/src/segment.cc" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
<Cursor>
<Cursor1 position="169" topLine="0" />
</Cursor>
</File>
<File name="src/parameters.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="189" topLine="0" />
</Cursor>
</File>
<File name="CMakeLists.txt" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="759" topLine="1" />
</Cursor>
</File>
<File name="src/main.cc" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="5592" topLine="181" />
<Cursor1 position="778" topLine="0" />
</Cursor>
</File>
<File name="src/src/camera.cc" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -47,4 +17,44 @@
<Cursor1 position="124" topLine="0" />
</Cursor>
</File>
<File name="src/main.cc" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="5347" topLine="41" />
</Cursor>
</File>
<File name="src/src/circuit.cc" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1889" topLine="75" />
</Cursor>
</File>
<File name="src/parameters.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="189" topLine="0" />
</Cursor>
</File>
<File name="CMakeLists.txt" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1219" topLine="4" />
</Cursor>
</File>
<File name="src/include/drawstuff.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="354" topLine="0" />
</Cursor>
</File>
<File name="src/src/segment.cc" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
<Cursor>
<Cursor1 position="158" topLine="0" />
</Cursor>
</File>
<File name="src/include/camera.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="221" topLine="0" />
</Cursor>
</File>
<File name="src/include/segment.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="325" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

View File

@ -0,0 +1,5 @@
*.png:
type: bopti-image
profile: p4
name_regex: (.*)\.png \1

BIN
assets-cg/player/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -0,0 +1,5 @@
*.png:
type: bopti-image
profile: p4
name_regex: (.*)\.png \1

BIN
assets-cg/trees/tree1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
assets-cg/trees/tree2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
assets-cg/trees/tree3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -3,9 +3,8 @@
//---
#pragma once
#include <stdint.h>
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);
}

View File

@ -1,4 +1,41 @@
#include <vector>
#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 );

View File

@ -2,8 +2,8 @@
#include <gint/defs/util.h>
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 );

View File

@ -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

View File

@ -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<Segment*> 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; k<indexstart+nbInterestingSegments+1; k++) // Need to project 1 more segment than actual drawing
projectCircuitFP( k );
//cam->cY = 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; k<indexstart+nbInterestingSegments; k++)
{
drawCircuitSegment( k );
}
//cam->cX = 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<indexend-1; k++)
for( int k=indexend-1; 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", &currentSeg),
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);

View File

@ -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

View File

@ -11,7 +11,8 @@ extern std::vector<Segment*> 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; i<MAX_SEGMENT; i++)
/* for( int i=0; i<MAX_SEGMENT; i++)
{
Segment *s=new Segment( i );
circuit.push_back( s );
Segment *seg=new Segment( i );
if (seg!=nullptr) circuit.push_back( seg );
}
*/
addStraightLine( L_VERYSHORT );
addStraightLine( L_VERYSHORT );
addCurve( L_SHORT, C_EASY, LEFT_CURVE );
addHill( L_MEDIUM, H_BIG, UP_HILL );
addCurve( L_SHORT, C_HARD, RIGHT_CURVE );
addStraightLine( L_LONG );
};
void addStraightLine( Length l )
{
double lastZ=0;
int16_t lastY=0;
if (circuit.size()!=0)
{
lastY=circuit[circuit.size()-1]->wY;
lastZ=circuit[circuit.size()-1]->wZ;
}
for( int i=0; i<l; i++)
{
//Segment *s=new Segment( i );
Segment *seg=new Segment( 0, lastY, lastZ + (i+1)*SEGMENT_LENGTH, 0 );
if (seg!=nullptr) circuit.push_back( seg );
}
}
void addCurve( Length l, CurveStrength s, CurveType t )
{
double lastZ=0;
int16_t lastY=0;
if (circuit.size()!=0)
{
lastY=circuit[circuit.size()-1]->wY;
lastZ=circuit[circuit.size()-1]->wZ;
}
for( int i=0; i<l; i++)
{
//Segment *s=new Segment( i );
Segment *seg=new Segment( 0, lastY, lastZ+(i+1)*SEGMENT_LENGTH, s*t );
if (seg!=nullptr) circuit.push_back( seg );
}
}
void addHill( Length l, HillSize s, HillType t )
{
double lastZ=0;
int16_t lastY=0;
if (circuit.size()!=0)
{
lastY=circuit[circuit.size()-1]->wY;
lastZ=circuit[circuit.size()-1]->wZ;
}
for( int i=0; i<l; i++)
{
//Segment *s=new Segment( i );
Segment *seg=new Segment( 0, lastY+(i+1)*t*s, lastZ+(i+1)*SEGMENT_LENGTH, 0 );
if (seg!=nullptr) circuit.push_back( seg );
}
}
void projectCircuitFP( void )
{
for( int i=0; i<circuit.size(); i++)
@ -52,7 +120,7 @@ void printCircuit( void )
for( int i=0; i<20; i++)
{
dprint(198, 1+10*(i), C_RED, "%d-(sX,Y,W)=(%d,%d,%d)", i, circuit[i]->X, 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;
}

View File

@ -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 && y<SCREEN_HEIGHT)
{
float xmin = (float) x1min + (float) (x2min-x1min)*deltay;
float xmax = (float) x1max + (float) (x2max-x1max)*deltay;
gint_dhline( (int) xmin, (int) xmax, y, color );
}
deltay+=Ddeltay;
}
*/
uint16_t color = C_RGB(R,G,B);
if (y1==y2)
{
@ -59,9 +44,6 @@ void drawPolygon( int x1min, int x1max, int y1, int x2min, int x2max, int y2, ui
return;
}
//fixed_t Ddeltay = fdiv(fix(1), fix(y2-y1));
//fixed_t deltay = 0;
fixed_t deltay = fdiv(fix(1), fix(y2-y1));
fixed_t xmin = fix(x1min);

View File

@ -11,7 +11,29 @@ Segment::Segment( uint16_t n_seg )
{
wX = 0;
wY = 0;
wZ = fixdouble((400 + n_seg * SEGMENT_LENGTH));
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 = 0;
RDeco = 0;
}
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;
}
@ -23,22 +45,23 @@ Segment::~Segment()
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 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);