From e3d04f2d9c19b4d15a071d07c2eae40e7c8f4fe5 Mon Sep 17 00:00:00 2001 From: torcs-ng Date: Wed, 22 Dec 2021 23:20:30 +0000 Subject: [PATCH] - fix sd2-trackgen raceline git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@7839 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: dd359d6965f4d0a4a537dd6369a755f060e92ea2 Former-commit-id: 8d2ce421e948c2e8f2f3c574472ec164530ad463 --- src/tools/trackgen/raceline.cpp | 428 ++- src/tools/trackgen/track.cpp | 4478 ++++++++++++++++--------------- src/tools/trackgen/trackgen.h | 11 +- 3 files changed, 2460 insertions(+), 2457 deletions(-) diff --git a/src/tools/trackgen/raceline.cpp b/src/tools/trackgen/raceline.cpp index 772e609ed..30b63a396 100644 --- a/src/tools/trackgen/raceline.cpp +++ b/src/tools/trackgen/raceline.cpp @@ -24,14 +24,12 @@ #include #include - - - -struct RacelineSegment { - vec2d t; // raceline - vec2d l; // left track border - vec2d r; // right track border - double lane; // 0.0: left, 1.0: right +struct RacelineSegment +{ + vec2d t; // raceline + vec2d l; // left track border + vec2d r; // right track border + double lane; // 0.0: left, 1.0: right }; static const double SegLength = 2.0; @@ -42,277 +40,263 @@ static double SideDistInt = 2.0; // Security distance wrt inside static double trackWidth = 0.0; static const double SecurityR = 100.0; // Security radius - - - static void SplitTrack(tTrack *ptrack) { - const tTrackSeg *seg = ptrack->seg; - const tTrackSeg *first = NULL; - // Find pointer to start (seems not to start at the "start" all the time, e.g e-track-1) - do { - if (seg->lgfromstart == 0.0) { - first = seg; - break; - } - seg = seg->next; - } while (ptrack->seg != seg); - - trackWidth = seg->width; - nSegments = (int) floor(ptrack->length/SegLength); - rlseg = new RacelineSegment[nSegments]; + const tTrackSeg *seg = ptrack->seg; + const tTrackSeg *first = NULL; + // Find pointer to start (seems not to start at the "start" all the time, e.g e-track-1) + do { + if (seg->lgfromstart == 0.0) + { + first = seg; + break; + } + seg = seg->next; + } while (ptrack->seg != seg); - double lastSegLen = 0.0; - double curSegLen = 0.0; - int currentSegId = 0; + trackWidth = seg->width; + nSegments = (int) floor(ptrack->length/SegLength); + rlseg = new RacelineSegment[nSegments]; - do { - if (seg->type == TR_STR) { - double scale = seg->length; - double dxl = (seg->vertex[TR_EL].x - seg->vertex[TR_SL].x) / scale; - double dyl = (seg->vertex[TR_EL].y - seg->vertex[TR_SL].y) / scale; - double dxr = (seg->vertex[TR_ER].x - seg->vertex[TR_SR].x) / scale; - double dyr = (seg->vertex[TR_ER].y - seg->vertex[TR_SR].y) / scale; - - for (int i = 0; curSegLen < seg->length && currentSegId < nSegments; i++) { - rlseg[currentSegId].l.x = seg->vertex[TR_SL].x + dxl *curSegLen; - rlseg[currentSegId].l.y = seg->vertex[TR_SL].y + dyl *curSegLen; - rlseg[currentSegId].r.x = seg->vertex[TR_SR].x + dxr *curSegLen; - rlseg[currentSegId].r.y = seg->vertex[TR_SR].y + dyr *curSegLen; - rlseg[currentSegId].t = (rlseg[currentSegId].l + rlseg[currentSegId].r) / 2.0; - rlseg[currentSegId].lane = 0.5; + double lastSegLen = 0.0; + double curSegLen = 0.0; + int currentSegId = 0; - currentSegId++; - lastSegLen = curSegLen; - curSegLen += SegLength; - } - } else { - double dphi = 1.0/seg->radius; - vec2d c(seg->center.x, seg->center.y); - dphi = (seg->type == TR_LFT) ? dphi : -dphi; + do + { + if (seg->type == TR_STR) + { + double scale = seg->length; + double dxl = (seg->vertex[TR_EL].x - seg->vertex[TR_SL].x) / scale; + double dyl = (seg->vertex[TR_EL].y - seg->vertex[TR_SL].y) / scale; + double dxr = (seg->vertex[TR_ER].x - seg->vertex[TR_SR].x) / scale; + double dyr = (seg->vertex[TR_ER].y - seg->vertex[TR_SR].y) / scale; - vec2d l(seg->vertex[TR_SL].x, seg->vertex[TR_SL].y); - vec2d r(seg->vertex[TR_SR].x, seg->vertex[TR_SR].y); + for (int i = 0; curSegLen < seg->length && currentSegId < nSegments; i++) + { + rlseg[currentSegId].l.x = seg->vertex[TR_SL].x + dxl *curSegLen; + rlseg[currentSegId].l.y = seg->vertex[TR_SL].y + dyl *curSegLen; + rlseg[currentSegId].r.x = seg->vertex[TR_SR].x + dxr *curSegLen; + rlseg[currentSegId].r.y = seg->vertex[TR_SR].y + dyr *curSegLen; + rlseg[currentSegId].t = (rlseg[currentSegId].l + rlseg[currentSegId].r) / 2.0; + rlseg[currentSegId].lane = 0.5; - for (int i = 0; curSegLen < seg->length && currentSegId < nSegments; i++) { - double phi = curSegLen*dphi; - rlseg[currentSegId].l = l.rotate(c, phi); - rlseg[currentSegId].r = r.rotate(c, phi); - rlseg[currentSegId].t = (rlseg[currentSegId].l + rlseg[currentSegId].r) / 2.0; - rlseg[currentSegId].lane = 0.5; + currentSegId++; + lastSegLen = curSegLen; + curSegLen += SegLength; + } + } + else + { + double dphi = 1.0/seg->radius; + vec2d c(seg->center.x, seg->center.y); + dphi = (seg->type == TR_LFT) ? dphi : -dphi; - currentSegId++; - lastSegLen = curSegLen; - curSegLen += SegLength; - } - } + vec2d l(seg->vertex[TR_SL].x, seg->vertex[TR_SL].y); + vec2d r(seg->vertex[TR_SR].x, seg->vertex[TR_SR].y); - curSegLen = SegLength - (seg->length - lastSegLen); - lastSegLen = curSegLen; - while (curSegLen > SegLength) { - curSegLen -= SegLength; - } + for (int i = 0; curSegLen < seg->length && currentSegId < nSegments; i++) + { + double phi = curSegLen*dphi; + rlseg[currentSegId].l = l.rotate(c, phi); + rlseg[currentSegId].r = r.rotate(c, phi); + rlseg[currentSegId].t = (rlseg[currentSegId].l + rlseg[currentSegId].r) / 2.0; + rlseg[currentSegId].lane = 0.5; - seg = seg->next; - } while (first != seg); + currentSegId++; + lastSegLen = curSegLen; + curSegLen += SegLength; + } + } + + curSegLen = SegLength - (seg->length - lastSegLen); + lastSegLen = curSegLen; + + while (curSegLen > SegLength) + { + curSegLen -= SegLength; + } + + seg = seg->next; + } while (first != seg); } - - - static double GetRInverse(int prev, vec2d p, int next) { - - double x1 = rlseg[next].t.x - p.x; - double y1 = rlseg[next].t.y - p.y; - double x2 = rlseg[prev].t.x - p.x; - double y2 = rlseg[prev].t.y - p.y; - double x3 = rlseg[next].t.x - rlseg[prev].t.x; - double y3 = rlseg[next].t.y - rlseg[prev].t.y; - double det = x1 * y2 - x2 * y1; - double n1 = x1 * x1 + y1 * y1; - double n2 = x2 * x2 + y2 * y2; - double n3 = x3 * x3 + y3 * y3; - double nnn = sqrt(n1 * n2 * n3); + double x1 = rlseg[next].t.x - p.x; + double y1 = rlseg[next].t.y - p.y; + double x2 = rlseg[prev].t.x - p.x; + double y2 = rlseg[prev].t.y - p.y; + double x3 = rlseg[next].t.x - rlseg[prev].t.x; + double y3 = rlseg[next].t.y - rlseg[prev].t.y; - return 2 * det / nnn; + double det = x1 * y2 - x2 * y1; + double n1 = x1 * x1 + y1 * y1; + double n2 = x2 * x2 + y2 * y2; + double n3 = x3 * x3 + y3 * y3; + double nnn = sqrt(n1 * n2 * n3); + + return 2 * det / nnn; } - - - static void UpdateTxTy(int i) { - rlseg[i].t = rlseg[i].lane*rlseg[i].r + (1.0 - rlseg[i].lane)*rlseg[i].l; + rlseg[i].t = rlseg[i].lane*rlseg[i].r + (1.0 - rlseg[i].lane)*rlseg[i].l; } - - - static void AdjustRadius(int prev, int i, int next, double TargetRInverse, double Security = 0.0) { - double OldLane = rlseg[i].lane; + double OldLane = rlseg[i].lane; - // Start by aligning points for a reasonable initial lane - rlseg[i].lane = - (-(rlseg[next].t.y - rlseg[prev].t.y) * (rlseg[i].l.x - rlseg[prev].t.x) + - ( rlseg[next].t.x - rlseg[prev].t.x) * (rlseg[i].l.y - rlseg[prev].t.y)) / - ( (rlseg[next].t.y - rlseg[prev].t.y) * (rlseg[i].r.x - rlseg[i].l.x) - - ( rlseg[next].t.x - rlseg[prev].t.x) * (rlseg[i].r.y - rlseg[i].l.y)); - if (rlseg[i].lane < -0.2) - rlseg[i].lane = -0.2; - else if (rlseg[i].lane > 1.2) - rlseg[i].lane = 1.2; - UpdateTxTy(i); + // Start by aligning points for a reasonable initial lane + rlseg[i].lane = + (-(rlseg[next].t.y - rlseg[prev].t.y) * (rlseg[i].l.x - rlseg[prev].t.x) + + ( rlseg[next].t.x - rlseg[prev].t.x) * (rlseg[i].l.y - rlseg[prev].t.y)) / + ( (rlseg[next].t.y - rlseg[prev].t.y) * (rlseg[i].r.x - rlseg[i].l.x) - + ( rlseg[next].t.x - rlseg[prev].t.x) * (rlseg[i].r.y - rlseg[i].l.y)); + if (rlseg[i].lane < -0.2) + rlseg[i].lane = -0.2; + else if (rlseg[i].lane > 1.2) + rlseg[i].lane = 1.2; + UpdateTxTy(i); - // Newton-like resolution method - const double dLane = 0.0001; - vec2d d = dLane * (rlseg[i].r - rlseg[i].l); - double dRInverse = GetRInverse(prev, rlseg[i].t + d, next); + // Newton-like resolution method + const double dLane = 0.0001; + vec2d d = dLane * (rlseg[i].r - rlseg[i].l); + double dRInverse = GetRInverse(prev, rlseg[i].t + d, next); - if (dRInverse > 0.000000001) { - rlseg[i].lane += (dLane / dRInverse) * TargetRInverse; + if (dRInverse > 0.000000001) + { + rlseg[i].lane += (dLane / dRInverse) * TargetRInverse; - double ExtLane = (SideDistExt + Security) / trackWidth; - double IntLane = (SideDistInt + Security) / trackWidth; - if (ExtLane > 0.5) - ExtLane = 0.5; - if (IntLane > 0.5) - IntLane = 0.5; + double ExtLane = (SideDistExt + Security) / trackWidth; + double IntLane = (SideDistInt + Security) / trackWidth; + if (ExtLane > 0.5) + ExtLane = 0.5; + if (IntLane > 0.5) + IntLane = 0.5; - if (TargetRInverse >= 0.0) - { - if (rlseg[i].lane < IntLane) - rlseg[i].lane = IntLane; - if (1 - rlseg[i].lane < ExtLane) - { - if (1 - OldLane < ExtLane) - rlseg[i].lane = MIN(OldLane, rlseg[i].lane); - else - rlseg[i].lane = 1 - ExtLane; - } - } - else - { - if (rlseg[i].lane < ExtLane) - { - if (OldLane < ExtLane) - rlseg[i].lane = MAX(OldLane, rlseg[i].lane); - else - rlseg[i].lane = ExtLane; - } - if (1 - rlseg[i].lane < IntLane) - rlseg[i].lane = 1 - IntLane; - } - } + if (TargetRInverse >= 0.0) + { + if (rlseg[i].lane < IntLane) + rlseg[i].lane = IntLane; + if (1 - rlseg[i].lane < ExtLane) + { + if (1 - OldLane < ExtLane) + rlseg[i].lane = MIN(OldLane, rlseg[i].lane); + else + rlseg[i].lane = 1 - ExtLane; + } + } + else + { + if (rlseg[i].lane < ExtLane) + { + if (OldLane < ExtLane) + rlseg[i].lane = MAX(OldLane, rlseg[i].lane); + else + rlseg[i].lane = ExtLane; + } + if (1 - rlseg[i].lane < IntLane) + rlseg[i].lane = 1 - IntLane; + } + } - UpdateTxTy(i); + UpdateTxTy(i); } - - - static void Smooth(int Step) { - int prev = ((nSegments - Step) / Step) * Step; - int prevprev = prev - Step; - int next = Step; - int nextnext = next + Step; + int prev = ((nSegments - Step) / Step) * Step; + int prevprev = prev - Step; + int next = Step; + int nextnext = next + Step; - for (int i = 0; i <= nSegments - Step; i += Step) { - double ri0 = GetRInverse(prevprev, rlseg[prev].t, i); - double ri1 = GetRInverse(i, rlseg[next].t, nextnext); - - double lPrev = (rlseg[i].t-rlseg[prev].t).len(); - double lNext = (rlseg[i].t-rlseg[next].t).len(); - double TargetRInverse = (lNext * ri0 + lPrev * ri1) / (lNext + lPrev); + for (int i = 0; i <= nSegments - Step; i += Step) + { + double ri0 = GetRInverse(prevprev, rlseg[prev].t, i); + double ri1 = GetRInverse(i, rlseg[next].t, nextnext); - double Security = lPrev * lNext / (8 * SecurityR); - AdjustRadius(prev, i, next, TargetRInverse, Security); + double lPrev = (rlseg[i].t-rlseg[prev].t).len(); + double lNext = (rlseg[i].t-rlseg[next].t).len(); + double TargetRInverse = (lNext * ri0 + lPrev * ri1) / (lNext + lPrev); - prevprev = prev; - prev = i; - next = nextnext; - nextnext = next + Step; - if (nextnext > nSegments - Step) - nextnext = 0; - } + double Security = lPrev * lNext / (8 * SecurityR); + AdjustRadius(prev, i, next, TargetRInverse, Security); + + prevprev = prev; + prev = i; + next = nextnext; + nextnext = next + Step; + if (nextnext > nSegments - Step) + nextnext = 0; + } } - - - static void StepInterpolate(int iMin, int iMax, int Step) { - int next = (iMax + Step) % nSegments; - if (next > nSegments - Step) - next = 0; + int next = (iMax + Step) % nSegments; + if (next > nSegments - Step) + next = 0; - int prev = (((nSegments + iMin - Step) % nSegments) / Step) * Step; - if (prev > nSegments - Step) - prev -= Step; + int prev = (((nSegments + iMin - Step) % nSegments) / Step) * Step; + if (prev > nSegments - Step) + prev -= Step; - double ir0 = GetRInverse(prev, rlseg[iMin].t, iMax % nSegments); - double ir1 = GetRInverse(iMin, rlseg[iMax % nSegments].t, next); - for (int k = iMax; --k > iMin;) { - double x = double(k - iMin) / double(iMax - iMin); - double TargetRInverse = x * ir1 + (1 - x) * ir0; - AdjustRadius(iMin, k, iMax % nSegments, TargetRInverse); - } + double ir0 = GetRInverse(prev, rlseg[iMin].t, iMax % nSegments); + double ir1 = GetRInverse(iMin, rlseg[iMax % nSegments].t, next); + + for (int k = iMax; --k > iMin;) + { + double x = double(k - iMin) / double(iMax - iMin); + double TargetRInverse = x * ir1 + (1 - x) * ir0; + AdjustRadius(iMin, k, iMax % nSegments, TargetRInverse); + } } - - - static void Interpolate(int Step) { - if (Step > 1) - { - int i; - for (i = Step; i <= nSegments - Step; i += Step) - StepInterpolate(i - Step, i, Step); - StepInterpolate(i - Step, nSegments, Step); - } + if (Step > 1) + { + int i; + for (i = Step; i <= nSegments - Step; i += Step) + StepInterpolate(i - Step, i, Step); + StepInterpolate(i - Step, nSegments, Step); + } } - - - void generateRaceLine(tTrack *pTrack, const double lSideDistExt, const double lSideDistInt) { - SideDistExt = lSideDistExt; - SideDistInt = lSideDistInt; - - SplitTrack(pTrack); + SideDistExt = lSideDistExt; + SideDistInt = lSideDistInt; - for (int Step = 128; (Step /= 2) > 0;) { - for (int i = 100 * int(sqrt((double)Step)); --i >= 0;) { - Smooth(Step); - } - Interpolate(Step); - } + SplitTrack(pTrack); + + for (int Step = 128; (Step /= 2) > 0;) + { + for (int i = 100 * int(sqrt((double)Step)); --i >= 0;) + { + Smooth(Step); + } + + Interpolate(Step); + } } - - double getTexureOffset(double length) { - if (!rlseg) { - return 0.0; - } + if (!rlseg) + { + return 0.0; + } - double seg = length/SegLength; // normalize - double rem = seg - floor(seg); // rem [0..0.999] + double seg = length/SegLength; // normalize + double rem = seg - floor(seg); // rem [0..0.999] - // Average, does not work perfectly on the track end/start transition, but should not matter - int length1 = ((int) floor(seg)) % nSegments; - int length2 = (length1 + 1) % nSegments; + // Average, does not work perfectly on the track end/start transition, but should not matter + int length1 = ((int) floor(seg)) % nSegments; + int length2 = (length1 + 1) % nSegments; - return (rlseg[length1].lane*(1.0 - rem) + rlseg[length2].lane*rem) - 0.5; + return (rlseg[length1].lane*(1.0 - rem) + rlseg[length2].lane*rem) - 0.5; } - - - - - diff --git a/src/tools/trackgen/track.cpp b/src/tools/trackgen/track.cpp index 5a17f4918..be510294c 100644 --- a/src/tools/trackgen/track.cpp +++ b/src/tools/trackgen/track.cpp @@ -17,8 +17,8 @@ * * ***************************************************************************/ -/** @file - +/** @file + @author Eric Espie @version $Id$ */ @@ -45,13 +45,13 @@ typedef struct texElt { char *name; char *namebump; - char * nameraceline; + char * nameraceline; int mipmap; // Not yet used. unsigned int texid; struct texElt *next; } tTexElt; -typedef struct dispElt +typedef struct dispElt { int start; int nb; @@ -85,166 +85,166 @@ static tdble TrackStep; #endif static void initPits(tTrack *theTrack, void *TrackHandle, tTrackPitInfo *pits) { - tTrackSeg *curMainSeg; - tTrackSeg *curPitSeg = NULL; - tTrackSeg *pitBuildingsStart = NULL; - const char *segName; - tTrkLocPos curPos; - int i; - bool found = false; - bool changeSeg = false; - tdble offset = 0; - tdble toStart = 0; - static char path2[256]; + tTrackSeg *curMainSeg; + tTrackSeg *curPitSeg = NULL; + tTrackSeg *pitBuildingsStart = NULL; + const char *segName; + tTrkLocPos curPos; + int i; + bool found = false; + bool changeSeg = false; + tdble offset = 0; + tdble toStart = 0; + static char path2[256]; - sprintf(path2, "%s/%s", TRK_SECT_MAIN, TRK_SECT_PITS); + sprintf(path2, "%s/%s", TRK_SECT_MAIN, TRK_SECT_PITS); - // In TR_PIT_NO_BUILDING, the pit positions are located exactly the same, - // as in the TR_PIT_ON_TRACK_SIDE. It differs only later, showing/not showing - // the buildings. + // In TR_PIT_NO_BUILDING, the pit positions are located exactly the same, + // as in the TR_PIT_ON_TRACK_SIDE. It differs only later, showing/not showing + // the buildings. switch (pits->type) { - case TR_PIT_ON_TRACK_SIDE: - case TR_PIT_NO_BUILDING: + case TR_PIT_ON_TRACK_SIDE: + case TR_PIT_NO_BUILDING: pits->driversPitsNb = MIN(pits->nPitSeg,pits->nMaxPits); - pits->driversPits = (tTrackOwnPit*)calloc(pits->driversPitsNb, sizeof(tTrackOwnPit)); - - curPos.type = TR_TOMIDDLE; - //TR_LPOS_MAIN; //NB: TR_LPOS_MAIN not handled by RtTrackLocal2Global! + pits->driversPits = (tTrackOwnPit*)calloc(pits->driversPitsNb, sizeof(tTrackOwnPit)); - segName = GfParmGetStr(TrackHandle, path2, TRK_ATT_BUILDINGS_START, NULL); - if (segName != 0) { - pitBuildingsStart = theTrack->seg; - found = false; + curPos.type = TR_TOMIDDLE; + //TR_LPOS_MAIN; //NB: TR_LPOS_MAIN not handled by RtTrackLocal2Global! + + segName = GfParmGetStr(TrackHandle, path2, TRK_ATT_BUILDINGS_START, NULL); + if (segName != 0) { + pitBuildingsStart = theTrack->seg; + found = false; for(i = 0; i <= theTrack->nseg; i++) { if (!strcmp(segName, pitBuildingsStart->name)) { - found = true; + found = true; } else if (found) { - pitBuildingsStart = pitBuildingsStart->next; - break; - } - pitBuildingsStart = pitBuildingsStart->prev; - } + pitBuildingsStart = pitBuildingsStart->next; + break; + } + pitBuildingsStart = pitBuildingsStart->prev; + } if (!found) { - pitBuildingsStart = NULL; - } - } + pitBuildingsStart = NULL; + } + } - if (pitBuildingsStart == NULL) - pitBuildingsStart = pits->pitStart; + if (pitBuildingsStart == NULL) + pitBuildingsStart = pits->pitStart; - curMainSeg = pitBuildingsStart->prev; + curMainSeg = pitBuildingsStart->prev; - changeSeg = true; - offset = 0; - toStart = 0; - i = 0; + changeSeg = true; + offset = 0; + toStart = 0; + i = 0; while (i < pits->driversPitsNb) { if (changeSeg) { - changeSeg = false; - offset = 0; - curMainSeg = curMainSeg->next; + changeSeg = false; + offset = 0; + curMainSeg = curMainSeg->next; switch (pits->side) { - case TR_RGT: - curPitSeg = curMainSeg->rside; + case TR_RGT: + curPitSeg = curMainSeg->rside; if (curPitSeg->rside) { - offset = curPitSeg->width; - curPitSeg = curPitSeg->rside; - } - break; - - case TR_LFT: - curPitSeg = curMainSeg->lside; + offset = curPitSeg->width; + curPitSeg = curPitSeg->rside; + } + break; + + case TR_LFT: + curPitSeg = curMainSeg->lside; if (curPitSeg->lside) { - offset = curPitSeg->width; - curPitSeg = curPitSeg->lside; - } - break; - } + offset = curPitSeg->width; + curPitSeg = curPitSeg->lside; + } + break; + } - curPos.seg = curMainSeg; + curPos.seg = curMainSeg; if (toStart >= curMainSeg->length) { - toStart -= curMainSeg->length; - changeSeg = true; - continue; - } - }//if changeSeg - - /* Not the real position but the start and border one - * instead of center */ - //RtTrackLocal2Global expects toStart as a length in meters for straight, - //and as an angle in radian for curves - //TODO(kilo) - //Proper handling of this should enable non-linear pitlanes. - //Postponed after 2.0 -#if 0 - tdble pitCenter = toStart + pits->len / 2.0; - switch(curMainSeg->type) { - case TR_STR: - pits->driversPits[i].pos.toStart = pitCenter; - break; + toStart -= curMainSeg->length; + changeSeg = true; + continue; + } + }//if changeSeg - case TR_LFT: - case TR_RGT: - pits->driversPits[i].pos.toStart = pitCenter / curMainSeg->radius; - break; - } + /* Not the real position but the start and border one + * instead of center */ + //RtTrackLocal2Global expects toStart as a length in meters for straight, + //and as an angle in radian for curves + //TODO(kilo) + //Proper handling of this should enable non-linear pitlanes. + //Postponed after 2.0 +#if 0 + tdble pitCenter = toStart + pits->len / 2.0; + switch(curMainSeg->type) { + case TR_STR: + pits->driversPits[i].pos.toStart = pitCenter; + break; + + case TR_LFT: + case TR_RGT: + pits->driversPits[i].pos.toStart = pitCenter / curMainSeg->radius; + break; + } #endif - //TODO(kilo) get rid of following line when above feature is ready - curPos.toStart = toStart; + //TODO(kilo) get rid of following line when above feature is ready + curPos.toStart = toStart; switch (pits->side) { - case TR_RGT: - curPos.toRight = -offset - RtTrackGetWidth(curPitSeg, toStart); - curPos.toLeft = curMainSeg->width - curPos.toRight; + case TR_RGT: + curPos.toRight = -offset - RtTrackGetWidth(curPitSeg, toStart); + curPos.toLeft = curMainSeg->width - curPos.toRight; curPos.toMiddle = - curMainSeg->width / 2.0 + curPos.toRight; - break; + break; - case TR_LFT: - curPos.toLeft = -offset - RtTrackGetWidth(curPitSeg, toStart); - curPos.toRight = curMainSeg->width - curPos.toLeft; - curPos.toMiddle = curMainSeg->width / 2.0 - curPos.toLeft; - break; - } + case TR_LFT: + curPos.toLeft = -offset - RtTrackGetWidth(curPitSeg, toStart); + curPos.toRight = curMainSeg->width - curPos.toLeft; + curPos.toMiddle = curMainSeg->width / 2.0 - curPos.toLeft; + break; + } - memcpy(&(pits->driversPits[i].pos), &curPos, sizeof(curPos)); - toStart += pits->len; + memcpy(&(pits->driversPits[i].pos), &curPos, sizeof(curPos)); + toStart += pits->len; if (toStart >= curMainSeg->length) { - toStart -= curMainSeg->length; - changeSeg = true; - } + toStart -= curMainSeg->length; + changeSeg = true; + } - i++; + i++; - }//while i - break; + }//while i + break; - case TR_PIT_ON_SEPARATE_PATH: - break; - - case TR_PIT_NONE: - break; - } + case TR_PIT_ON_SEPARATE_PATH: + break; + + case TR_PIT_NONE: + break; + } } /** Bug fix: - If width of border decreased, additional vertices are needed to avoid missing surfaces - Implementation: - Compares old end vertices and new start vertices, set startNeeded if one is different + If width of border decreased, additional vertices are needed to avoid missing surfaces + Implementation: + Compares old end vertices and new start vertices, set startNeeded if one is different **/ int InitScene(tTrack *Track, void *TrackHandle, int bump, int raceline) @@ -317,7 +317,7 @@ InitScene(tTrack *Track, void *TrackHandle, int bump, int raceline) tdble delatz = Track->seg->next->vertex[TR_SL].z - Track->seg->vertex[TR_EL].z; tdble delata = Track->seg->next->angle[TR_ZS] - Track->seg->angle[TR_ZE]; NORM_PI_PI(delata); - + printf("Delta X = %f\n", delatx); printf("Delta Y = %f\n", delaty); printf("Delta Z = %f\n", delatz); @@ -330,217 +330,224 @@ InitScene(tTrack *Track, void *TrackHandle, int bump, int raceline) Groups = (tGroup *)calloc(Track->nseg, sizeof(tGroup)); ActiveGroups = 0; GroupNb = Track->nseg; - + width = Track->width; //wi2 = width / 2.0; // Never used. - if (raceline) { - double SideDistExt = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLEXT, (char*)NULL, 2.0); - double SideDistInt = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLINT, (char*)NULL, 2.0); - generateRaceLine(Track, SideDistExt, SideDistInt); - } - trkpos.type = TR_LPOS_MAIN; + double rlWidthScale = 1.0; + double rlOffset = 0.0; + + if (raceline) + { + double SideDistExt = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLEXT, (char*)NULL, 2.0); + double SideDistInt = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLINT, (char*)NULL, 2.0); + rlWidthScale = GfParmGetNum(TrackHandle, TRK_SECT_MAIN, TRK_ATT_RLWIDTHSCALE, (char*)NULL, 1.0); + rlOffset = (1.0 - 1.0/rlWidthScale)/2.0; + generateRaceLine(Track, SideDistExt, SideDistInt); + } + + trkpos.type = TR_LPOS_MAIN; #define SETTEXTURE(texname, texnamebump, texnameraceline, _mipmap) do { \ - int found = 0; \ - curTexElt = texList; \ - if (curTexElt == NULL) { \ - curTexElt = (tTexElt*)calloc(1, sizeof(tTexElt)); \ - curTexElt->next = curTexElt; \ - texList = curTexElt; \ - curTexElt->name = strdup(texname); \ - curTexElt->namebump = strdup(texnamebump); \ + int found = 0; \ + curTexElt = texList; \ + if (curTexElt == NULL) { \ + curTexElt = (tTexElt*)calloc(1, sizeof(tTexElt)); \ + curTexElt->next = curTexElt; \ + texList = curTexElt; \ + curTexElt->name = strdup(texname); \ + curTexElt->namebump = strdup(texnamebump); \ curTexElt->nameraceline = strdup(texnameraceline); \ - curTexElt->mipmap = _mipmap; \ + curTexElt->mipmap = _mipmap; \ curTexElt->texid = GenTexId++; \ - } else { \ - do { \ - curTexElt = curTexElt->next; \ - if (strcmp(texname, curTexElt->name) == 0) { \ - found = 1; \ - break; \ - } \ - } while (curTexElt != texList); \ - if (!found) { \ - curTexElt = (tTexElt*)calloc(1, sizeof(tTexElt)); \ - curTexElt->next = texList->next; \ - texList->next = curTexElt; \ - texList = curTexElt; \ - curTexElt->name = strdup(texname); \ + } else { \ + do { \ + curTexElt = curTexElt->next; \ + if (strcmp(texname, curTexElt->name) == 0) { \ + found = 1; \ + break; \ + } \ + } while (curTexElt != texList); \ + if (!found) { \ + curTexElt = (tTexElt*)calloc(1, sizeof(tTexElt)); \ + curTexElt->next = texList->next; \ + texList->next = curTexElt; \ + texList = curTexElt; \ + curTexElt->name = strdup(texname); \ curTexElt->namebump = strdup(texnamebump); \ curTexElt->nameraceline = strdup(texnameraceline); \ curTexElt->mipmap = _mipmap; \ curTexElt->texid = GenTexId++; \ - } \ - } \ - curTexId = curTexElt->texid; \ + } \ + } \ + curTexId = curTexElt->texid; \ } while (0) #define NBELTLIST 1 #define NEWDISPLIST(texchange, _name, _id) do { \ - if (!bump || (*(curTexElt->namebump) != 0)) { \ - if (theCurDispElt != NULL) { \ - startNeeded = texchange; \ - if (theCurDispElt->start != nbvert) { \ - theCurDispElt->nb = nbvert - theCurDispElt->start; \ - theCurDispElt = aDispElt = (tDispElt*)malloc(sizeof(tDispElt)); \ - aDispElt->start = nbvert; \ - aDispElt->nb = 0; \ - aDispElt->name = strdup(_name); \ - aDispElt->id = _id; \ - aDispElt->texture = curTexElt; \ - aDispElt->surfType = 0; \ - if (Groups[_id].nb == 0) { \ - ActiveGroups++; \ - aDispElt->next = aDispElt; \ - Groups[_id].dispList = aDispElt; \ - } else { \ - aDispElt->next = Groups[_id].dispList->next; \ - Groups[_id].dispList->next = aDispElt; \ - Groups[_id].dispList = aDispElt; \ - } \ - Groups[_id].nb++; \ - } else { \ - aDispElt->texture = curTexElt; \ - aDispElt->surfType = 0; \ - } \ - } else { \ - theCurDispElt = aDispElt = (tDispElt*)malloc(sizeof(tDispElt)); \ - aDispElt->start = nbvert; \ - aDispElt->nb = 0; \ - aDispElt->name = strdup(_name); \ - aDispElt->id = _id; \ - aDispElt->texture = curTexElt; \ - aDispElt->surfType = 0; \ - aDispElt->next = aDispElt; \ - Groups[_id].dispList = aDispElt; \ - Groups[_id].nb++; \ - ActiveGroups++; \ - } \ - /* fprintf(stderr, "%s %d (%s)\n", _name, _id, curTexElt->name); */ \ - } \ + if (!bump || (*(curTexElt->namebump) != 0)) { \ + if (theCurDispElt != NULL) { \ + startNeeded = texchange; \ + if (theCurDispElt->start != nbvert) { \ + theCurDispElt->nb = nbvert - theCurDispElt->start; \ + theCurDispElt = aDispElt = (tDispElt*)malloc(sizeof(tDispElt)); \ + aDispElt->start = nbvert; \ + aDispElt->nb = 0; \ + aDispElt->name = strdup(_name); \ + aDispElt->id = _id; \ + aDispElt->texture = curTexElt; \ + aDispElt->surfType = 0; \ + if (Groups[_id].nb == 0) { \ + ActiveGroups++; \ + aDispElt->next = aDispElt; \ + Groups[_id].dispList = aDispElt; \ + } else { \ + aDispElt->next = Groups[_id].dispList->next; \ + Groups[_id].dispList->next = aDispElt; \ + Groups[_id].dispList = aDispElt; \ + } \ + Groups[_id].nb++; \ + } else { \ + aDispElt->texture = curTexElt; \ + aDispElt->surfType = 0; \ + } \ + } else { \ + theCurDispElt = aDispElt = (tDispElt*)malloc(sizeof(tDispElt)); \ + aDispElt->start = nbvert; \ + aDispElt->nb = 0; \ + aDispElt->name = strdup(_name); \ + aDispElt->id = _id; \ + aDispElt->texture = curTexElt; \ + aDispElt->surfType = 0; \ + aDispElt->next = aDispElt; \ + Groups[_id].dispList = aDispElt; \ + Groups[_id].nb++; \ + ActiveGroups++; \ + } \ + /* fprintf(stderr, "%s %d (%s)\n", _name, _id, curTexElt->name); */ \ + } \ } while (0) #define CHECKDISPLIST(mat, name, id, off) do { \ - const char *texname; \ - const char *texnamebump; \ + const char *texname; \ + const char *texnamebump; \ const char *texnameraceline; \ - int mipmap; \ - static char path_[256]; \ - if (Track->version < 4) { \ - sprintf(path_, "%s/%s/%s", TRK_SECT_SURFACES, TRK_LST_SURF, mat); \ + int mipmap; \ + static char path_[256]; \ + if (Track->version < 4) { \ + sprintf(path_, "%s/%s/%s", TRK_SECT_SURFACES, TRK_LST_SURF, mat); \ } else { \ - sprintf(path_, "%s/%s", TRK_SECT_SURFACES, mat); \ + sprintf(path_, "%s/%s", TRK_SECT_SURFACES, mat); \ } \ - texnamebump = GfParmGetStr(TrackHandle, path_, TRK_ATT_BUMPNAME, ""); \ + texnamebump = GfParmGetStr(TrackHandle, path_, TRK_ATT_BUMPNAME, ""); \ texnameraceline = GfParmGetStr(TrackHandle, path_, TRK_ATT_RACELINENAME, ""); \ - texname = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXTURE, "tr-asphalt.png"); \ - mipmap = (int)GfParmGetNum(TrackHandle, path_, TRK_ATT_TEXMIPMAP, (char*)NULL, 0); \ - SETTEXTURE(texname, texnamebump, texnameraceline, mipmap); \ - if ((curTexId != prevTexId) || (startNeeded)) { \ - const char *textype; \ + texname = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXTURE, "tr-asphalt.png"); \ + mipmap = (int)GfParmGetNum(TrackHandle, path_, TRK_ATT_TEXMIPMAP, (char*)NULL, 0); \ + SETTEXTURE(texname, texnamebump, texnameraceline, mipmap); \ + if ((curTexId != prevTexId) || (startNeeded)) { \ + const char *textype; \ if (bump) { \ - curTexType = 1; \ - curTexLink = 1; \ - curTexOffset = -off; \ - curTexSize = GfParmGetNum(TrackHandle, path_, TRK_ATT_BUMPSIZE, (char*)NULL, 20.0); \ - } else { \ - textype = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXTYPE, "continuous"); \ - if (strcmp(textype, "continuous") == 0) \ - curTexType = 1; \ - else \ - curTexType = 0; \ - textype = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXLINK, TRK_VAL_YES); \ - if (strcmp(textype, TRK_VAL_YES) == 0) \ - curTexLink = 1; \ - else \ - curTexLink = 0; \ - textype = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXSTARTBOUNDARY, TRK_VAL_NO); \ - if (strcmp(textype, TRK_VAL_YES) == 0) \ - curTexOffset = -off; \ - else \ - curTexOffset = 0; \ - curTexSize = GfParmGetNum(TrackHandle, path_, TRK_ATT_TEXSIZE, (char*)NULL, 20.0); \ - } \ - prevTexId = curTexId; \ - NEWDISPLIST(1, name, id); \ - } \ + curTexType = 1; \ + curTexLink = 1; \ + curTexOffset = -off; \ + curTexSize = GfParmGetNum(TrackHandle, path_, TRK_ATT_BUMPSIZE, (char*)NULL, 20.0); \ + } else { \ + textype = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXTYPE, "continuous"); \ + if (strcmp(textype, "continuous") == 0) \ + curTexType = 1; \ + else \ + curTexType = 0; \ + textype = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXLINK, TRK_VAL_YES); \ + if (strcmp(textype, TRK_VAL_YES) == 0) \ + curTexLink = 1; \ + else \ + curTexLink = 0; \ + textype = GfParmGetStr(TrackHandle, path_, TRK_ATT_TEXSTARTBOUNDARY, TRK_VAL_NO); \ + if (strcmp(textype, TRK_VAL_YES) == 0) \ + curTexOffset = -off; \ + else \ + curTexOffset = 0; \ + curTexSize = GfParmGetNum(TrackHandle, path_, TRK_ATT_TEXSIZE, (char*)NULL, 20.0); \ + } \ + prevTexId = curTexId; \ + NEWDISPLIST(1, name, id); \ + } \ } while (0) #define CHECKDISPLIST2(texture, mipmap, name, id) do { \ - char texname[300]; \ - sprintf(texname, "%s.png", texture); \ - SETTEXTURE(texname, "", "", mipmap); \ - if (curTexId != prevTexId) { \ - prevTexId = curTexId; \ - NEWDISPLIST(1, name, id); \ - } \ + char texname[300]; \ + sprintf(texname, "%s.png", texture); \ + SETTEXTURE(texname, "", "", mipmap); \ + if (curTexId != prevTexId) { \ + prevTexId = curTexId; \ + NEWDISPLIST(1, name, id); \ + } \ } while (0) #define CHECKDISPLIST3(texture, mipmap, name, id) do { \ - SETTEXTURE(texture, "", "", mipmap); \ - if (curTexId != prevTexId) { \ - prevTexId = curTexId; \ - NEWDISPLIST(1, name, id); \ - } \ + SETTEXTURE(texture, "", "", mipmap); \ + if (curTexId != prevTexId) { \ + prevTexId = curTexId; \ + NEWDISPLIST(1, name, id); \ + } \ } while (0) #define CLOSEDISPLIST() do { \ - theCurDispElt->nb = nbvert - theCurDispElt->start; \ + theCurDispElt->nb = nbvert - theCurDispElt->start; \ } while (0) #define SETPOINT(t1, t2, x, y, z) do { \ - if (*(curTexElt->name) != 0) { \ - tracktexcoord[2*nbvert] = t1; \ - tracktexcoord[2*nbvert+1] = t2; \ - trackvertices[3*nbvert] = x; \ - trackvertices[3*nbvert+1] = y; \ - trackvertices[3*nbvert+2] = z; \ - trackindices[nbvert] = nbvert; \ - ++nbvert; \ - } \ + if (*(curTexElt->name) != 0) { \ + tracktexcoord[2*nbvert] = t1; \ + tracktexcoord[2*nbvert+1] = t2; \ + trackvertices[3*nbvert] = x; \ + trackvertices[3*nbvert+1] = y; \ + trackvertices[3*nbvert+2] = z; \ + trackindices[nbvert] = nbvert; \ + ++nbvert; \ + } \ } while (0) #define SETPOINT2(t1, t2, x, y, z) do { \ - if (*(curTexElt->name) != 0) { \ - tracktexcoord[2*nbvert] = t1; \ - tracktexcoord[2*nbvert+1] = t2; \ - trackvertices[3*nbvert] = x; \ - trackvertices[3*nbvert+1] = y; \ - trackvertices[3*nbvert+2] = z; \ - trackindices[nbvert] = nbvert; \ - ++nbvert; \ - printf("x=%f y=%f z=%f u=%f v=%f\n", \ - (tdble)(x), (tdble)(y), (tdble)(z), \ - (tdble)(t1), (tdble)(t2)); \ - } \ + if (*(curTexElt->name) != 0) { \ + tracktexcoord[2*nbvert] = t1; \ + tracktexcoord[2*nbvert+1] = t2; \ + trackvertices[3*nbvert] = x; \ + trackvertices[3*nbvert+1] = y; \ + trackvertices[3*nbvert+2] = z; \ + trackindices[nbvert] = nbvert; \ + ++nbvert; \ + printf("x=%f y=%f z=%f u=%f v=%f\n", \ + (tdble)(x), (tdble)(y), (tdble)(z), \ + (tdble)(t1), (tdble)(t2)); \ + } \ } while (0) /* Count the number of vertice to allocate */ nbvert = 0; for (i = 0, seg = Track->seg->next; i < Track->nseg; i++, seg = seg->next) { - nbvert++; - switch (seg->type) { - case TR_STR: - nbvert += (int)(seg->length / LMAX); - break; - case TR_LFT: - nbvert += (int)(seg->arc * (seg->radiusr) / LMAX); - break; - case TR_RGT: - nbvert += (int)(seg->arc * (seg->radiusl) / LMAX); - break; - } + nbvert++; + switch (seg->type) { + case TR_STR: + nbvert += (int)(seg->length / LMAX); + break; + case TR_LFT: + nbvert += (int)(seg->arc * (seg->radiusr) / LMAX); + break; + case TR_RGT: + nbvert += (int)(seg->arc * (seg->radiusl) / LMAX); + break; + } } nbvert++; nbvert *= 30; nbvert+=58; /* start bridge */ nbvert+=12 + 10 * Track->pits.driversPitsNb; - // TODO: Investigate if this is a feasible solution, nbvert was perviously += 1000. + // TODO: Investigate if this is a feasible solution, nbvert was perviously += 1000. nbvert+=10000; /* safety margin */ printf("=== Indices Array Size = %d\n", nbvert); printf("=== Vertex Array Size = %d\n", nbvert * 3); @@ -557,117 +564,128 @@ InitScene(tTrack *Track, void *TrackHandle, int bump, int raceline) startNeeded = 1; runninglentgh = 0; for (i = 0, seg = Track->seg->next; i < Track->nseg; i++, seg = seg->next) { - CHECKDISPLIST(seg->surface->material, "tkMn", i, seg->lgfromstart); - if (!curTexLink) { - curTexSeg = 0; - } else { - curTexSeg = seg->lgfromstart; - } - curTexSeg += curTexOffset; + CHECKDISPLIST(seg->surface->material, "tkMn", i, seg->lgfromstart); + if (!curTexLink) { + curTexSeg = 0; + } else { + curTexSeg = seg->lgfromstart; + } + curTexSeg += curTexOffset; - if (raceline) { + if (raceline) + { // Required if some smaller than width tiled texture is used. curTexSize = seg->width; } - texLen = curTexSeg / curTexSize; - if (startNeeded || (runninglentgh > LG_STEP_MAX)) { - NEWDISPLIST(0, "tkMn", i); - runninglentgh = 0; - ts = 0; - if (raceline) { + texLen = curTexSeg / curTexSize; + if (startNeeded || (runninglentgh > LG_STEP_MAX)) { + NEWDISPLIST(0, "tkMn", i); + runninglentgh = 0; + ts = 0; + if (raceline) + { // Required if some smaller than width tiled texture is used. texMaxT = 1.0; - } else { + } + else + { // Normal case texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); } - SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, 0.0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - } - - switch (seg->type) { - case TR_STR: - ts = LMAX; - texStep = LMAX / curTexSize; - trkpos.seg = seg; - while (ts < seg->length) { - texLen += texStep; - trkpos.toStart = ts; + double rlto = getTexureOffset(seg->lgfromstart)/rlWidthScale; - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT - rlOffset + rlto, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, 0.0 + rlOffset + rlto, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + } - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + switch (seg->type) { + case TR_STR: + ts = LMAX; + texStep = LMAX / curTexSize; + trkpos.seg = seg; + while (ts < seg->length) { + texLen += texStep; + trkpos.toStart = ts; - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.0, x, y, RtTrackHeightL(&trkpos)); + double rlto = getTexureOffset(seg->lgfromstart + ts)/rlWidthScale; - ts += LMAX; - } - ts = seg->length; - break; - case TR_LFT: - step = LMAX / (seg->radiusr); - texStep = step * seg->radius / curTexSize; - anz = seg->angle[TR_ZS] + step; - ts = step; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz < seg->angle[TR_ZE]) { - texLen += texStep; - trkpos.toStart = ts; + SETPOINT(texLen, texMaxT - rlOffset + rlto, x, y, RtTrackHeightL(&trkpos)); - /* left */ - trkpos.toRight = width; - SETPOINT(texLen, texMaxT, seg->center.x + radiusl * sin(anz), seg->center.y - radiusl * cos(anz), RtTrackHeightL(&trkpos)); + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - /* right */ - trkpos.toRight = 0; - SETPOINT(texLen, 0.0, seg->center.x + radiusr * sin(anz), seg->center.y - radiusr * cos(anz), RtTrackHeightL(&trkpos)); + SETPOINT(texLen, 0.0 + rlOffset + rlto, x, y, RtTrackHeightL(&trkpos)); - ts += step; - anz += step; - } - ts = seg->arc; - break; - case TR_RGT: - step = LMAX / (seg->radiusl); - texStep = step * seg->radius / curTexSize; - anz = seg->angle[TR_ZS] - step; - ts = step; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz > seg->angle[TR_ZE]) { - texLen += texStep; - trkpos.toStart = ts; + ts += LMAX; + } + ts = seg->length; + break; + case TR_LFT: + step = LMAX / (seg->radiusr); + texStep = step * seg->radius / curTexSize; + anz = seg->angle[TR_ZS] + step; + ts = step; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz < seg->angle[TR_ZE]) { + texLen += texStep; + trkpos.toStart = ts; - /* left */ - trkpos.toRight = width; - SETPOINT(texLen, texMaxT, seg->center.x - radiusl * sin(anz), seg->center.y + radiusl * cos(anz), RtTrackHeightL(&trkpos)); + double rlto = getTexureOffset(seg->lgfromstart + ts*seg->radius)/rlWidthScale; + /* left */ + trkpos.toRight = width; + SETPOINT(texLen, texMaxT - rlOffset + rlto, seg->center.x + radiusl * sin(anz), seg->center.y - radiusl * cos(anz), RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - SETPOINT(texLen, 0, seg->center.x - radiusr * sin(anz), seg->center.y + radiusr * cos(anz), RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + SETPOINT(texLen, 0.0 + rlOffset + rlto, seg->center.x + radiusr * sin(anz), seg->center.y - radiusr * cos(anz), RtTrackHeightL(&trkpos)); - ts += step; - anz -= step; - } - ts = seg->arc; - break; - } - texLen = (curTexSeg + seg->length) / curTexSize; + ts += step; + anz += step; + } + ts = seg->arc; + break; + case TR_RGT: + step = LMAX / (seg->radiusl); + texStep = step * seg->radius / curTexSize; + anz = seg->angle[TR_ZS] - step; + ts = step; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz > seg->angle[TR_ZE]) { + texLen += texStep; + trkpos.toStart = ts; - SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, 0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + double rlto = getTexureOffset(seg->lgfromstart + ts*seg->radius)/rlWidthScale; + /* left */ + trkpos.toRight = width; + SETPOINT(texLen, texMaxT - rlOffset + rlto, seg->center.x - radiusl * sin(anz), seg->center.y + radiusl * cos(anz), RtTrackHeightL(&trkpos)); - startNeeded = 0; - runninglentgh += seg->length; + /* right */ + trkpos.toRight = 0; + SETPOINT(texLen, 0 + rlOffset + rlto, seg->center.x - radiusr * sin(anz), seg->center.y + radiusr * cos(anz), RtTrackHeightL(&trkpos)); + + ts += step; + anz -= step; + } + ts = seg->arc; + break; + } + texLen = (curTexSeg + seg->length) / curTexSize; + + double rlto = getTexureOffset(seg->lgfromstart + seg->length)/rlWidthScale; + SETPOINT(texLen, texMaxT - rlOffset + rlto, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, 0 + rlOffset + rlto, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + + startNeeded = 0; + runninglentgh += seg->length; } if (raceline) { @@ -678,383 +696,383 @@ InitScene(tTrack *Track, void *TrackHandle, int bump, int raceline) /* Right Border */ for (j = 0; j < 3; j++) { - prevTexId = 0; - texLen = 0; - startNeeded = 1; - runninglentgh = 0; - sprintf(sname, "t%dRB", j); - for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { - if ((mseg->rside != NULL) && (mseg->rside->type2 == TR_RBORDER)) { - seg = mseg->rside; - CHECKDISPLIST(seg->surface->material, sname, i, mseg->lgfromstart); - if (!curTexLink) { - curTexSeg = 0; - } else { - curTexSeg = mseg->lgfromstart; - } - curTexSeg += curTexOffset; - texLen = curTexSeg / curTexSize; - if (startNeeded || (runninglentgh > LG_STEP_MAX)) { - NEWDISPLIST(0, sname, i); - runninglentgh = 0; - ts = 0; + prevTexId = 0; + texLen = 0; + startNeeded = 1; + runninglentgh = 0; + sprintf(sname, "t%dRB", j); + for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { + if ((mseg->rside != NULL) && (mseg->rside->type2 == TR_RBORDER)) { + seg = mseg->rside; + CHECKDISPLIST(seg->surface->material, sname, i, mseg->lgfromstart); + if (!curTexLink) { + curTexSeg = 0; + } else { + curTexSeg = mseg->lgfromstart; + } + curTexSeg += curTexOffset; + texLen = curTexSeg / curTexSize; + if (startNeeded || (runninglentgh > LG_STEP_MAX)) { + NEWDISPLIST(0, sname, i); + runninglentgh = 0; + ts = 0; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - } - break; - case TR_CURB: - switch (j) { - case 0: - if (!mseg->prev->rside || (mseg->prev->rside->type2 != TR_RBORDER) || (mseg->prev->rside->style != TR_CURB)) { - SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z - 0.1); - SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - } - SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); - break; - case 1: - SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); - SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - break; - case 2: - break; + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + } + break; + case TR_CURB: + switch (j) { + case 0: + if (!mseg->prev->rside || (mseg->prev->rside->type2 != TR_RBORDER) || (mseg->prev->rside->style != TR_CURB)) { + SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z - 0.1); + SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + } + SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); + break; + case 1: + SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); + SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + break; + case 2: + break; - } - break; - case TR_WALL: - switch (j) { - case 0: - SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, .33, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); - break; - case 1: - SETPOINT(texLen, 0.33, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); - SETPOINT(texLen, 0.66, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); - break; - case 2: - if (!mseg->prev->rside || (mseg->prev->rside->type2 != TR_RBORDER) || (mseg->prev->rside->style != TR_WALL)) { - SETPOINT(texLen - seg->width/curTexSize, 0.66, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); - SETPOINT(texLen - seg->width/curTexSize, 1.00, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - } - SETPOINT(texLen, 0.66, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); - SETPOINT(texLen, 1.0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - break; - } - break; - } - - } - - switch (seg->type) { - case TR_STR: - ts = LMAX; - texStep = LMAX / curTexSize; - texLen += texStep; - trkpos.seg = seg; - while (ts < seg->length) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + } + break; + case TR_WALL: + switch (j) { + case 0: + SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, .33, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); + break; + case 1: + SETPOINT(texLen, 0.33, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); + SETPOINT(texLen, 0.66, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); + break; + case 2: + if (!mseg->prev->rside || (mseg->prev->rside->type2 != TR_RBORDER) || (mseg->prev->rside->style != TR_WALL)) { + SETPOINT(texLen - seg->width/curTexSize, 0.66, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); + SETPOINT(texLen - seg->width/curTexSize, 1.00, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + } + SETPOINT(texLen, 0.66, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); + SETPOINT(texLen, 1.0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + break; + } + break; + } - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - trkpos.toRight = 0 ; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - } - break; - case TR_CURB: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - trkpos.toRight = 0 ; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - trkpos.toRight = 0 ; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - break; - case 2: - break; - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - trkpos.toRight = 0 ; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 2: - trkpos.toRight = 0 ; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); - break; - } - break; - } + } - ts += LMAX; - texLen += texStep; - } - ts = seg->length; - break; - case TR_LFT: - step = LMAX / (mseg->radiusr); - texStep = step * mseg->radius / curTexSize; - anz = seg->angle[TR_ZS] + step; - ts = step; - texLen += texStep; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz < seg->angle[TR_ZE]) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + switch (seg->type) { + case TR_STR: + ts = LMAX; + texStep = LMAX / curTexSize; + texLen += texStep; + trkpos.seg = seg; + while (ts < seg->length) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - } - break; - case TR_CURB: - switch (j) { - case 0: - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - break; - case 2: - break; - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 2: - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); - break; - } - break; - } + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + trkpos.toRight = 0 ; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + } + break; + case TR_CURB: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + trkpos.toRight = 0 ; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + trkpos.toRight = 0 ; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + break; + case 2: + break; + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + trkpos.toRight = 0 ; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 2: + trkpos.toRight = 0 ; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); + break; + } + break; + } - ts += step; - texLen += texStep; - anz += step; - } - ts = seg->arc; - break; - case TR_RGT: - step = LMAX / (mseg->radiusl); - texStep = step * mseg->radius / curTexSize; - anz = seg->angle[TR_ZS] - step; - ts = step; - texLen += texStep; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz > seg->angle[TR_ZE]) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + ts += LMAX; + texLen += texStep; + } + ts = seg->length; + break; + case TR_LFT: + step = LMAX / (mseg->radiusr); + texStep = step * mseg->radius / curTexSize; + anz = seg->angle[TR_ZS] + step; + ts = step; + texLen += texStep; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz < seg->angle[TR_ZE]) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - } - break; - case TR_CURB: - switch (j) { - case 0: - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - break; - case 2: - break; - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 2: - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); - break; - } - break; - } + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + } + break; + case TR_CURB: + switch (j) { + case 0: + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + break; + case 2: + break; + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 2: + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); + break; + } + break; + } - ts += step; - texLen += texStep; - anz -= step; - } - ts = seg->arc; - break; - } - texLen = (curTexSeg + mseg->length) / curTexSize; + ts += step; + texLen += texStep; + anz += step; + } + ts = seg->arc; + break; + case TR_RGT: + step = LMAX / (mseg->radiusl); + texStep = step * mseg->radius / curTexSize; + anz = seg->angle[TR_ZS] - step; + ts = step; + texLen += texStep; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz > seg->angle[TR_ZE]) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - } - break; - case TR_CURB: - switch (j) { - case 0: - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); - if (mseg->next->rside && ((mseg->next->rside->type2 != TR_RBORDER) || (mseg->next->rside->style != TR_CURB))) { - SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z - 0.1); - SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - } - break; - case 1: - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); - SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - break; - case 2: - break; - } - break; - case TR_WALL: - switch (j) { - case 0: - SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, 0.33, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); - break; - case 1: - SETPOINT(texLen, 0.33, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); - SETPOINT(texLen, 0.66, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); - break; - case 2: - SETPOINT(texLen, 0.66, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); - SETPOINT(texLen, 1.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - if (mseg->next->rside && ((mseg->next->rside->type2 != TR_RBORDER) || (mseg->next->rside->style != TR_WALL))) { - SETPOINT(texLen + seg->width/curTexSize, 0.66, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); - SETPOINT(texLen + seg->width/curTexSize, 1.00, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - } - break; - } - break; - } + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + } + break; + case TR_CURB: + switch (j) { + case 0: + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + break; + case 2: + break; + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 2: + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); + break; + } + break; + } - startNeeded = 0; - runninglentgh += seg->length; - } else { - startNeeded = 1; - } - } + ts += step; + texLen += texStep; + anz -= step; + } + ts = seg->arc; + break; + } + texLen = (curTexSeg + mseg->length) / curTexSize; + + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + } + break; + case TR_CURB: + switch (j) { + case 0: + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); + if (mseg->next->rside && ((mseg->next->rside->type2 != TR_RBORDER) || (mseg->next->rside->style != TR_CURB))) { + SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z - 0.1); + SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + } + break; + case 1: + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); + SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + break; + case 2: + break; + } + break; + case TR_WALL: + switch (j) { + case 0: + SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, 0.33, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); + break; + case 1: + SETPOINT(texLen, 0.33, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); + SETPOINT(texLen, 0.66, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); + break; + case 2: + SETPOINT(texLen, 0.66, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); + SETPOINT(texLen, 1.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + if (mseg->next->rside && ((mseg->next->rside->type2 != TR_RBORDER) || (mseg->next->rside->style != TR_WALL))) { + SETPOINT(texLen + seg->width/curTexSize, 0.66, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); + SETPOINT(texLen + seg->width/curTexSize, 1.00, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + } + break; + } + break; + } + + startNeeded = 0; + runninglentgh += seg->length; + } else { + startNeeded = 1; + } } - + } + /* Right Side */ prevTexId = 0; @@ -1063,527 +1081,527 @@ InitScene(tTrack *Track, void *TrackHandle, int bump, int raceline) runninglentgh = 0; hasBorder = 0; for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { - if ((mseg->rside != NULL) && - ((mseg->rside->type2 == TR_RSIDE) || (mseg->rside->rside != NULL))) { - seg = mseg->rside; - if (seg->rside != NULL) { - seg = seg->rside; - if (hasBorder == 0) { - startNeeded = 1; - hasBorder = 1; - } - } else { - if (hasBorder) { - startNeeded = 1; - hasBorder = 0; - } - } + if ((mseg->rside != NULL) && + ((mseg->rside->type2 == TR_RSIDE) || (mseg->rside->rside != NULL))) { + seg = mseg->rside; + if (seg->rside != NULL) { + seg = seg->rside; + if (hasBorder == 0) { + startNeeded = 1; + hasBorder = 1; + } + } else { + if (hasBorder) { + startNeeded = 1; + hasBorder = 0; + } + } - if (!startNeeded) - { - tdble d0 = Distance(lastSeg->vertex[TR_EL].x, lastSeg->vertex[TR_EL].y, lastSeg->vertex[TR_EL].z, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - tdble d1 = Distance(lastSeg->vertex[TR_ER].x, lastSeg->vertex[TR_ER].y, lastSeg->vertex[TR_ER].z, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - if ((d0 > 0.01) || (d1 > 0.01)) - startNeeded = 1; - } + if (!startNeeded) + { + tdble d0 = Distance(lastSeg->vertex[TR_EL].x, lastSeg->vertex[TR_EL].y, lastSeg->vertex[TR_EL].z, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + tdble d1 = Distance(lastSeg->vertex[TR_ER].x, lastSeg->vertex[TR_ER].y, lastSeg->vertex[TR_ER].z, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + if ((d0 > 0.01) || (d1 > 0.01)) + startNeeded = 1; + } - CHECKDISPLIST(seg->surface->material, "tkRS", i, mseg->lgfromstart); - if (!curTexLink) { - curTexSeg = 0; - } else { - curTexSeg = mseg->lgfromstart; - } - curTexSeg += curTexOffset; - texLen = curTexSeg / curTexSize; - if (startNeeded || (runninglentgh > LG_STEP_MAX)) { - NEWDISPLIST(0, "tkRS", i); - runninglentgh = 0; - ts = 0; + CHECKDISPLIST(seg->surface->material, "tkRS", i, mseg->lgfromstart); + if (!curTexLink) { + curTexSeg = 0; + } else { + curTexSeg = mseg->lgfromstart; + } + curTexSeg += curTexOffset; + texLen = curTexSeg / curTexSize; + if (startNeeded || (runninglentgh > LG_STEP_MAX)) { + NEWDISPLIST(0, "tkRS", i); + runninglentgh = 0; + ts = 0; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - } + SETPOINT(texLen, 0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, texMaxT, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + } - switch (seg->type) { - case TR_STR: - ts = LMAX; - texStep = LMAX / curTexSize; - texLen += texStep; - trkpos.seg = seg; - while (ts < seg->length) { - trkpos.toStart = ts; + switch (seg->type) { + case TR_STR: + ts = LMAX; + texStep = LMAX / curTexSize; + texLen += texStep; + trkpos.seg = seg; + while (ts < seg->length) { + trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - trkpos.toRight = 0 ; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + trkpos.toRight = 0 ; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - ts += LMAX; - texLen += texStep; - } - ts = seg->length; - break; - case TR_LFT: - step = LMAX / (mseg->radiusr); - texStep = step * mseg->radius / curTexSize; - anz = seg->angle[TR_ZS] + step; - ts = step; - texLen += texStep; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz < seg->angle[TR_ZE]) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + ts += LMAX; + texLen += texStep; + } + ts = seg->length; + break; + case TR_LFT: + step = LMAX / (mseg->radiusr); + texStep = step * mseg->radius / curTexSize; + anz = seg->angle[TR_ZS] + step; + ts = step; + texLen += texStep; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz < seg->angle[TR_ZE]) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - ts += step; - texLen += texStep; - anz += step; - } - ts = seg->arc; - break; - case TR_RGT: - step = LMAX / (mseg->radiusl); - texStep = step * mseg->radius / curTexSize; - anz = seg->angle[TR_ZS] - step; - ts = step; - texLen += texStep; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz > seg->angle[TR_ZE]) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + ts += step; + texLen += texStep; + anz += step; + } + ts = seg->arc; + break; + case TR_RGT: + step = LMAX / (mseg->radiusl); + texStep = step * mseg->radius / curTexSize; + anz = seg->angle[TR_ZS] - step; + ts = step; + texLen += texStep; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz > seg->angle[TR_ZE]) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - ts += step; - texLen += texStep; - anz -= step; - } - ts = seg->arc; - break; - } - texLen = (curTexSeg + mseg->length) / curTexSize; + ts += step; + texLen += texStep; + anz -= step; + } + ts = seg->arc; + break; + } + texLen = (curTexSeg + mseg->length) / curTexSize; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, texMaxT, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - startNeeded = 0; - runninglentgh += seg->length; - lastSeg = seg; - } else { - startNeeded = 1; - } + startNeeded = 0; + runninglentgh += seg->length; + lastSeg = seg; + } else { + startNeeded = 1; + } } /* Left Border */ for (j = 0; j < 3; j++) { - prevTexId = 0; - texLen = 0; - startNeeded = 1; - runninglentgh = 0; - sprintf(sname, "t%dLB", j); - for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { - if ((mseg->lside != NULL) && (mseg->lside->type2 == TR_LBORDER)) { - seg = mseg->lside; - CHECKDISPLIST(seg->surface->material, sname, i, mseg->lgfromstart); - if (!curTexLink) { - curTexSeg = 0; - } else { - curTexSeg = mseg->lgfromstart; - } - curTexSeg += curTexOffset; - texLen = curTexSeg / curTexSize; - if (startNeeded || (runninglentgh > LG_STEP_MAX)) { - NEWDISPLIST(0, sname, i); - runninglentgh = 0; - ts = 0; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - } - break; - case TR_CURB: - switch (j) { - case 0: - SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); - break; - case 1: - if (!mseg->prev->rside || (mseg->prev->rside->type2 != TR_RBORDER) || (mseg->prev->rside->style != TR_CURB)) { - SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z - 0.1); - } - SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); - SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - break; - case 2: - break; - } - break; - case TR_WALL: - switch (j) { - case 0: - if (!mseg->prev->rside || (mseg->prev->rside->type2 != TR_RBORDER) || (mseg->prev->rside->style != TR_WALL)) { - SETPOINT(texLen - seg->width/curTexSize, 1.00, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - SETPOINT(texLen - seg->width/curTexSize, 0.66, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); - } - SETPOINT(texLen, 1.0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, 0.66, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); - break; - case 1: - SETPOINT(texLen, 0.66, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); - SETPOINT(texLen, 0.33, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); - break; - case 2: - SETPOINT(texLen, 0.33, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); - SETPOINT(texLen, 0.0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - break; - } - break; - } + prevTexId = 0; + texLen = 0; + startNeeded = 1; + runninglentgh = 0; + sprintf(sname, "t%dLB", j); + for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { + if ((mseg->lside != NULL) && (mseg->lside->type2 == TR_LBORDER)) { + seg = mseg->lside; + CHECKDISPLIST(seg->surface->material, sname, i, mseg->lgfromstart); + if (!curTexLink) { + curTexSeg = 0; + } else { + curTexSeg = mseg->lgfromstart; + } + curTexSeg += curTexOffset; + texLen = curTexSeg / curTexSize; + if (startNeeded || (runninglentgh > LG_STEP_MAX)) { + NEWDISPLIST(0, sname, i); + runninglentgh = 0; + ts = 0; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + } + break; + case TR_CURB: + switch (j) { + case 0: + SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); + break; + case 1: + if (!mseg->prev->rside || (mseg->prev->rside->type2 != TR_RBORDER) || (mseg->prev->rside->style != TR_CURB)) { + SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z - 0.1); + } + SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); + SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + break; + case 2: + break; + } + break; + case TR_WALL: + switch (j) { + case 0: + if (!mseg->prev->rside || (mseg->prev->rside->type2 != TR_RBORDER) || (mseg->prev->rside->style != TR_WALL)) { + SETPOINT(texLen - seg->width/curTexSize, 1.00, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + SETPOINT(texLen - seg->width/curTexSize, 0.66, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); + } + SETPOINT(texLen, 1.0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, 0.66, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); + break; + case 1: + SETPOINT(texLen, 0.66, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + seg->height); + SETPOINT(texLen, 0.33, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); + break; + case 2: + SETPOINT(texLen, 0.33, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + seg->height); + SETPOINT(texLen, 0.0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + break; + } + break; + } - } - - switch (seg->type) { - case TR_STR: - ts = LMAX; - texStep = LMAX / curTexSize; - texLen += texStep; - trkpos.seg = seg; - while (ts < seg->length) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + } - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - } - break; - case TR_CURB: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - break; - case 2: - break; - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 2: - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - SETPOINT(texLen, 0.0, x, y, RtTrackHeightL(&trkpos)); - break; - } - break; - } + switch (seg->type) { + case TR_STR: + ts = LMAX; + texStep = LMAX / curTexSize; + texLen += texStep; + trkpos.seg = seg; + while (ts < seg->length) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - ts += LMAX; - texLen += texStep; - } - ts = seg->length; - break; - case TR_LFT: - step = LMAX / (mseg->radiusr); - texStep = step * mseg->radius / curTexSize; - anz = seg->angle[TR_ZS] + step; - ts = step; - texLen += texStep; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz < seg->angle[TR_ZE]) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + } + break; + case TR_CURB: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + break; + case 2: + break; + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 2: + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + SETPOINT(texLen, 0.0, x, y, RtTrackHeightL(&trkpos)); + break; + } + break; + } - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - } - break; - case TR_CURB: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - break; - case 2: - break; - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 2: - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - SETPOINT(texLen, 0.0, x, y, RtTrackHeightL(&trkpos)); - break; - } - break; - } + ts += LMAX; + texLen += texStep; + } + ts = seg->length; + break; + case TR_LFT: + step = LMAX / (mseg->radiusr); + texStep = step * mseg->radius / curTexSize; + anz = seg->angle[TR_ZS] + step; + ts = step; + texLen += texStep; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz < seg->angle[TR_ZE]) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + } + break; + case TR_CURB: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + break; + case 2: + break; + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 2: + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + SETPOINT(texLen, 0.0, x, y, RtTrackHeightL(&trkpos)); + break; + } + break; + } - ts += step; - texLen += texStep; - anz += step; - } - ts = seg->arc; - break; - case TR_RGT: - step = LMAX / (mseg->radiusl); - texStep = step * mseg->radius / curTexSize; - anz = seg->angle[TR_ZS] - step; - ts = step; - texLen += texStep; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz > seg->angle[TR_ZE]) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + ts += step; + texLen += texStep; + anz += step; + } + ts = seg->arc; + break; + case TR_RGT: + step = LMAX / (mseg->radiusl); + texStep = step * mseg->radius / curTexSize; + anz = seg->angle[TR_ZS] - step; + ts = step; + texLen += texStep; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz > seg->angle[TR_ZE]) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - } - break; - case TR_CURB: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - break; - case 2: - break; - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 1: - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - break; - case 2: - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); - SETPOINT(texLen, 0.0, x, y, RtTrackHeightL(&trkpos)); - break; - } - break; - } + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + } + break; + case TR_CURB: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos) + seg->height); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + break; + case 2: + break; + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 1.0, x, y, RtTrackHeightL(&trkpos)); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 1: + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, RtTrackHeightL(&trkpos) + seg->height); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + break; + case 2: + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, RtTrackHeightL(&trkpos) + seg->height); + SETPOINT(texLen, 0.0, x, y, RtTrackHeightL(&trkpos)); + break; + } + break; + } - ts += step; - texLen += texStep; - anz -= step; - } - ts = seg->arc; - break; - } - texLen = (curTexSeg + mseg->length) / curTexSize; + ts += step; + texLen += texStep; + anz -= step; + } + ts = seg->arc; + break; + } + texLen = (curTexSeg + mseg->length) / curTexSize; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - switch (seg->style) { - case TR_PLAN: - if (j == 0) { - SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, 0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - } - break; - case TR_CURB: - switch (j) { - case 0: - SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); - break; - case 1: - SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); - SETPOINT(texLen, 0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - if (mseg->next->lside && ((mseg->next->lside->type2 != TR_LBORDER) || (mseg->next->lside->style != TR_CURB))) { - SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, 0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z - 0.1); - } - break; - case 2: - break; - } - break; - case TR_WALL: - switch (j) { - case 0: - SETPOINT(texLen, 1.0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, 0.66, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); - if (mseg->next->lside && ((mseg->next->lside->type2 != TR_LBORDER) || (mseg->next->lside->style != TR_WALL))) { - SETPOINT(texLen + seg->width/curTexSize, 1.00, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - SETPOINT(texLen + seg->width/curTexSize, 0.66, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); - } - break; - case 1: - SETPOINT(texLen, 0.66, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); - SETPOINT(texLen, 0.33, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); - break; - case 2: - SETPOINT(texLen, 0.33, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); - SETPOINT(texLen, 0.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - break; - } - break; - } + switch (seg->style) { + case TR_PLAN: + if (j == 0) { + SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, 0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + } + break; + case TR_CURB: + switch (j) { + case 0: + SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); + break; + case 1: + SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); + SETPOINT(texLen, 0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + if (mseg->next->lside && ((mseg->next->lside->type2 != TR_LBORDER) || (mseg->next->lside->style != TR_CURB))) { + SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, 0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z - 0.1); + } + break; + case 2: + break; + } + break; + case TR_WALL: + switch (j) { + case 0: + SETPOINT(texLen, 1.0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, 0.66, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); + if (mseg->next->lside && ((mseg->next->lside->type2 != TR_LBORDER) || (mseg->next->lside->style != TR_WALL))) { + SETPOINT(texLen + seg->width/curTexSize, 1.00, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + SETPOINT(texLen + seg->width/curTexSize, 0.66, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); + } + break; + case 1: + SETPOINT(texLen, 0.66, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + seg->height); + SETPOINT(texLen, 0.33, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); + break; + case 2: + SETPOINT(texLen, 0.33, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + seg->height); + SETPOINT(texLen, 0.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + break; + } + break; + } - startNeeded = 0; - runninglentgh += seg->length; - } else { - startNeeded = 1; - } - } + startNeeded = 0; + runninglentgh += seg->length; + } else { + startNeeded = 1; + } } - + } + /* Left Side */ prevTexId = 0; texLen = 0; @@ -1591,1080 +1609,1080 @@ InitScene(tTrack *Track, void *TrackHandle, int bump, int raceline) runninglentgh = 0; hasBorder = 0; for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { - if ((mseg->lside != NULL) && - ((mseg->lside->type2 == TR_LSIDE) || (mseg->lside->lside != NULL))) { - seg = mseg->lside; - if (seg->lside) { - seg = seg->lside; - if (hasBorder == 0) { - startNeeded = 1; - hasBorder = 1; - } - } else { - if (hasBorder) { - startNeeded = 1; - hasBorder = 0; - } - } + if ((mseg->lside != NULL) && + ((mseg->lside->type2 == TR_LSIDE) || (mseg->lside->lside != NULL))) { + seg = mseg->lside; + if (seg->lside) { + seg = seg->lside; + if (hasBorder == 0) { + startNeeded = 1; + hasBorder = 1; + } + } else { + if (hasBorder) { + startNeeded = 1; + hasBorder = 0; + } + } - if (!startNeeded) - { - tdble d0 = Distance(lastSeg->vertex[TR_EL].x, lastSeg->vertex[TR_EL].y, lastSeg->vertex[TR_EL].z, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - tdble d1 = Distance(lastSeg->vertex[TR_ER].x, lastSeg->vertex[TR_ER].y, lastSeg->vertex[TR_ER].z, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - if ((d0 > 0.01) || (d1 > 0.01)) - startNeeded = 1; - } + if (!startNeeded) + { + tdble d0 = Distance(lastSeg->vertex[TR_EL].x, lastSeg->vertex[TR_EL].y, lastSeg->vertex[TR_EL].z, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + tdble d1 = Distance(lastSeg->vertex[TR_ER].x, lastSeg->vertex[TR_ER].y, lastSeg->vertex[TR_ER].z, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + if ((d0 > 0.01) || (d1 > 0.01)) + startNeeded = 1; + } - CHECKDISPLIST(seg->surface->material, "tkLS", i, mseg->lgfromstart); - if (!curTexLink) { - curTexSeg = 0; - } else { - curTexSeg = mseg->lgfromstart; - } - curTexSeg += curTexOffset; - texLen = curTexSeg / curTexSize; - if (startNeeded || (runninglentgh > LG_STEP_MAX)) { - NEWDISPLIST(0, "tkLS", i); - runninglentgh = 0; + CHECKDISPLIST(seg->surface->material, "tkLS", i, mseg->lgfromstart); + if (!curTexLink) { + curTexSeg = 0; + } else { + curTexSeg = mseg->lgfromstart; + } + curTexSeg += curTexOffset; + texLen = curTexSeg / curTexSize; + if (startNeeded || (runninglentgh > LG_STEP_MAX)) { + NEWDISPLIST(0, "tkLS", i); + runninglentgh = 0; - ts = 0; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - } + ts = 0; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + SETPOINT(texLen, texMaxT, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + } - switch (seg->type) { - case TR_STR: - ts = LMAX; - texStep = LMAX / curTexSize; - texLen += texStep; - trkpos.seg = seg; - while (ts < seg->length) { - trkpos.toStart = ts; + switch (seg->type) { + case TR_STR: + ts = LMAX; + texStep = LMAX / curTexSize; + texLen += texStep; + trkpos.seg = seg; + while (ts < seg->length) { + trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - ts += LMAX; - texLen += texStep; - } - ts = seg->length; - break; - case TR_LFT: - step = LMAX / (mseg->radiusr); - texStep = step * mseg->radius / curTexSize; - anz = seg->angle[TR_ZS] + step; - ts = step; - texLen += texStep; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz < seg->angle[TR_ZE]) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + ts += LMAX; + texLen += texStep; + } + ts = seg->length; + break; + case TR_LFT: + step = LMAX / (mseg->radiusr); + texStep = step * mseg->radius / curTexSize; + anz = seg->angle[TR_ZS] + step; + ts = step; + texLen += texStep; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz < seg->angle[TR_ZE]) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - ts += step; - texLen += texStep; - anz += step; - } - ts = seg->arc; - break; - case TR_RGT: - step = LMAX / (mseg->radiusl); - texStep = step * mseg->radius / curTexSize; - anz = seg->angle[TR_ZS] - step; - ts = step; - texLen += texStep; - radiusr = seg->radiusr; - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz > seg->angle[TR_ZE]) { - trkpos.toStart = ts; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + ts += step; + texLen += texStep; + anz += step; + } + ts = seg->arc; + break; + case TR_RGT: + step = LMAX / (mseg->radiusl); + texStep = step * mseg->radius / curTexSize; + anz = seg->angle[TR_ZS] - step; + ts = step; + texLen += texStep; + radiusr = seg->radiusr; + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz > seg->angle[TR_ZE]) { + trkpos.toStart = ts; + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - /* left */ - trkpos.toRight = width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); + /* left */ + trkpos.toRight = width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, texMaxT, x, y, RtTrackHeightL(&trkpos)); - /* right */ - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); + /* right */ + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0, x, y, RtTrackHeightL(&trkpos)); - ts += step; - texLen += texStep; - anz -= step; - } - ts = seg->arc; - break; - } - texLen = (curTexSeg + mseg->length) / curTexSize; + ts += step; + texLen += texStep; + anz -= step; + } + ts = seg->arc; + break; + } + texLen = (curTexSeg + mseg->length) / curTexSize; - width = RtTrackGetWidth(seg, ts); - texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); + width = RtTrackGetWidth(seg, ts); + texMaxT = (curTexType == 1 ? width / curTexSize : 1.0 + floor(width / curTexSize)); - SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen, 0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + SETPOINT(texLen, texMaxT, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen, 0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - startNeeded = 0; - runninglentgh += seg->length; - lastSeg = seg; - } else { - startNeeded = 1; - } + startNeeded = 0; + runninglentgh += seg->length; + lastSeg = seg; + } else { + startNeeded = 1; + } } /* Right barrier */ for (j = 0; j < 3; j++) { - prevTexId = 0; - texLen = 0; - startNeeded = 1; - runninglentgh = 0; - sprintf(sname, "B%dRt", j); - for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { - if ((mseg->rside != NULL) && (mseg->rside->raceInfo & TR_PITBUILD)) { - startNeeded = 1; - runninglentgh = 0; - NEWDISPLIST(0, sname, i); - } else { - curBarrier = mseg->barrier[0]; - CHECKDISPLIST(curBarrier->surface->material, sname, i, 0); - if (!curTexLink) { - texLen = 0; //edited - } /*else { - ; - } auch edited */ - //texLen = curTexSeg / curTexSize; - if (mseg->rside) { - seg = mseg->rside; - if (seg->rside) { - seg = seg->rside; - } - } else { - seg = mseg; - } - trkpos.seg = seg; - if (startNeeded || (runninglentgh > LG_STEP_MAX)) { - NEWDISPLIST(0, sname, i); - if (curTexType == 0) texLen = 0; - runninglentgh = 0; - xprev = seg->vertex[TR_SR].x; // edited - yprev = seg->vertex[TR_SR].y; // edited + prevTexId = 0; + texLen = 0; + startNeeded = 1; + runninglentgh = 0; + sprintf(sname, "B%dRt", j); + for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { + if ((mseg->rside != NULL) && (mseg->rside->raceInfo & TR_PITBUILD)) { + startNeeded = 1; + runninglentgh = 0; + NEWDISPLIST(0, sname, i); + } else { + curBarrier = mseg->barrier[0]; + CHECKDISPLIST(curBarrier->surface->material, sname, i, 0); + if (!curTexLink) { + texLen = 0; //edited + } /*else { + ; + } auch edited */ + //texLen = curTexSeg / curTexSize; + if (mseg->rside) { + seg = mseg->rside; + if (seg->rside) { + seg = seg->rside; + } + } else { + seg = mseg; + } + trkpos.seg = seg; + if (startNeeded || (runninglentgh > LG_STEP_MAX)) { + NEWDISPLIST(0, sname, i); + if (curTexType == 0) texLen = 0; + runninglentgh = 0; + xprev = seg->vertex[TR_SR].x; // edited + yprev = seg->vertex[TR_SR].y; // edited - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - SETPOINT(texLen, 1.0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + curBarrier->height); - } - break; - case TR_WALL: - switch (j) { - case 0: - SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - SETPOINT(texLen, 0.33, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + curBarrier->height); - break; - case 1: - trkpos.toStart = 0; - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + curBarrier->height); - SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_SR].z + curBarrier->height); - break; - case 2: - trkpos.toStart = 0; - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - if ((mseg->prev->barrier[0]->style != TR_WALL) || (mseg->prev->barrier[0]->height != curBarrier->height)) { - SETPOINT(texLen - curBarrier->width/curTexSize, 0.66, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + curBarrier->height); - SETPOINT(texLen - curBarrier->width/curTexSize, 1.00, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); - } - SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_SR].z + curBarrier->height); - SETPOINT(texLen, 1.0, x, y, seg->vertex[TR_SR].z); - break; - } - break; - } - } - switch (seg->type) { - case TR_STR: - ts = LMAX; - - trkpos.seg = seg; - while (ts < seg->length) { - trkpos.toStart = ts; - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - curHeight = RtTrackHeightL(&trkpos); - texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new - texLen += texStep; //new - xprev=x; //new - yprev=y; //new - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 0, x, y, curHeight); - SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); - } - break; - case TR_WALL: - switch (j) { - case 0: - SETPOINT(texLen, 0.0, x, y, curHeight); - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - break; - case 1: - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - break; - case 2: - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - SETPOINT(texLen, 1.0, x, y, curHeight); - break; - } - break; - } + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + SETPOINT(texLen, 1.0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + curBarrier->height); + } + break; + case TR_WALL: + switch (j) { + case 0: + SETPOINT(texLen, 0, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + SETPOINT(texLen, 0.33, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + curBarrier->height); + break; + case 1: + trkpos.toStart = 0; + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + curBarrier->height); + SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_SR].z + curBarrier->height); + break; + case 2: + trkpos.toStart = 0; + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + if ((mseg->prev->barrier[0]->style != TR_WALL) || (mseg->prev->barrier[0]->height != curBarrier->height)) { + SETPOINT(texLen - curBarrier->width/curTexSize, 0.66, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z + curBarrier->height); + SETPOINT(texLen - curBarrier->width/curTexSize, 1.00, seg->vertex[TR_SR].x, seg->vertex[TR_SR].y, seg->vertex[TR_SR].z); + } + SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_SR].z + curBarrier->height); + SETPOINT(texLen, 1.0, x, y, seg->vertex[TR_SR].z); + break; + } + break; + } + } + switch (seg->type) { + case TR_STR: + ts = LMAX; - ts += LMAX; - - } - ts = seg->length; - break; - case TR_LFT: - step = LMAX / (mseg->radiusr); - // texStep = step * mseg->radius / curTexSize; //edited - anz = seg->angle[TR_ZS] + step; - ts = step; - //texLen += texStep; - radiusr = seg->radiusr; - trkpos.seg = seg; - while (anz < seg->angle[TR_ZE]) { - trkpos.toStart = ts; - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - - - curHeight = RtTrackHeightL(&trkpos); - texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new - texLen += texStep; //new - xprev=x; //new - yprev=y; //new - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 0.0, x, y, curHeight); - SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); - } - break; - case TR_WALL: - switch (j) { - case 0: - SETPOINT(texLen, 0.0, x, y, curHeight); - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - break; - case 1: - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - break; - case 2: - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - SETPOINT(texLen, 1.0, x, y, curHeight); - break; - } - break; - } + trkpos.seg = seg; + while (ts < seg->length) { + trkpos.toStart = ts; + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + curHeight = RtTrackHeightL(&trkpos); + texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new + texLen += texStep; //new + xprev=x; //new + yprev=y; //new + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 0, x, y, curHeight); + SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); + } + break; + case TR_WALL: + switch (j) { + case 0: + SETPOINT(texLen, 0.0, x, y, curHeight); + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + break; + case 1: + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + break; + case 2: + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + SETPOINT(texLen, 1.0, x, y, curHeight); + break; + } + break; + } - ts += step; - //removed - anz += step; - } - ts = seg->arc; - break; - case TR_RGT: - step = LMAX / (mseg->radiusl); - //removed - anz = seg->angle[TR_ZS] - step; - ts = step; - //removed - radiusr = seg->radiusr; - trkpos.seg = seg; - while (anz > seg->angle[TR_ZE]) { - trkpos.toStart = ts; - trkpos.toRight = 0; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - - curHeight = RtTrackHeightL(&trkpos); - texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new - texLen += texStep; //new - xprev=x; //new - yprev=y; //new - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 0.0, x, y, curHeight); - SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); - } - break; - case TR_WALL: - switch (j) { - case 0: - SETPOINT(texLen, 0.0, x, y, curHeight); - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - break; - case 1: - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - break; - case 2: - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - SETPOINT(texLen, 1.0, x, y, curHeight); - break; - } - break; - } - ts += step; - anz -= step; - } - ts = seg->arc; - break; - } - texStep = sqrt( pow( ( seg->vertex[TR_ER].y - yprev ), 2.0f) + pow(( seg->vertex[TR_ER].x - xprev ), 2.0f) ) / curTexSize; //new - texLen += texStep; //edited - xprev = seg->vertex[TR_ER].x; //new - yprev = seg->vertex[TR_ER].y; //new - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 0.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - SETPOINT(texLen, 1.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + curBarrier->height); - } - break; - case TR_WALL: - switch (j) { - case 0: - SETPOINT(texLen, 0.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - SETPOINT(texLen, 0.33, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + curBarrier->height); - break; - case 1: - SETPOINT(texLen, 0.33, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + curBarrier->height); - trkpos.toStart = ts; - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_ER].z + curBarrier->height); - break; - case 2: - trkpos.toStart = ts; - trkpos.toRight = -curBarrier->width; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_ER].z + curBarrier->height); - SETPOINT(texLen, 1.00, x, y, seg->vertex[TR_ER].z); - if ((mseg->next->barrier[0]->style != TR_WALL) || (mseg->next->barrier[0]->height != curBarrier->height)) { - SETPOINT(texLen + curBarrier->width/curTexSize, 0.66, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + curBarrier->height); - SETPOINT(texLen + curBarrier->width/curTexSize, 1.00, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); - } - break; - } - break; - } - startNeeded = 0; - runninglentgh += seg->length; - } - } + ts += LMAX; + + } + ts = seg->length; + break; + case TR_LFT: + step = LMAX / (mseg->radiusr); + // texStep = step * mseg->radius / curTexSize; //edited + anz = seg->angle[TR_ZS] + step; + ts = step; + //texLen += texStep; + radiusr = seg->radiusr; + trkpos.seg = seg; + while (anz < seg->angle[TR_ZE]) { + trkpos.toStart = ts; + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + + + curHeight = RtTrackHeightL(&trkpos); + texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new + texLen += texStep; //new + xprev=x; //new + yprev=y; //new + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 0.0, x, y, curHeight); + SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); + } + break; + case TR_WALL: + switch (j) { + case 0: + SETPOINT(texLen, 0.0, x, y, curHeight); + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + break; + case 1: + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + break; + case 2: + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + SETPOINT(texLen, 1.0, x, y, curHeight); + break; + } + break; + } + + ts += step; + //removed + anz += step; + } + ts = seg->arc; + break; + case TR_RGT: + step = LMAX / (mseg->radiusl); + //removed + anz = seg->angle[TR_ZS] - step; + ts = step; + //removed + radiusr = seg->radiusr; + trkpos.seg = seg; + while (anz > seg->angle[TR_ZE]) { + trkpos.toStart = ts; + trkpos.toRight = 0; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + + curHeight = RtTrackHeightL(&trkpos); + texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new + texLen += texStep; //new + xprev=x; //new + yprev=y; //new + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 0.0, x, y, curHeight); + SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); + } + break; + case TR_WALL: + switch (j) { + case 0: + SETPOINT(texLen, 0.0, x, y, curHeight); + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + break; + case 1: + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + break; + case 2: + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + SETPOINT(texLen, 1.0, x, y, curHeight); + break; + } + break; + } + ts += step; + anz -= step; + } + ts = seg->arc; + break; + } + texStep = sqrt( pow( ( seg->vertex[TR_ER].y - yprev ), 2.0f) + pow(( seg->vertex[TR_ER].x - xprev ), 2.0f) ) / curTexSize; //new + texLen += texStep; //edited + xprev = seg->vertex[TR_ER].x; //new + yprev = seg->vertex[TR_ER].y; //new + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 0.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + SETPOINT(texLen, 1.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + curBarrier->height); + } + break; + case TR_WALL: + switch (j) { + case 0: + SETPOINT(texLen, 0.0, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + SETPOINT(texLen, 0.33, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + curBarrier->height); + break; + case 1: + SETPOINT(texLen, 0.33, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + curBarrier->height); + trkpos.toStart = ts; + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_ER].z + curBarrier->height); + break; + case 2: + trkpos.toStart = ts; + trkpos.toRight = -curBarrier->width; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_ER].z + curBarrier->height); + SETPOINT(texLen, 1.00, x, y, seg->vertex[TR_ER].z); + if ((mseg->next->barrier[0]->style != TR_WALL) || (mseg->next->barrier[0]->height != curBarrier->height)) { + SETPOINT(texLen + curBarrier->width/curTexSize, 0.66, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z + curBarrier->height); + SETPOINT(texLen + curBarrier->width/curTexSize, 1.00, seg->vertex[TR_ER].x, seg->vertex[TR_ER].y, seg->vertex[TR_ER].z); + } + break; + } + break; + } + startNeeded = 0; + runninglentgh += seg->length; + } } - + } + /* Left Barrier */ for (j = 0; j < 3; j++) { - prevTexId = 0; - texLen = 0; - startNeeded = 1; - runninglentgh = 0; - sprintf(sname, "B%dLt", j); - for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { - if ((mseg->lside != NULL) && (mseg->lside->raceInfo & TR_PITBUILD)) { - runninglentgh = 0; - startNeeded = 1; - NEWDISPLIST(0, sname, i); - } else { - curBarrier = mseg->barrier[1]; - CHECKDISPLIST(curBarrier->surface->material, sname, i, 0); - if (!curTexLink) { - texLen = 0; //* - } /*else { - curTexSeg = mseg->lgfromstart; - } - texLen = curTexSeg / curTexSize; */ - if (mseg->lside) { - seg = mseg->lside; - if (seg->lside) { - seg = seg->lside; - } - } else { - seg = mseg; - } - if (startNeeded || (runninglentgh > LG_STEP_MAX)) { - NEWDISPLIST(0, sname, i); - runninglentgh = 0; - if (curTexType == 0) texLen = 0; - xprev = seg->vertex[TR_SR].x; // edited - yprev = seg->vertex[TR_SR].y; // edited + prevTexId = 0; + texLen = 0; + startNeeded = 1; + runninglentgh = 0; + sprintf(sname, "B%dLt", j); + for (i = 0, mseg = Track->seg->next; i < Track->nseg; i++, mseg = mseg->next) { + if ((mseg->lside != NULL) && (mseg->lside->raceInfo & TR_PITBUILD)) { + runninglentgh = 0; + startNeeded = 1; + NEWDISPLIST(0, sname, i); + } else { + curBarrier = mseg->barrier[1]; + CHECKDISPLIST(curBarrier->surface->material, sname, i, 0); + if (!curTexLink) { + texLen = 0; //* + } /*else { + curTexSeg = mseg->lgfromstart; + } + texLen = curTexSeg / curTexSize; */ + if (mseg->lside) { + seg = mseg->lside; + if (seg->lside) { + seg = seg->lside; + } + } else { + seg = mseg; + } + if (startNeeded || (runninglentgh > LG_STEP_MAX)) { + NEWDISPLIST(0, sname, i); + runninglentgh = 0; + if (curTexType == 0) texLen = 0; + xprev = seg->vertex[TR_SR].x; // edited + yprev = seg->vertex[TR_SR].y; // edited - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 1.0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + curBarrier->height); - SETPOINT(texLen, 0.0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toStart = 0; - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, 0); - trkpos.seg = seg; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - if ((mseg->prev->barrier[1]->style != TR_WALL) || (mseg->prev->barrier[1]->height != curBarrier->height)) { - SETPOINT(texLen - curBarrier->width/curTexSize, 1.00, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - SETPOINT(texLen - curBarrier->width/curTexSize, 0.66, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + curBarrier->height); - } - SETPOINT(texLen, 1.0, x, y, seg->vertex[TR_SL].z); - SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_SL].z + curBarrier->height); - break; - case 1: - trkpos.toStart = 0; - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, 0); - trkpos.seg = seg; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_SL].z + curBarrier->height); - SETPOINT(texLen, 0.33, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + curBarrier->height); - break; - case 2: - SETPOINT(texLen, 0.33, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + curBarrier->height); - SETPOINT(texLen, 0.0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); - break; - } - break; - } - } - - switch (seg->type) { - case TR_STR: - ts = LMAX; + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 1.0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + curBarrier->height); + SETPOINT(texLen, 0.0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toStart = 0; + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, 0); + trkpos.seg = seg; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + if ((mseg->prev->barrier[1]->style != TR_WALL) || (mseg->prev->barrier[1]->height != curBarrier->height)) { + SETPOINT(texLen - curBarrier->width/curTexSize, 1.00, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + SETPOINT(texLen - curBarrier->width/curTexSize, 0.66, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + curBarrier->height); + } + SETPOINT(texLen, 1.0, x, y, seg->vertex[TR_SL].z); + SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_SL].z + curBarrier->height); + break; + case 1: + trkpos.toStart = 0; + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, 0); + trkpos.seg = seg; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_SL].z + curBarrier->height); + SETPOINT(texLen, 0.33, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + curBarrier->height); + break; + case 2: + SETPOINT(texLen, 0.33, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z + curBarrier->height); + SETPOINT(texLen, 0.0, seg->vertex[TR_SL].x, seg->vertex[TR_SL].y, seg->vertex[TR_SL].z); + break; + } + break; + } + } - trkpos.seg = seg; - while (ts < seg->length) { - trkpos.toStart = ts; - trkpos.toRight = RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - curHeight = RtTrackHeightL(&trkpos); - texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new - texLen += texStep; //new - xprev=x; //new - yprev=y; //new - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); - SETPOINT(texLen, 0, x, y, curHeight); - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 1.0, x, y, curHeight); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - break; - case 1: - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - trkpos.toRight = RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - break; - case 2: - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - SETPOINT(texLen, 0, x, y, curHeight); - break; - } - break; - } + switch (seg->type) { + case TR_STR: + ts = LMAX; - ts += LMAX; - - } - ts = seg->length; - break; - case TR_LFT: - step = LMAX / (mseg->radiusr); - - anz = seg->angle[TR_ZS] + step; - ts = step; - - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz < seg->angle[TR_ZE]) { - trkpos.toStart = ts; - trkpos.toRight = RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - curHeight = RtTrackHeightL(&trkpos); - texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new - texLen += texStep; //new - xprev=x; //new - yprev=y; //new + trkpos.seg = seg; + while (ts < seg->length) { + trkpos.toStart = ts; + trkpos.toRight = RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + curHeight = RtTrackHeightL(&trkpos); + texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new + texLen += texStep; //new + xprev=x; //new + yprev=y; //new + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); + SETPOINT(texLen, 0, x, y, curHeight); + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 1.0, x, y, curHeight); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + break; + case 1: + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + trkpos.toRight = RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + break; + case 2: + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + SETPOINT(texLen, 0, x, y, curHeight); + break; + } + break; + } - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); - SETPOINT(texLen, 0, x, y, curHeight); - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 1.0, x, y, curHeight); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - break; - case 1: - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - trkpos.toRight = RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - break; - case 2: - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - SETPOINT(texLen, 0, x, y, curHeight); - break; - } - break; - } + ts += LMAX; - ts += step; - - - anz += step; - } - ts = seg->arc; - break; - case TR_RGT: - step = LMAX / (mseg->radiusl); - - anz = seg->angle[TR_ZS] - step; - ts = step; - - radiusl = seg->radiusl; - trkpos.seg = seg; - while (anz > seg->angle[TR_ZE]) { - trkpos.toStart = ts; - trkpos.toRight = RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - curHeight = RtTrackHeightL(&trkpos); - texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new - texLen += texStep; //new - xprev=x; //new - yprev=y; //new - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); - SETPOINT(texLen, 0, x, y, curHeight); - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 1.0, x, y, curHeight); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - break; - case 1: - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); - trkpos.toRight = RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - break; - case 2: - SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); - SETPOINT(texLen, 0, x, y, curHeight); - break; - } - break; - } + } + ts = seg->length; + break; + case TR_LFT: + step = LMAX / (mseg->radiusr); - ts += step; - - anz -= step; - } - ts = seg->arc; - break; - } - texStep = sqrt( pow( ( seg->vertex[TR_ER].y - yprev ), 2.0f) + pow(( seg->vertex[TR_ER].x - xprev ), 2.0f) ) / curTexSize; //new - texLen += texStep; //edited - xprev = seg->vertex[TR_ER].x; //new - yprev = seg->vertex[TR_ER].y; + anz = seg->angle[TR_ZS] + step; + ts = step; - switch (curBarrier->style) { - case TR_FENCE: - if (j == 0) { - SETPOINT(texLen, 1.0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + curBarrier->height); - SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - } - break; - case TR_WALL: - switch (j) { - case 0: - trkpos.toStart = ts; - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 1.0, x, y, seg->vertex[TR_EL].z); - SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_EL].z + curBarrier->height); - if ((mseg->next->barrier[1]->style != TR_WALL) || (mseg->next->barrier[1]->height != curBarrier->height)) { - SETPOINT(texLen + curBarrier->width/curTexSize, 1.00, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - SETPOINT(texLen + curBarrier->width/curTexSize, 0.66, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + curBarrier->height); - } - break; - case 1: - trkpos.toStart = ts; - trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_EL].z + curBarrier->height); - SETPOINT(texLen, 0.33, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + curBarrier->height); - break; - case 2: - SETPOINT(texLen, 0.33, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + curBarrier->height); - SETPOINT(texLen, 0.0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); - break; - } - break; - } + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz < seg->angle[TR_ZE]) { + trkpos.toStart = ts; + trkpos.toRight = RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + curHeight = RtTrackHeightL(&trkpos); + texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new + texLen += texStep; //new + xprev=x; //new + yprev=y; //new - startNeeded = 0; - runninglentgh += seg->length; - } - } + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); + SETPOINT(texLen, 0, x, y, curHeight); + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 1.0, x, y, curHeight); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + break; + case 1: + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + trkpos.toRight = RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + break; + case 2: + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + SETPOINT(texLen, 0, x, y, curHeight); + break; + } + break; + } + + ts += step; + + + anz += step; + } + ts = seg->arc; + break; + case TR_RGT: + step = LMAX / (mseg->radiusl); + + anz = seg->angle[TR_ZS] - step; + ts = step; + + radiusl = seg->radiusl; + trkpos.seg = seg; + while (anz > seg->angle[TR_ZE]) { + trkpos.toStart = ts; + trkpos.toRight = RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + curHeight = RtTrackHeightL(&trkpos); + texStep = sqrt( pow( ( y - yprev ), 2.0f) + pow(( x - xprev ), 2.0f) ) / curTexSize; //new + texLen += texStep; //new + xprev=x; //new + yprev=y; //new + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 1.0, x, y, curHeight + curBarrier->height); + SETPOINT(texLen, 0, x, y, curHeight); + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 1.0, x, y, curHeight); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + break; + case 1: + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, curHeight + curBarrier->height); + trkpos.toRight = RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + break; + case 2: + SETPOINT(texLen, 0.33, x, y, curHeight + curBarrier->height); + SETPOINT(texLen, 0, x, y, curHeight); + break; + } + break; + } + + ts += step; + + anz -= step; + } + ts = seg->arc; + break; + } + texStep = sqrt( pow( ( seg->vertex[TR_ER].y - yprev ), 2.0f) + pow(( seg->vertex[TR_ER].x - xprev ), 2.0f) ) / curTexSize; //new + texLen += texStep; //edited + xprev = seg->vertex[TR_ER].x; //new + yprev = seg->vertex[TR_ER].y; + + switch (curBarrier->style) { + case TR_FENCE: + if (j == 0) { + SETPOINT(texLen, 1.0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + curBarrier->height); + SETPOINT(texLen, 0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + } + break; + case TR_WALL: + switch (j) { + case 0: + trkpos.toStart = ts; + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 1.0, x, y, seg->vertex[TR_EL].z); + SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_EL].z + curBarrier->height); + if ((mseg->next->barrier[1]->style != TR_WALL) || (mseg->next->barrier[1]->height != curBarrier->height)) { + SETPOINT(texLen + curBarrier->width/curTexSize, 1.00, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + SETPOINT(texLen + curBarrier->width/curTexSize, 0.66, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + curBarrier->height); + } + break; + case 1: + trkpos.toStart = ts; + trkpos.toRight = curBarrier->width + RtTrackGetWidth(seg, ts); + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + SETPOINT(texLen, 0.66, x, y, seg->vertex[TR_EL].z + curBarrier->height); + SETPOINT(texLen, 0.33, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + curBarrier->height); + break; + case 2: + SETPOINT(texLen, 0.33, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z + curBarrier->height); + SETPOINT(texLen, 0.0, seg->vertex[TR_EL].x, seg->vertex[TR_EL].y, seg->vertex[TR_EL].z); + break; + } + break; + } + + startNeeded = 0; + runninglentgh += seg->length; + } + } } if (!bump) { - /* Turn Marks */ - for (i = 0, seg = Track->seg->next; i < Track->nseg; i++, seg = seg->next) { - if (seg->ext) { - t3Dd normvec; - int nbMarks = seg->ext->nbMarks; - int *marks = seg->ext->marks; - int j, k; + /* Turn Marks */ + for (i = 0, seg = Track->seg->next; i < Track->nseg; i++, seg = seg->next) { + if (seg->ext) { + t3Dd normvec; + int nbMarks = seg->ext->nbMarks; + int *marks = seg->ext->marks; + int j, k; - for (j = 0; j < nbMarks; j++) { - /* find the segment */ - tdble lgfs = seg->lgfromstart - (tdble)marks[j]; - if (lgfs < 0) { - lgfs += Track->length; - } - for (k = 0, mseg = Track->seg->next; k < Track->nseg; k++, mseg = mseg->next) { - if ((lgfs >= mseg->lgfromstart) && (lgfs < (mseg->lgfromstart + mseg->length))) { - break; - } - } - - if (seg->type == TR_RGT) { - sprintf(buf, "turn%dR", marks[j]); - trkpos.toRight = Track->width + tmHSpace + tmWidth; - } else { - sprintf(buf, "turn%dL", marks[j]); - trkpos.toRight = -tmHSpace; - } - trkpos.toStart = lgfs - mseg->lgfromstart; - if (mseg->type != TR_STR) { - trkpos.toStart = trkpos.toStart / mseg->radius; - } - trkpos.seg = mseg; - RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); - z = tmVSpace + RtTrackHeightL(&trkpos); - if (seg->type == TR_LFT) { - RtTrackSideNormalG(mseg, x, y, TR_RGT, &normvec); - normvec.x = -normvec.x; - normvec.y = -normvec.y; - } else { - RtTrackSideNormalG(mseg, x, y, TR_LFT, &normvec); - } - CHECKDISPLIST2(buf, 0, "TuMk", mseg->id); - aDispElt->surfType = 0x10; + for (j = 0; j < nbMarks; j++) { + /* find the segment */ + tdble lgfs = seg->lgfromstart - (tdble)marks[j]; + if (lgfs < 0) { + lgfs += Track->length; + } + for (k = 0, mseg = Track->seg->next; k < Track->nseg; k++, mseg = mseg->next) { + if ((lgfs >= mseg->lgfromstart) && (lgfs < (mseg->lgfromstart + mseg->length))) { + break; + } + } - SETPOINT(0.0, 0.0, x, y, z); - SETPOINT(1.0, 0.0, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z); - SETPOINT(0.0, 1.0, x, y, z + tmHeight); - SETPOINT(1.0, 1.0, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z + tmHeight); + if (seg->type == TR_RGT) { + sprintf(buf, "turn%dR", marks[j]); + trkpos.toRight = Track->width + tmHSpace + tmWidth; + } else { + sprintf(buf, "turn%dL", marks[j]); + trkpos.toRight = -tmHSpace; + } + trkpos.toStart = lgfs - mseg->lgfromstart; + if (mseg->type != TR_STR) { + trkpos.toStart = trkpos.toStart / mseg->radius; + } + trkpos.seg = mseg; + RtTrackLocal2Global(&trkpos, &x, &y, TR_TORIGHT); + z = tmVSpace + RtTrackHeightL(&trkpos); + if (seg->type == TR_LFT) { + RtTrackSideNormalG(mseg, x, y, TR_RGT, &normvec); + normvec.x = -normvec.x; + normvec.y = -normvec.y; + } else { + RtTrackSideNormalG(mseg, x, y, TR_LFT, &normvec); + } + CHECKDISPLIST2(buf, 0, "TuMk", mseg->id); + aDispElt->surfType = 0x10; - CHECKDISPLIST2("back-sign", 0, "TuMk", mseg->id); - aDispElt->surfType = 0x10; + SETPOINT(0.0, 0.0, x, y, z); + SETPOINT(1.0, 0.0, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z); + SETPOINT(0.0, 1.0, x, y, z + tmHeight); + SETPOINT(1.0, 1.0, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z + tmHeight); - SETPOINT(0.0, 0.0, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z); - SETPOINT(1.0, 0.0, x, y, z); - SETPOINT(0.0, 1.0, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z + tmHeight); - SETPOINT(1.0, 1.0, x, y, z + tmHeight); + CHECKDISPLIST2("back-sign", 0, "TuMk", mseg->id); + aDispElt->surfType = 0x10; - printf("(%f, %f, %f), (%f, %f, %f)\n", x, y, z, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z + tmHeight); - - } - } - } - - + SETPOINT(0.0, 0.0, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z); + SETPOINT(1.0, 0.0, x, y, z); + SETPOINT(0.0, 1.0, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z + tmHeight); + SETPOINT(1.0, 1.0, x, y, z + tmHeight); - /* Start Bridge */ - CHECKDISPLIST2("pylon1", 4, "S0Bg", 0); + printf("(%f, %f, %f), (%f, %f, %f)\n", x, y, z, x + tmWidth * normvec.x, y + tmWidth * normvec.y, z + tmHeight); + + } + } + } + + + + /* Start Bridge */ + CHECKDISPLIST2("pylon1", 4, "S0Bg", 0); #define BR_HEIGHT_1 8.0 #define BR_HEIGHT_2 6.0 #define BR_WIDTH_0 2.0 #define BR_WIDTH_1 2.0 - mseg = Track->seg->next; - if (mseg->rside) { - seg = mseg->rside; - if (seg->rside) { - seg = seg->rside; - } - } else { - seg = mseg; - } + mseg = Track->seg->next; + if (mseg->rside) { + seg = mseg->rside; + if (seg->rside) { + seg = seg->rside; + } + } else { + seg = mseg; + } - x = seg->vertex[TR_SR].x; - y = seg->vertex[TR_SR].y - 0.1; - z = seg->vertex[TR_SR].z; + x = seg->vertex[TR_SR].x; + y = seg->vertex[TR_SR].y - 0.1; + z = seg->vertex[TR_SR].z; - SETPOINT(0, 0, x, y, z); - SETPOINT(0, 1, x, y, z + BR_HEIGHT_2); + SETPOINT(0, 0, x, y, z); + SETPOINT(0, 1, x, y, z + BR_HEIGHT_2); - x += BR_WIDTH_0; + x += BR_WIDTH_0; - SETPOINT(1, 0, x, y, z); - SETPOINT(1, 1, x, y, z + BR_HEIGHT_2); + SETPOINT(1, 0, x, y, z); + SETPOINT(1, 1, x, y, z + BR_HEIGHT_2); - y -= BR_WIDTH_1; + y -= BR_WIDTH_1; - SETPOINT(2, 0, x, y, z); - SETPOINT(2, 1, x, y, z + BR_HEIGHT_2); + SETPOINT(2, 0, x, y, z); + SETPOINT(2, 1, x, y, z + BR_HEIGHT_2); - x -= BR_WIDTH_0; + x -= BR_WIDTH_0; - SETPOINT(3, 0, x, y, z); - SETPOINT(3, 1, x, y, z + BR_HEIGHT_2); + SETPOINT(3, 0, x, y, z); + SETPOINT(3, 1, x, y, z + BR_HEIGHT_2); - y += BR_WIDTH_1; + y += BR_WIDTH_1; - SETPOINT(4, 0, x, y, z); - SETPOINT(4, 1, x, y, z + BR_HEIGHT_2); - - - NEWDISPLIST(0, "S1Bg", 0); - - if (mseg->lside) { - seg = mseg->lside; - if (seg->lside) { - seg = seg->lside; - } - } else { - seg = mseg; - } - x2 = seg->vertex[TR_SL].x; - y2 = seg->vertex[TR_SL].y + 0.1; - z2 = seg->vertex[TR_SL].z; - - SETPOINT(0, 1, x2, y2, z + BR_HEIGHT_2); - SETPOINT(0, 0, x2, y2, z2); - - x2 += BR_WIDTH_0; - - SETPOINT(1, 1, x2, y2, z + BR_HEIGHT_2); - SETPOINT(1, 0, x2, y2, z2); - - y2 += BR_WIDTH_1; - - SETPOINT(2, 1, x2, y2, z + BR_HEIGHT_2); - SETPOINT(2, 0, x2, y2, z2); - - x2 -= BR_WIDTH_0; - - SETPOINT(3, 1, x2, y2, z + BR_HEIGHT_2); - SETPOINT(3, 0, x2, y2, z2); - - y2 -= BR_WIDTH_1; - - SETPOINT(4, 1, x2, y2, z + BR_HEIGHT_2); - SETPOINT(4, 0, x2, y2, z2); - - CHECKDISPLIST2("pylon2", 4, "S2Bg", 0); + SETPOINT(4, 0, x, y, z); + SETPOINT(4, 1, x, y, z + BR_HEIGHT_2); - SETPOINT(0, 1, x, y, z + BR_HEIGHT_1); - SETPOINT(0, 0, x, y, z + BR_HEIGHT_2); + NEWDISPLIST(0, "S1Bg", 0); - y -= BR_WIDTH_1; + if (mseg->lside) { + seg = mseg->lside; + if (seg->lside) { + seg = seg->lside; + } + } else { + seg = mseg; + } + x2 = seg->vertex[TR_SL].x; + y2 = seg->vertex[TR_SL].y + 0.1; + z2 = seg->vertex[TR_SL].z; - SETPOINT(1, 1, x, y, z + BR_HEIGHT_1); - SETPOINT(1, 0, x, y, z + BR_HEIGHT_2); + SETPOINT(0, 1, x2, y2, z + BR_HEIGHT_2); + SETPOINT(0, 0, x2, y2, z2); - x += BR_WIDTH_0; + x2 += BR_WIDTH_0; - SETPOINT(2, 1, x, y, z + BR_HEIGHT_1); - SETPOINT(2, 0, x, y, z + BR_HEIGHT_2); + SETPOINT(1, 1, x2, y2, z + BR_HEIGHT_2); + SETPOINT(1, 0, x2, y2, z2); - y += BR_WIDTH_1; - - SETPOINT(3, 1, x, y, z + BR_HEIGHT_1); - SETPOINT(3, 0, x, y, z + BR_HEIGHT_2); + y2 += BR_WIDTH_1; - x -= BR_WIDTH_0; - - SETPOINT(3, 1, x + BR_WIDTH_0, y, z + BR_HEIGHT_1); - SETPOINT(3, 0, x, y, z + BR_HEIGHT_1); + SETPOINT(2, 1, x2, y2, z + BR_HEIGHT_2); + SETPOINT(2, 0, x2, y2, z2); - y -= BR_WIDTH_1; - - SETPOINT(4, 1, x + BR_WIDTH_0, y, z + BR_HEIGHT_1); - SETPOINT(4, 0, x, y, z + BR_HEIGHT_1); + x2 -= BR_WIDTH_0; - y += BR_WIDTH_1; /* back to origin */ + SETPOINT(3, 1, x2, y2, z + BR_HEIGHT_2); + SETPOINT(3, 0, x2, y2, z2); - NEWDISPLIST(0, "S3Bg", 0); + y2 -= BR_WIDTH_1; - y2 += BR_WIDTH_1; + SETPOINT(4, 1, x2, y2, z + BR_HEIGHT_2); + SETPOINT(4, 0, x2, y2, z2); - SETPOINT(0, 1, x2 + BR_WIDTH_0, y2, z + BR_HEIGHT_1); - SETPOINT(0, 0, x2, y2, z + BR_HEIGHT_1); - - y2 -= BR_WIDTH_1; - - SETPOINT(1, 1, x2 + BR_WIDTH_0, y2, z + BR_HEIGHT_1); - SETPOINT(1, 0, x2, y2, z + BR_HEIGHT_1); - - x2 += BR_WIDTH_0; - - SETPOINT(1, 1, x2, y2, z + BR_HEIGHT_1); - SETPOINT(1, 0, x2, y2, z + BR_HEIGHT_2); - - y2 += BR_WIDTH_1; - - SETPOINT(2, 1, x2, y2, z + BR_HEIGHT_1); - SETPOINT(2, 0, x2, y2, z + BR_HEIGHT_2); - - x2 -= BR_WIDTH_0; - - SETPOINT(3, 1, x2, y2, z + BR_HEIGHT_1); - SETPOINT(3, 0, x2, y2, z + BR_HEIGHT_2); - - y2 -= BR_WIDTH_1; - - SETPOINT(4, 1, x2, y2, z + BR_HEIGHT_1); - SETPOINT(4, 0, x2, y2, z + BR_HEIGHT_2); - - /* Middle on the bridge */ - CHECKDISPLIST2("pylon3", 4, "S4Bg", 2); - - SETPOINT(0, 0, x2, y2, z + BR_HEIGHT_2); - SETPOINT(1, 0, x, y, z + BR_HEIGHT_2); - SETPOINT(0, 0.25, x2, y2, z + BR_HEIGHT_1); - SETPOINT(1, 0.25, x, y, z + BR_HEIGHT_1); - - x += BR_WIDTH_0; - x2 += BR_WIDTH_0; - - SETPOINT(0, 0.5, x2, y2, z + BR_HEIGHT_1); - SETPOINT(1, 0.5, x, y, z + BR_HEIGHT_1); + CHECKDISPLIST2("pylon2", 4, "S2Bg", 0); - SETPOINT(0, 0.75, x2, y2, z + BR_HEIGHT_2); - SETPOINT(1, 0.75, x, y, z + BR_HEIGHT_2); + SETPOINT(0, 1, x, y, z + BR_HEIGHT_1); + SETPOINT(0, 0, x, y, z + BR_HEIGHT_2); - x -= BR_WIDTH_0; - x2 -= BR_WIDTH_0; + y -= BR_WIDTH_1; - SETPOINT(0, 1, x2, y2, z + BR_HEIGHT_2); - SETPOINT(1, 1, x, y, z + BR_HEIGHT_2); + SETPOINT(1, 1, x, y, z + BR_HEIGHT_1); + SETPOINT(1, 0, x, y, z + BR_HEIGHT_2); + + x += BR_WIDTH_0; + + SETPOINT(2, 1, x, y, z + BR_HEIGHT_1); + SETPOINT(2, 0, x, y, z + BR_HEIGHT_2); + + y += BR_WIDTH_1; + + SETPOINT(3, 1, x, y, z + BR_HEIGHT_1); + SETPOINT(3, 0, x, y, z + BR_HEIGHT_2); + + x -= BR_WIDTH_0; + + SETPOINT(3, 1, x + BR_WIDTH_0, y, z + BR_HEIGHT_1); + SETPOINT(3, 0, x, y, z + BR_HEIGHT_1); + + y -= BR_WIDTH_1; + + SETPOINT(4, 1, x + BR_WIDTH_0, y, z + BR_HEIGHT_1); + SETPOINT(4, 0, x, y, z + BR_HEIGHT_1); + + y += BR_WIDTH_1; /* back to origin */ + + NEWDISPLIST(0, "S3Bg", 0); + + y2 += BR_WIDTH_1; + + SETPOINT(0, 1, x2 + BR_WIDTH_0, y2, z + BR_HEIGHT_1); + SETPOINT(0, 0, x2, y2, z + BR_HEIGHT_1); + + y2 -= BR_WIDTH_1; + + SETPOINT(1, 1, x2 + BR_WIDTH_0, y2, z + BR_HEIGHT_1); + SETPOINT(1, 0, x2, y2, z + BR_HEIGHT_1); + + x2 += BR_WIDTH_0; + + SETPOINT(1, 1, x2, y2, z + BR_HEIGHT_1); + SETPOINT(1, 0, x2, y2, z + BR_HEIGHT_2); + + y2 += BR_WIDTH_1; + + SETPOINT(2, 1, x2, y2, z + BR_HEIGHT_1); + SETPOINT(2, 0, x2, y2, z + BR_HEIGHT_2); + + x2 -= BR_WIDTH_0; + + SETPOINT(3, 1, x2, y2, z + BR_HEIGHT_1); + SETPOINT(3, 0, x2, y2, z + BR_HEIGHT_2); + + y2 -= BR_WIDTH_1; + + SETPOINT(4, 1, x2, y2, z + BR_HEIGHT_1); + SETPOINT(4, 0, x2, y2, z + BR_HEIGHT_2); + + /* Middle on the bridge */ + CHECKDISPLIST2("pylon3", 4, "S4Bg", 2); + + SETPOINT(0, 0, x2, y2, z + BR_HEIGHT_2); + SETPOINT(1, 0, x, y, z + BR_HEIGHT_2); + SETPOINT(0, 0.25, x2, y2, z + BR_HEIGHT_1); + SETPOINT(1, 0.25, x, y, z + BR_HEIGHT_1); + + x += BR_WIDTH_0; + x2 += BR_WIDTH_0; + + SETPOINT(0, 0.5, x2, y2, z + BR_HEIGHT_1); + SETPOINT(1, 0.5, x, y, z + BR_HEIGHT_1); + + + SETPOINT(0, 0.75, x2, y2, z + BR_HEIGHT_2); + SETPOINT(1, 0.75, x, y, z + BR_HEIGHT_2); + + x -= BR_WIDTH_0; + x2 -= BR_WIDTH_0; + + SETPOINT(0, 1, x2, y2, z + BR_HEIGHT_2); + SETPOINT(1, 1, x, y, z + BR_HEIGHT_2); - /* draw the pits */ + /* draw the pits */ #define PIT_HEIGHT 5.0 #define PIT_DEEP 10.0 #define PIT_TOP 0.2 - pits = &(Track->pits); - initPits(Track,TrackHandle,pits); + pits = &(Track->pits); + initPits(Track,TrackHandle,pits); - switch(pits->type) { - case TR_PIT_ON_TRACK_SIDE: - { - static int uid = 1; - t3Dd normvec; + switch(pits->type) { + case TR_PIT_ON_TRACK_SIDE: + { + static int uid = 1; + t3Dd normvec; - startNeeded = 1; - sprintf(sname, "P%dts", uid++); - CHECKDISPLIST3("concrete2.png", 4, sname, pits->driversPits[0].pos.seg->id); + startNeeded = 1; + sprintf(sname, "P%dts", uid++); + CHECKDISPLIST3("concrete2.png", 4, sname, pits->driversPits[0].pos.seg->id); - RtTrackLocal2Global(&(pits->driversPits[0].pos), &x, &y, pits->driversPits[0].pos.type); - RtTrackSideNormalG(pits->driversPits[0].pos.seg, x, y, pits->side, &normvec); - z2 = RtTrackHeightG(pits->driversPits[0].pos.seg, x, y); + RtTrackLocal2Global(&(pits->driversPits[0].pos), &x, &y, pits->driversPits[0].pos.type); + RtTrackSideNormalG(pits->driversPits[0].pos.seg, x, y, pits->side, &normvec); + z2 = RtTrackHeightG(pits->driversPits[0].pos.seg, x, y); - x2 = x + PIT_TOP * normvec.x; - y2 = y + PIT_TOP * normvec.y; - SETPOINT(1.0 - PIT_TOP, PIT_HEIGHT - PIT_TOP, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); - SETPOINT(1.0 - PIT_TOP, PIT_HEIGHT, x2, y2, z2 + PIT_HEIGHT); + x2 = x + PIT_TOP * normvec.x; + y2 = y + PIT_TOP * normvec.y; + SETPOINT(1.0 - PIT_TOP, PIT_HEIGHT - PIT_TOP, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); + SETPOINT(1.0 - PIT_TOP, PIT_HEIGHT, x2, y2, z2 + PIT_HEIGHT); - x2 = x; - y2 = y; - SETPOINT(1.0, PIT_HEIGHT - PIT_TOP, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); + x2 = x; + y2 = y; + SETPOINT(1.0, PIT_HEIGHT - PIT_TOP, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); - x2 = x - PIT_DEEP * normvec.x; - y2 = y - PIT_DEEP * normvec.y; - SETPOINT(1.0 + PIT_DEEP, PIT_HEIGHT, x2, y2, z2 + PIT_HEIGHT); + x2 = x - PIT_DEEP * normvec.x; + y2 = y - PIT_DEEP * normvec.y; + SETPOINT(1.0 + PIT_DEEP, PIT_HEIGHT, x2, y2, z2 + PIT_HEIGHT); - x2 = x; - y2 = y; - SETPOINT(1.0, 0, x2, y2, z2); + x2 = x; + y2 = y; + SETPOINT(1.0, 0, x2, y2, z2); - x2 = x - PIT_DEEP * normvec.x; - y2 = y - PIT_DEEP * normvec.y; - SETPOINT(1.0 + PIT_DEEP, 0, x2, y2, z2); + x2 = x - PIT_DEEP * normvec.x; + y2 = y - PIT_DEEP * normvec.y; + SETPOINT(1.0 + PIT_DEEP, 0, x2, y2, z2); - for (i = 0; i < pits->driversPitsNb; i++) { - startNeeded = 1; - sprintf(sname, "P%dts", uid++); - CHECKDISPLIST3("concrete.png", 4, sname, pits->driversPits[i].pos.seg->id); + for (i = 0; i < pits->driversPitsNb; i++) { + startNeeded = 1; + sprintf(sname, "P%dts", uid++); + CHECKDISPLIST3("concrete.png", 4, sname, pits->driversPits[i].pos.seg->id); - RtTrackLocal2Global(&(pits->driversPits[i].pos), &x, &y, pits->driversPits[i].pos.type); - RtTrackSideNormalG(pits->driversPits[i].pos.seg, x, y, pits->side, &normvec); - x2 = x; - y2 = y; - z2 = RtTrackHeightG(pits->driversPits[i].pos.seg, x2, y2); + RtTrackLocal2Global(&(pits->driversPits[i].pos), &x, &y, pits->driversPits[i].pos.type); + RtTrackSideNormalG(pits->driversPits[i].pos.seg, x, y, pits->side, &normvec); + x2 = x; + y2 = y; + z2 = RtTrackHeightG(pits->driversPits[i].pos.seg, x2, y2); - if (pits->side == TR_RGT) { - x3 = x + pits->len * normvec.y; - y3 = y - pits->len * normvec.x; - } else { - x3 = x - pits->len * normvec.y; - y3 = y + pits->len * normvec.x; - } + if (pits->side == TR_RGT) { + x3 = x + pits->len * normvec.y; + y3 = y - pits->len * normvec.x; + } else { + x3 = x - pits->len * normvec.y; + y3 = y + pits->len * normvec.x; + } - z3 = RtTrackHeightG(pits->driversPits[i].pos.seg, x3, y3); - SETPOINT(pits->len, 0, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); - SETPOINT(0, 0, x3, y3, z3 + PIT_HEIGHT - PIT_TOP); + z3 = RtTrackHeightG(pits->driversPits[i].pos.seg, x3, y3); + SETPOINT(pits->len, 0, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); + SETPOINT(0, 0, x3, y3, z3 + PIT_HEIGHT - PIT_TOP); - tdble dx = PIT_TOP * normvec.x; - tdble dy = PIT_TOP * normvec.y; - SETPOINT(pits->len, PIT_TOP, x2 + dx, y2 + dy, z2 + PIT_HEIGHT - PIT_TOP); - SETPOINT(0, PIT_TOP, x3 + dx, y3 + dy, z3 + PIT_HEIGHT - PIT_TOP); - SETPOINT(pits->len, 2 * PIT_TOP, x2 + dx, y2 + dy, z2 + PIT_HEIGHT); - SETPOINT(0, 2 * PIT_TOP, x3 + dx, y3 + dy, z3 + PIT_HEIGHT); + tdble dx = PIT_TOP * normvec.x; + tdble dy = PIT_TOP * normvec.y; + SETPOINT(pits->len, PIT_TOP, x2 + dx, y2 + dy, z2 + PIT_HEIGHT - PIT_TOP); + SETPOINT(0, PIT_TOP, x3 + dx, y3 + dy, z3 + PIT_HEIGHT - PIT_TOP); + SETPOINT(pits->len, 2 * PIT_TOP, x2 + dx, y2 + dy, z2 + PIT_HEIGHT); + SETPOINT(0, 2 * PIT_TOP, x3 + dx, y3 + dy, z3 + PIT_HEIGHT); - dx = - PIT_DEEP * normvec.x; - dy = - PIT_DEEP * normvec.y; + dx = - PIT_DEEP * normvec.x; + dy = - PIT_DEEP * normvec.y; - SETPOINT(pits->len, 2 * PIT_TOP + PIT_DEEP, x2 + dx, y2 + dy, z2 + PIT_HEIGHT); - SETPOINT(0, 2 * PIT_TOP + PIT_DEEP, x3 + dx, y3 + dy, z3 + PIT_HEIGHT); - SETPOINT(pits->len, 2 * PIT_TOP + PIT_DEEP + PIT_HEIGHT, x2 + dx, y2 + dy, z2); - SETPOINT(0, 2 * PIT_TOP + PIT_DEEP + PIT_HEIGHT, x3 + dx, y3 + dy, z3); - }//for i + SETPOINT(pits->len, 2 * PIT_TOP + PIT_DEEP, x2 + dx, y2 + dy, z2 + PIT_HEIGHT); + SETPOINT(0, 2 * PIT_TOP + PIT_DEEP, x3 + dx, y3 + dy, z3 + PIT_HEIGHT); + SETPOINT(pits->len, 2 * PIT_TOP + PIT_DEEP + PIT_HEIGHT, x2 + dx, y2 + dy, z2); + SETPOINT(0, 2 * PIT_TOP + PIT_DEEP + PIT_HEIGHT, x3 + dx, y3 + dy, z3); + }//for i - startNeeded = 1; - i--; - sprintf(sname, "P%dts", uid++); - CHECKDISPLIST3("concrete2.png", 4, sname, pits->driversPits[i].pos.seg->id); + startNeeded = 1; + i--; + sprintf(sname, "P%dts", uid++); + CHECKDISPLIST3("concrete2.png", 4, sname, pits->driversPits[i].pos.seg->id); - RtTrackLocal2Global(&(pits->driversPits[i].pos), &x, &y, pits->driversPits[i].pos.type); - RtTrackSideNormalG(pits->driversPits[i].pos.seg, x, y, pits->side, &normvec); + RtTrackLocal2Global(&(pits->driversPits[i].pos), &x, &y, pits->driversPits[i].pos.type); + RtTrackSideNormalG(pits->driversPits[i].pos.seg, x, y, pits->side, &normvec); - if (pits->side == TR_RGT) { - x += pits->len * normvec.y; - y -= pits->len * normvec.x; - } else { - x -= pits->len * normvec.y; - y += pits->len * normvec.x; - } + if (pits->side == TR_RGT) { + x += pits->len * normvec.y; + y -= pits->len * normvec.x; + } else { + x -= pits->len * normvec.y; + y += pits->len * normvec.x; + } - z2 = RtTrackHeightG(pits->driversPits[i].pos.seg, x, y); - x2 = x + PIT_TOP * normvec.x; - y2 = y + PIT_TOP * normvec.y; - SETPOINT(1.0 - PIT_TOP, PIT_HEIGHT, x2, y2, z2 + PIT_HEIGHT); - SETPOINT(1.0 - PIT_TOP, PIT_HEIGHT - PIT_TOP, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); + z2 = RtTrackHeightG(pits->driversPits[i].pos.seg, x, y); + x2 = x + PIT_TOP * normvec.x; + y2 = y + PIT_TOP * normvec.y; + SETPOINT(1.0 - PIT_TOP, PIT_HEIGHT, x2, y2, z2 + PIT_HEIGHT); + SETPOINT(1.0 - PIT_TOP, PIT_HEIGHT - PIT_TOP, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); - x2 = x - PIT_DEEP * normvec.x; - y2 = y - PIT_DEEP * normvec.y; - SETPOINT(1.0 + PIT_DEEP, PIT_HEIGHT, x2, y2, z2 + PIT_HEIGHT); + x2 = x - PIT_DEEP * normvec.x; + y2 = y - PIT_DEEP * normvec.y; + SETPOINT(1.0 + PIT_DEEP, PIT_HEIGHT, x2, y2, z2 + PIT_HEIGHT); - x2 = x; - y2 = y; - SETPOINT(1.0, PIT_HEIGHT - PIT_TOP, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); + x2 = x; + y2 = y; + SETPOINT(1.0, PIT_HEIGHT - PIT_TOP, x2, y2, z2 + PIT_HEIGHT - PIT_TOP); - x2 = x - PIT_DEEP * normvec.x; - y2 = y - PIT_DEEP * normvec.y; - SETPOINT(1.0 + PIT_DEEP, 0, x2, y2, z2); + x2 = x - PIT_DEEP * normvec.x; + y2 = y - PIT_DEEP * normvec.y; + SETPOINT(1.0 + PIT_DEEP, 0, x2, y2, z2); - x2 = x; - y2 = y; - SETPOINT(1.0, 0, x2, y2, z2); - break; //TR_PIT_ON_TRACK_SIDE - } - case TR_PIT_NO_BUILDING: - break; + x2 = x; + y2 = y; + SETPOINT(1.0, 0, x2, y2, z2); + break; //TR_PIT_ON_TRACK_SIDE + } + case TR_PIT_NO_BUILDING: + break; - case TR_PIT_ON_SEPARATE_PATH: - break; + case TR_PIT_ON_SEPARATE_PATH: + break; - case TR_PIT_NONE: - break; + case TR_PIT_NONE: + break; - }//switch pits->type - } - CLOSEDISPLIST(); - printf("=== Indices really used = %d\n", nbvert); + }//switch pits->type + } + CLOSEDISPLIST(); + printf("=== Indices really used = %d\n", nbvert); - return 0; + return 0; }//InitScene @@ -2672,53 +2690,53 @@ static void saveObject(FILE *curFd, int nb, int start, char *texture, char *name, int surfType) { int i, index; - + fprintf(curFd, "OBJECT poly\n"); - fprintf(curFd, "name \"%s\"\n", name); + fprintf(curFd, "name \"%s\"\n", name); fprintf(curFd, "texture \"%s\"\n", texture); fprintf(curFd, "numvert %d\n", nb); for (i = 0; i < nb; i++) { - index = 3 * (start + i); - fprintf(curFd, "%f %f %f\n", trackvertices[index], trackvertices[index+2], -trackvertices[index+1]); + index = 3 * (start + i); + fprintf(curFd, "%f %f %f\n", trackvertices[index], trackvertices[index+2], -trackvertices[index+1]); } fprintf(curFd, "numsurf %d\n", nb - 2); if (surfType) { - fprintf(curFd, "SURF 0x10\n"); + fprintf(curFd, "SURF 0x10\n"); } else { - fprintf(curFd, "SURF 0x30\n"); + fprintf(curFd, "SURF 0x30\n"); } fprintf(curFd, "mat 0\n"); fprintf(curFd, "refs 3\n"); fprintf(curFd, "%d %f %f\n", 0, tracktexcoord[2*start], tracktexcoord[2*start+1]); fprintf(curFd, "%d %f %f\n", 1, tracktexcoord[2*(start+1)], tracktexcoord[2*(start+1)+1]); fprintf(curFd, "%d %f %f\n", 2, tracktexcoord[2*(start+2)], tracktexcoord[2*(start+2)+1]); - + /* triangle strip conversion to triangles */ for (i = 2; i < nb-1; i++) { - if (surfType) { - fprintf(curFd, "SURF 0x10\n"); - } else { - fprintf(curFd, "SURF 0x30\n"); - } - fprintf(curFd, "mat 0\n"); - fprintf(curFd, "refs 3\n"); - if ((i % 2) == 0) { - index = i; - fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); - index = i - 1; - fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); - index = i + 1; - fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); - } else { - index = i - 1; - fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); - index = i; - fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); - index = i + 1; - fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); - } + if (surfType) { + fprintf(curFd, "SURF 0x10\n"); + } else { + fprintf(curFd, "SURF 0x30\n"); + } + fprintf(curFd, "mat 0\n"); + fprintf(curFd, "refs 3\n"); + if ((i % 2) == 0) { + index = i; + fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); + index = i - 1; + fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); + index = i + 1; + fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); + } else { + index = i - 1; + fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); + index = i; + fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); + index = i + 1; + fprintf(curFd, "%d %f %f\n", index, tracktexcoord[2*(start+index)], tracktexcoord[2*(start+index)+1]); + } } fprintf(curFd, "kids 0\n"); } @@ -2732,24 +2750,24 @@ SaveMainTrack(FILE *curFd, int bump, int raceline) int i; for (i = 0; i < GroupNb; i++) { - if (Groups[i].nb != 0) { - aDispElt = Groups[i].dispList; - sprintf(buf, "TKMN%d", i); - Ac3dGroup(curFd, buf, Groups[i].nb); - do { - aDispElt = aDispElt->next; - if (aDispElt->nb != 0) { - sprintf(buf, "%s%d", aDispElt->name, aDispElt->id); - if (bump) { - saveObject(curFd, aDispElt->nb, aDispElt->start, aDispElt->texture->namebump, buf, aDispElt->surfType); - } else if (raceline) { - saveObject(curFd, aDispElt->nb, aDispElt->start, aDispElt->texture->nameraceline, buf, aDispElt->surfType); - } else { - saveObject(curFd, aDispElt->nb, aDispElt->start, aDispElt->texture->name, buf, aDispElt->surfType); - } - } - } while (aDispElt != Groups[i].dispList); - } + if (Groups[i].nb != 0) { + aDispElt = Groups[i].dispList; + sprintf(buf, "TKMN%d", i); + Ac3dGroup(curFd, buf, Groups[i].nb); + do { + aDispElt = aDispElt->next; + if (aDispElt->nb != 0) { + sprintf(buf, "%s%d", aDispElt->name, aDispElt->id); + if (bump) { + saveObject(curFd, aDispElt->nb, aDispElt->start, aDispElt->texture->namebump, buf, aDispElt->surfType); + } else if (raceline) { + saveObject(curFd, aDispElt->nb, aDispElt->start, aDispElt->texture->nameraceline, buf, aDispElt->surfType); + } else { + saveObject(curFd, aDispElt->nb, aDispElt->start, aDispElt->texture->name, buf, aDispElt->surfType); + } + } + } while (aDispElt != Groups[i].dispList); + } } } @@ -2762,12 +2780,12 @@ SaveMainTrack(FILE *curFd, int bump, int raceline) */ void CalculateTrack(tTrack * Track, void *TrackHandle, int bump, int raceline) { - TrackStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_TSTEP, NULL, TrackStep); - printf("Track step: %.2f ", TrackStep); - - InitScene(Track, TrackHandle, bump, raceline); - - printf("Calculation finished\n"); + TrackStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_TSTEP, NULL, TrackStep); + printf("Track step: %.2f ", TrackStep); + + InitScene(Track, TrackHandle, bump, raceline); + + printf("Calculation finished\n"); } @@ -2782,7 +2800,7 @@ void GenerateTrack(tTrack * Track, void *TrackHandle, char *outFile, FILE *AllFd, int bump, int raceline) { FILE *curFd; - + TrackStep = GfParmGetNum(TrackHandle, TRK_SECT_TERRAIN, TRK_ATT_TSTEP, NULL, TrackStep); printf("Track step: %.2f ", TrackStep); @@ -2794,7 +2812,7 @@ GenerateTrack(tTrack * Track, void *TrackHandle, char *outFile, FILE *AllFd, int SaveMainTrack(curFd, bump, raceline); Ac3dClose(curFd); } - + if (AllFd) { Ac3dGroup(AllFd, "track", ActiveGroups); SaveMainTrack(AllFd, bump, raceline); diff --git a/src/tools/trackgen/trackgen.h b/src/tools/trackgen/trackgen.h index 8b7b366f7..47d351e13 100644 --- a/src/tools/trackgen/trackgen.h +++ b/src/tools/trackgen/trackgen.h @@ -2,7 +2,7 @@ file : trackgen.h created : Sun Dec 24 16:00:03 CET 2000 - copyright : (C) 2000 by Eric Espié + copyright : (C) 2000 by Eric Espié email : Eric.Espie@torcs.org version : $Id$ @@ -16,9 +16,9 @@ * (at your option) any later version. * * * ***************************************************************************/ - -/** @file - + +/** @file + @author Eric Espie @version $Id$ */ @@ -35,12 +35,13 @@ extern void GenerateTrack(tTrack * Track, void *TrackHandle, char *outFile, FILE *AllFd, int bump, int raceline); extern void CalculateTrack(tTrack * Track, void *TrackHandle, int bump, int trackline); extern void generateRaceLine(tTrack* pTrack, const double SideDistExt, const double SideDistInt); +extern double getTexureOffset(double length); extern char *OutputFileName; extern int HeightSteps; extern int UseBorder; -#endif /* _TRACKGEN_H_ */ +#endif /* _TRACKGEN_H_ */