35#include <portability.h>
83 tdble CosA, SinA, r, a;
93 toRight = (width / 2.0) +
p->toMiddle;
95 toRight = width -
p->toLeft;
109 tr = toRight - seg->
Kyl *
p->toStart;
153 while (segnotfound) {
165 ts = x * cosine +
y * sine;
168 p->toRight =
y * cosine - x * sine;
169 if ((
ts < 0) && (depl < 1)) {
173 }
else if ((
ts > seg->
length) && (depl > -1)) {
193 theta -= (T)(2.0 *
PI);
195 while (theta < -
PI) {
196 theta += (T)(2.0 *
PI);
199 p->toStart = theta + a2;
202 if ((theta < -a2) && (depl < 1)) {
206 else if ((theta > a2) && (depl > -1)) {
220 p->toMiddle =
p->toRight - seg->
width / 2.0;
221 p->toLeft = seg->
width -
p->toRight;
229 while ((sseg = sseg->
side[side]) != NULL) {
256 while ((*toSide < 0.0f) && (sseg->
side[trSide] != NULL)) {
257 sseg = sseg->
side[trSide];
260 *toOppositeSide -= prevWidth;
262 p->toMiddle +=
sign*(prevWidth + curWidth)/2.0f;
263 prevWidth = curWidth;
317 if ((tr < 0) && (seg->
rside != NULL)) {
321 if ((tr < 0) && (seg->
rside != NULL)) {
325 }
else if ((tr > seg->
width) && (seg->
lside != NULL)) {
328 if ((tr > seg->
width) && (seg->
lside != NULL)) {
385 tdble base_height = height_right_side + banking_height;
396 alpha = seg->
width - tr;
400 return base_height + alpha * (seg->
height + curb_roughness) / seg->
width;
421 if (current->
side[tr_side] != NULL) {
422 return current->
side[tr_side];
430 while (neighbour->
side[tr_other_side] != NULL) {
431 otherSurface = neighbour;
432 if (neighbour->
side[tr_other_side] == current) {
435 neighbour = neighbour->
side[tr_other_side];
512 if (side == seg->
type) {
522 lg = 1.0 / sqrt(norm->
x * norm->
x + norm->
y * norm->
y);
541 switch (
p->seg->type) {
543 return p->seg->angle[
TR_ZS];
546 return p->seg->angle[
TR_ZS] -
p->toStart;
549 return p->seg->angle[
TR_ZS] +
p->toStart;
570 t3Dd px1, px2, py1, py2;
614 v1.
x = px2.
x - px1.
x;
615 v1.
y = px2.
y - px1.
y;
616 v1.
z = px2.
z - px1.
z;
619 v2.
x = py2.
x - py1.
x;
620 v2.
y = py2.
y - py1.
y;
621 v2.
z = py2.
z - py1.
z;
623 norm->
x = v1.
y * v2.
z - v2.
y * v1.
z;
624 norm->
y = v2.
x * v1.
z - v1.
x * v2.
z;
625 norm->
z = v1.
x * v2.
y - v2.
x * v1.
y;
626 lg = sqrt(norm->
x * norm->
x + norm->
y * norm->
y + norm->
z * norm->
z);
672 lg +=
p->toStart * seg->
radius;
699 if (car->_pit == NULL)
return 1;
701 pitpos = &(car->_pit->pos);
702 carpos = &(car->_trkPos);
718 *dL +=
track->length;
719 }
else if (*dL >
track->length) {
720 *dL -=
track->length;
752 const int BUFSIZE = 256;
759 for (i=0; i < 4; i++) {
783 for (i=0; i < 2; i++) {
789 for (i=0; i < 2; i++) {
797 for (i=0; i < 8; i++) {
804 for (i=0; i < 2; i++) {
810 for (i=0; i < 3; i++) {
835static const char*
CarPitSetupFilenames[6] = {
"practice",
"qualifying",
"race",
"backup1",
"backup2",
"backup3" };
852 const char* trackname,
857 snprintf(filename, len,
"%s_%s_%d_%s" , carname, trackname, robidx,
CarPitSetupFilenames[type]);
871 if (fabs(v->
min - v->
max) >= 0.0001f) {
891 const char* filepath,
895 const int BUFSIZE = 256;
906 for (i=0; i < 4; i++) {
930 for (i=0; i < 2; i++) {
936 for (i=0; i < 2; i++) {
944 for (i=0; i < 8; i++) {
951 for (i=0; i < 2; i++) {
958 for (i=0; i < 3; i++) {
995 const char* modulename,
997 const char* trackname,
1001 const int filelen = 256;
1002 char filename[filelen];
1005 const int pathlen = 1024;
1008 snprintf(path, pathlen,
"%sdrivers/%s/setups",
GetLocalDir(), modulename);
1010 snprintf(path, pathlen,
"%sdrivers/%s/setups/%s.xml",
GetLocalDir(), modulename, filename);
1013 GfError(
"RtSaveCarPitSetup, could not create %s\n", path);
1030 const char* modulename,
1032 const char* trackname,
1036 const int filelen = 256;
1037 char filename[filelen];
1040 const int pathlen = 1024;
1043 snprintf(path, pathlen,
"%sdrivers/%s/setups/%s.xml",
GetLocalDir(), modulename, filename);
1044 FILE* file = fopen(path,
"r");
1101 const char* modulename,
1103 const char* trackname,
1104 const char* carname,
1108 const int filelen = 256;
1109 char filename[filelen];
1112 const int pathlen = 1024;
1115 snprintf(path, pathlen,
"%sdrivers/%s/setups/%s.xml",
GetLocalDir(), modulename, filename);
1129 const int BUFSIZE = 1024;
1133 snprintf(buf, BUFSIZE,
"%scars/%s/%s.xml",
GetDataDir(), carname, carname);
1136 GfError(
"carhdle NULL in %s, line %d\n", __FILE__, __LINE__);
1142 if (category == 0) {
1143 GfError(
"category string NULL in %s, line %d\n", __FILE__, __LINE__);
1149 snprintf(buf, BUFSIZE,
"%scategories/%s.xml",
GetDataDir(), category);
1152 GfError(
"cathdle NULL in %s, line %d\n", __FILE__, __LINE__);
1175 if (carhandle == 0) {
1176 GfError(
"carhandle NULL in %s, line %d\n", __FILE__, __LINE__);
1200 const char* modulename,
1202 const char* trackname,
1206 const int filelen = 256;
1207 char filename[filelen];
1210 const int pathlen = 1024;
1213 snprintf(path, pathlen,
"%sdrivers/%s/setups/%s.xml",
GetLocalDir(), modulename, filename);
static const char * WingSect[2]
static const char * AxleSect[2]
#define SECT_CENTRALDIFFERENTIAL
#define PRM_LOCKINGBRAKE_TQ
#define SECT_REARLFTWHEEL
#define PRM_REBOUNDTHRESHOLD
#define PRM_BUMPTHRESHOLD
struct CarElt tCarElt
Car structure (tCarElt).
#define SECT_REARRGTWHEEL
#define SECT_FRNTDIFFERENTIAL
#define VAL_DIFF_VISCOUS_COUPLER
#define SECT_FRNTRGTWHEEL
#define PRM_MAX_SLIP_BIAS
#define VAL_DIFF_LIMITED_SLIP
#define SECT_FRNTLFTWHEEL
#define SECT_REARDIFFERENTIAL
float tdble
Floating point type used in TORCS.
int GfParmSetNumEx(void *handle, const char *path, const char *key, const char *unit, tdble val, tdble min, tdble max)
Set a numerical parameter and its bounds, creating it if necessary.
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
int GfParmSetStr(void *handle, const char *path, const char *key, const char *val)
Set a string parameter in the parameter set handle.
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
tdble GfParmSI2Unit(const char *unit, tdble val)
Convert a value from SI to given unit.
int GfParmGetNumBoundaries(void *handle, const char *path, const char *key, tdble *min, tdble *max)
Get the min and max of a numerical parameter from the parameter set handle.
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
int GfParmWriteFile(const char *file, void *parmHandle, const char *name)
Write parameter set into file.
void * GfParmMergeHandles(void *ref, void *tgt, int mode)
Merge two parameter sets into a new private set.
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
struct trackSeg tTrackSeg
Track segment (tTrackSeg) The segments can be straights (type TR_STR): (the track goes from the right...
int main(int argc, char *argv[])
static const char * CarPitSetupFilenames[6]
Array with names for rtCarPitSetupType enumeration.
static tTrackSeg * resolveTrackSeg(const tTrkLocPos *p, tdble *toRight)
Resolve the effective segment and rebase the lateral coordinate to it.
static void RtParmSetNum(void *hdlesetup, const char *path, const char *key, const char *unit, tCarPitSetupValue *v)
Robottool internal: Set parameter if min != max, save as well min and max values.
static void RtReadCarPitSetupEntry(tCarPitSetupValue *v, const char *path, const char *key, void *hdle, bool minmaxonly)
static void rtTrackGlobal2Local(tTrackSeg *segment, T X, T Y, tTrkLocPos *p, int type)
tCarPitSetupValue thirdbump[2]
tCarPitSetupValue wheelcaster[4]
tCarPitSetupValue diffmintqbias[3]
tCarPitSetupValue brakePressure
tCarPitSetupValue wheelcamber[4]
tCarPitSetupValue suspfastbump[4]
tCarPitSetupValue suspspring[4]
tCarPitSetupValue brakeRepartition
tCarPitSetupValue suspbumpthreshold[4]
tCarPitSetupValue gearsratio[MAX_GEARS - 2]
tCarPitSetupValue wheeltoe[4]
tCarPitSetupValue suspslowbump[4]
tCarPitSetupValue diffratio[3]
tCarPitSetupValue thirdX0[2]
tCarPitSetupValue diffslipbias[3]
tCarPitSetupValue difflockinginputbraketq[3]
tCarPitSetupValue wingangle[2]
tCarPitSetupValue suspfastrebound[4]
tCarPitSetupValue suspslowrebound[4]
tCarPitSetupValue arbspring[2]
tCarPitSetupValue wheelrideheight[4]
tCarPitSetupValue suspreboundthreshold[4]
tCarPitSetupValue susppackers[4]
tCarPitSetupValue thirdrebound[2]
tCarPitSetupValue diffmaxtqbias[3]
tCarPitSetupValue steerLock
tCarPitSetupValue difflockinginputtq[3]
tCarPitSetupValue thirdspring[2]
Location on the track in local coordinates.
tdble toRight
Distance (+ to left, - to right) relative to the right side of segment.
tTrackSeg * seg
Track segment.
tdble toStart
Distance to start of segment (or arc if turn)
int type
Geometrical type:
tTrackSurface * surface
Segment surface.
tdble height
Max height for curbs.
t3Dd vertex[4]
Coordinates of the 4 corners of the segment.
tdble radiusr
Radius in meters of the right side of the track (>0)
tdble radius
Radius in meters of the middle of the track (>0)
tdble arc
Arc in rad of the curve (>0)
tdble lgfromstart
Length of beginning of segment from starting line.
t3Dd center
Center of the curve.
tdble length
Length in meters of the middle of the track.
tdble radiusl
Radius in meters of the left side of the track (>0)
struct trackSeg * next
Next segment.
tdble startWidth
Width of the beginning of the segment.
struct trackSeg * prev
Previous segment.
int style
Border and barrier segments style:
struct trackSeg * side[2]
tdble width
Width of the segment (if constant width)
tdble endWidth
Width of the end of the segment.
tdble kRoughWaveLen
Wave length in m of the surface.
tdble kRoughness
Roughtness in m of the surface (wave height)
int GfCreateDir(char *path)
Create directory for given path recursively, so all missing parent directories are created as well.
#define GFPARM_RMODE_CREAT
Allow an empty in-memory set on file-open failure; does not write a file.
#define GFPARM_RMODE_STD
Return a new handle sharing cached data for this filename, if available.
#define GFPARM_MMODE_RELSRC
release ref after the merge
#define GFPARM_MMODE_RELDST
release tgt after the merge
#define GFPARM_MMODE_SRC
Include ref attributes; merge common attributes using ref restrictions and tgt values.
#define GFPARM_MMODE_DST
Include tgt attributes; merge common attributes using ref restrictions and tgt values.
#define TR_XS
X Start angle.
#define TR_RSIDE
Right side segment (outer segment)
#define TR_CS
Center start angle.
#define TR_MAIN
Main track segment (ie road part)
#define TR_LFT
Left curve.
#define TR_LPOS_SEGMENT
Relative to the segment which the point is located, including border and sides, mostly used for conta...
#define TR_RBORDER
Right border segment (inner segment)
#define TR_LBORDER
Left border segment (inner segment)
#define TR_LPOS_TRACK
Local position relative to the outermost barriers, mostly used for collision detection with barrier.
#define TR_LSIDE
Left side segment (outer segment)
#define TR_CURB
Curb (border only)
#define TR_RGT
Right curve.
#define TR_ZS
Rotation angles of the track in rad anti-clockwise: Index in:
#define TR_SR
Start-Right corner.
int track(tModInfo *modInfo)
static const char * SuspSect[4]
static const char * WheelSect[4]