TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
Robot Track Tools API

API to gather information about the track and the cars state relative to the track. More...

Collaboration diagram for Robot Track Tools API:

Functions

tdble RtTrackGetWidth (tTrackSeg *seg, tdble toStart)
 Get the track width at the specified point.
void RtTrackLocal2Global (tTrkLocPos *p, tdble *X, tdble *Y, int flag)
 Calculate global coordinates from a local position relative to the given track segment (segment, toRight, toStart)The toStart position refers to the current segment, the function will not search for next segment if toStart is greater than the segment length.
void RtTrackGlobal2LocalD (tTrackSeg *segment, double X, double Y, tTrkLocPos *p, int type)
 Convert global coordinates to a local track position using double intermediates.
void RtTrackGlobal2Local (tTrackSeg *segment, tdble X, tdble Y, tTrkLocPos *p, int type)
 Convert global coordinates to a local track position.
tdble RtTrackHeightL (tTrkLocPos *p)
 Returns the absolute height in meters of the road at the Local position p.
tTrackSeg * RtTrackGetSideNeighbourSeg (tTrackSeg *main, tTrackSeg *current, int tr_side)
 Get the neighbour segment of the given current segment.
tTrackSeg * RtTrackGetSeg (tTrkLocPos *p)
 Get the effective segment of the given position starting from a segment of type TR_MAIN, searching to the sides.
tdble RtTrackHeightG (tTrackSeg *seg, tdble X, tdble Y)
 Returns the absolute height in meters of the road at the Global position (segment, X, Y)
void RtTrackSideNormalG (tTrackSeg *seg, tdble X, tdble Y, int side, t3Dd *norm)
 Compute the horizontal inward border normal using the supplied segment.
tdble RtTrackSideTgAngleL (tTrkLocPos *p)
 Used to get the tangent angle for a track position The angle is given in radian.
void RtTrackSurfaceNormalL (tTrkLocPos *p, t3Dd *norm)
 Used to get the normal vector of the road (pointing upward).
tdble RtGetDistFromStart (tCarElt *car)
 Get distance along the track from the start/finish line.
tdble RtGetDistFromStart2 (tTrkLocPos *p)
 Get distance along the track from the start/finish line.
int RtDistToPit (struct CarElt *car, tTrack *track, tdble *dL, tdble *dW)
 Get the distance to the pit stop.

Detailed Description

API to gather information about the track and the cars state relative to the track.

Function Documentation

◆ RtDistToPit()

int RtDistToPit ( struct CarElt * car,
tTrack * track,
tdble * dL,
tdble * dW )

Get the distance to the pit stop.

Parameters
[in]carThe concerned car.
[in]trackThe current Track
[out]dLNon-NULL destination for forward longitudinal distance in meters, adjusted by one track length when outside [0, track length].
[out]dWNon-NULL destination for pit.toRight - car.toRight in meters.
Returns
0 on success; 1 if the car has no assigned pit, leaving both outputs unchanged.
Note
With both lateral coordinates in the same main-track frame, dW is positive when the pit lies to the car's left, negative to its right.

Definition at line 692 of file rttrack.cpp.

Here is the call graph for this function:

◆ RtGetDistFromStart()

tdble RtGetDistFromStart ( tCarElt * car)

Get distance along the track from the start/finish line.

Parameters
[in]carthe concerned car.
Returns
Distance in meters using the car's local position; lap count is not included.

Definition at line 646 of file rttrack.cpp.

Here is the call graph for this function:

◆ RtGetDistFromStart2()

tdble RtGetDistFromStart2 ( tTrkLocPos * p)

Get distance along the track from the start/finish line.

Parameters
[in]pLocal position
Returns
Segment lgfromstart plus toStart (multiplied by radius on curves), in meters. Does not wrap or clamp positions outside the segment.

Definition at line 659 of file rttrack.cpp.

◆ RtTrackGetSeg()

tTrackSeg * RtTrackGetSeg ( tTrkLocPos * p)

Get the effective segment of the given position starting from a segment of type TR_MAIN, searching to the sides.

It does not search along the previous and next segments on the track. The supplied position is not modified.

Parameters
[in]pCurrent position relative to the main segment
Returns
segment for the given position

Definition at line 450 of file rttrack.cpp.

Here is the call graph for this function:

◆ RtTrackGetSideNeighbourSeg()

tTrackSeg * RtTrackGetSideNeighbourSeg ( tTrackSeg * main,
tTrackSeg * current,
int tr_side )

Get the neighbour segment of the given current segment.

This is required, because the lside and rside members only point to segments on the outside, the inside pointer is always NULL and this is implied in various code locations.

Parameters
[in]mainMain segment owning current's side chain (TR_MAIN).
[in]currentSegment to find the neighbour for
[in]tr_sideNeighbour we are looking for, either left or right, TR_SIDE_LFT or TR_SIDE_RGT
Returns
Borrowed adjacent segment when found. If the reverse-chain search finds no match, returns its last saved predecessor (initially main); NULL is not an end-of-chain sentinel. Both input segments must be valid.

Definition at line 419 of file rttrack.cpp.

Here is the call graph for this function:

◆ RtTrackGetWidth()

tdble RtTrackGetWidth ( tTrackSeg * seg,
tdble toStart )

Get the track width at the specified point.

Parameters
[in]segSegment
[in]toStartDistance from the beginning of the segment.
The units are:
  • meters for straights
  • radians for turns
Returns
Absolute value of startWidth + toStart*Kyl, in meters. The position is not clamped and no neighbouring segment is searched.
Note
The Pit lane and the track have different width, and the side segments have variable width.

Definition at line 59 of file rttrack.cpp.

◆ RtTrackGlobal2Local()

void RtTrackGlobal2Local ( tTrackSeg * segment,
tdble X,
tdble Y,
tTrkLocPos * p,
int type )

Convert global coordinates to a local track position.

Searches previous/next main segments starting at segment. Use a nearby main segment: this is a longitudinal search, not a global nearest-road query. toStart is in meters on straights and radians on curves; lateral distances are in meters. Positions outside the road are not clamped to its edges.

Parameters
[in]segmentMain segment from which to start the search.
[in]XGlobal X coordinate in meters.
[in]YGlobal Y coordinate in meters.
[out]pNon-NULL destination for segment, type and local coordinates.
[in]typeTR_LPOS_MAIN for main-road coordinates; TR_LPOS_SEGMENT to resolve borders/sides and rebase lateral coordinates; TR_LPOS_TRACK to extend toRight/toLeft to the outer edges including sides (seg and toMiddle remain relative to the main road).

Definition at line 298 of file rttrack.cpp.

Here is the call graph for this function:

◆ RtTrackGlobal2LocalD()

void RtTrackGlobal2LocalD ( tTrackSeg * segment,
double X,
double Y,
tTrkLocPos * p,
int type )

Convert global coordinates to a local track position using double intermediates.

Searches previous/next main segments starting at segment. Use a nearby main segment: this is a longitudinal search, not a global nearest-road query. toStart is in meters on straights and radians on curves; lateral distances are in meters. Positions outside the road are not clamped to its edges.

Parameters
[in]segmentMain segment from which to start the search.
[in]XGlobal X coordinate in meters.
[in]YGlobal Y coordinate in meters.
[out]pNon-NULL destination for segment, type and local coordinates.
[in]typeTR_LPOS_MAIN for main-road coordinates; TR_LPOS_SEGMENT to resolve borders/sides and rebase lateral coordinates; TR_LPOS_TRACK to extend toRight/toLeft to the outer edges including sides (seg and toMiddle remain relative to the main road).
Note
X and Y retain double precision during the calculation; the resulting tTrkLocPos fields still use tdble.

Definition at line 276 of file rttrack.cpp.

Here is the call graph for this function:

◆ RtTrackHeightG()

tdble RtTrackHeightG ( tTrackSeg * seg,
tdble X,
tdble Y )

Returns the absolute height in meters of the road at the Global position (segment, X, Y)

Parameters
[in]segSegment
[in]XGlobal X position
[in]YGlobal Y position
Returns
Height in meters

Definition at line 465 of file rttrack.cpp.

Here is the call graph for this function:

◆ RtTrackHeightL()

tdble RtTrackHeightL ( tTrkLocPos * p)

Returns the absolute height in meters of the road at the Local position p.

The effective side segment is resolved and the lateral coordinate is rebased relative to that segment before calculating its height. If the point lies outside the track (and sides) the height is computed using the tangent to the banking of the segment (or side).

             + Point given
            .^
           . |
          .  |
         .   |
        /    | height
       /     |
______/      v
^    ^^  ^
|    ||  |
track side
Parameters
[in]pLocal position; valid segment and surface data are required.
Returns
Height in meters, including surface roughness and curb height where applicable. This is the track/side surface, not surrounding terrain.

Definition at line 365 of file rttrack.cpp.

Here is the call graph for this function:

◆ RtTrackLocal2Global()

void RtTrackLocal2Global ( tTrkLocPos * p,
tdble * X,
tdble * Y,
int flag )

Calculate global coordinates from a local position relative to the given track segment (segment, toRight, toStart)The toStart position refers to the current segment, the function will not search for next segment if toStart is greater than the segment length.

toStart represent an angle in radian for curves and a length in meters for straights.

Parameters
[in]pLocal position
[out]XGlobal X position in meters; non-NULL output pointer.
[out]YGlobal Y position in meters; non-NULL output pointer.
[in]flagLocal position use:
  • TR_TOMIDDLE the toMiddle field is used (+ to left, - to right), relative to the middle of segment
  • TR_TORIGHT the toRight field is used (+ to left, - to right), relative to the right side of segment
  • TR_TOLEFT the toLeft field is used (- to left, + to right), relative to left side of segment

Definition at line 81 of file rttrack.cpp.

Here is the call graph for this function:

◆ RtTrackSideNormalG()

void RtTrackSideNormalG ( tTrackSeg * seg,
tdble X,
tdble Y,
int side,
t3Dd * norm )

Compute the horizontal inward border normal using the supplied segment.

The side parameter is used to indicate the right (TR_RGT) of the left (TR_LFT) side to consider. The Global position given (segment, X, Y) is used to project the point on the border, it is not necessary to give a point directly on the border itself. The horizontal components are normalized; the z component is not written.

Parameters
[in]segCurrent segment
[in]XGlobal X position
[in]YGlobal Y position
[in]sideSide where the normal is wanted
  • TR_LFT for left side
  • TR_RGT for right side
[in,out]normNon-NULL vector: x/y receive the horizontal normal pointing into the track; z is left unchanged. Initialize z to zero before calling if a horizontal 3D vector is required.
Note
Uses the supplied segment without searching its neighbours or sides. For curves, the point must differ from the curve center.

Definition at line 495 of file rttrack.cpp.

◆ RtTrackSideTgAngleL()

tdble RtTrackSideTgAngleL ( tTrkLocPos * p)

Used to get the tangent angle for a track position The angle is given in radian.

Zero points along the global positive X axis; the result is not normalized.

Parameters
[in]pLocal position
Returns
Tangent heading in radians, from the segment's start heading and signed curve angle. Width taper is not included.

Definition at line 539 of file rttrack.cpp.

◆ RtTrackSurfaceNormalL()

void RtTrackSurfaceNormalL ( tTrkLocPos * p,
t3Dd * norm )

Used to get the normal vector of the road (pointing upward).

Local coordinates are used to locate the point where to get the road normal vector. Uses a cross product of sampled segment chords, not an exact pointwise derivative. The result is normalized unless the sampled geometry is degenerate, in which case the zero vector is returned.

Parameters
[in]pLocal position
[out]normNon-NULL destination for the road normal.

Definition at line 567 of file rttrack.cpp.

Here is the call graph for this function: