I am in the planning discovery stage of creating a Traffic Simulator.
My initial road block pun intended is to decide the most flexible way to design the roads. They need to have multiple lanes, on ramps off ramps as well as roundabouts and ideally the ability to change altitude etc.
The suggestion was made that splines would be the way to go. As this was an unfamiliar programming area I checked the code base and the forums. I cam across a snippet by Jukuma. It looked interesting so I converted from DBP to GDK. I think the spline concept maybe a dead end and I am looking for a different approach. All suggestions will be considered.
Rather than add this to my many dead ends (it's the journey thats the joy) I am posting here for others to review comment learn from etc.
/* This code was modified from Dark Basic Pro Code posted by Jukuma in Code Snippets. March 2006
http://forum.thegamecreators.com/?m=forum_view&t=74401&b=6
Translated to C++ and modified by John James AKA Codger Feb 2008
This is a test of the practicality of using splines to define lanes in a traffic simulator
*/
#include "DarkGDK.h"
#define SPLINE_MAX 50
#define SPLINE_DIST 1500
void setsplinevectors ( int s, int d );
void splinedraw ( int v, float s );
int MyCounter = 0;
int MyOldCounter = 0;
int SplineCounter = 0;
void DarkGDK ( void )
{
int time = 0;
float step = 0;
int vector = 0;
float angle = 0;
// Use full screen exclusive to max speed
dbSetWindowPosition(0,0);
dbSetDisplayMode(dbScreenWidth(),dbScreenHeight(),dbScreenDepth());
dbSetWindowOff();
// general Paramaters
dbSyncRate( 0 );
dbSyncOn();
dbColorBackdrop( -1 );
dbInk( 0, 0 );
dbAutoCamOff ();
dbRandomize(dbTimer());
dbMakeObjectTriangle( 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
dbColorObject( 1, 255 );
dbSetObjectWireframe( 1, 1 );
dbMakeMeshFromObject( 1, 1 );
dbPositionCamera(0,0,-1500);
dbPointCamera(0,0,0);
setsplinevectors( SPLINE_MAX, SPLINE_DIST );
for ( step = 0.01 ;step < 1.000 ; step = step + 0.01 ) {
for ( vector = 1; vector <= (5 * SPLINE_MAX) ; vector += 5 ) {
splinedraw( vector, step );
MyCounter ++;
}
dbSetCursor( 10, 0 ); dbPrint( dbStr(dbScreenFPS()));
dbSetCursor( 10, 20 ); dbPrint( dbStr(MyCounter));
dbSetCursor( 10, 40 ); dbPrint( dbStr(SplineCounter));
MyCounter ++;
dbSync();
}
// our main loop
while ( LoopGDK ( ) ){
dbSetCameraToFollow( 0, 0, 0, angle , 1500, dbSin( angle ) * 100, 1.0, 0 );
dbPointCamera( 0, 0, 0 );
angle = angle + 0.5;
dbSetCursor( 10, 0 ); dbPrint( dbStr(dbScreenFPS()));
dbSetCursor( 10, 20 ); dbPrint( dbStr(MyCounter));
dbSetCursor( 10, 40 ); dbPrint( dbStr(SplineCounter));
dbSync();
MyCounter ++;
}
return;
}
void setsplinevectors ( int s, int d )
{
int v = 0;
int c = 0;
int null = 0;
for ( v = 1; v <= (5 * s ) ; v += 5 ) {
for ( c = 0; c <= 4; c++ ) {
null = dbMakeVector3( v + c );
}
dbSetVector3( v, 0, 0, 0 );
dbSetVector3( v + 1, 0, 0, 0 );
dbSetVector3( v + 2, dbNewXValue( 0, dbRnd( 359 ), dbRnd( d ) ), dbNewYValue( 0, dbRnd( 359 ), dbRnd( d ) ), dbNewZValue( 0, dbRnd( 359 ), dbRnd( d ) ) );
dbSetVector3( v + 3, dbNewXValue( 0, dbRnd( 359 ), dbRnd( d ) ), dbNewYValue( 0, dbRnd( 359 ), dbRnd( d ) ), dbNewZValue( 0, dbRnd( 359 ), dbRnd( d ) ) );
dbSetVector3( v + 4, dbNewXValue( 0, dbRnd( 359 ), d ), dbNewYValue( 0, dbRnd( 359 ), d ), dbNewZValue( 0, dbRnd( 359 ), d ) );
}
}
//***** 'splinedraw' **********************************************************
//+**** ============ **********************************************************
void splinedraw ( int v, float s )
{
float x1 = 0;
float y1 = 0;
float z1 = 0;
float x2 = 0;
float y2 = 0;
float z2 = 0;
int c = 0;
SplineCounter ++;
x1 = dbXVector3( v );
y1 = dbYVector3( v );
z1 = dbZVector3( v );
dbHermiteVector3( v, v + 1, v + 2, v + 3, v + 4, s );
x2 = dbXVector3( v );
y2 = dbYVector3( v );
z2 = dbZVector3( v );
dbLockVertexDataForLimb( 1, 0 );
c = dbGetVertexDataVertexCount();
dbSetVertexDataPosition( c - 3, x1 , y1 , z1 );
dbSetVertexDataPosition( c - 2, x2 , y2 , z2 );
dbSetVertexDataPosition( c - 1, x2 , y2 , z2 );
dbAddMeshToVertexData( 1 );
dbUnlockVertexData();
}
All the best
Coder
System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem