![]() |
torcs - 1.2.2 | ![]() |
00001 /*************************************************************************** 00002 00003 file : robottools.h 00004 created : Mon Feb 28 22:31:13 CET 2000 00005 copyright : (C) 2000 by Eric Espie 00006 email : torcs@free.fr 00007 version : $Id: robottools.h,v 1.6 2003/11/23 20:21:11 torcs Exp $ 00008 00009 ***************************************************************************/ 00010 00011 /*************************************************************************** 00012 * * 00013 * This program is free software; you can redistribute it and/or modify * 00014 * it under the terms of the GNU General Public License as published by * 00015 * the Free Software Foundation; either version 2 of the License, or * 00016 * (at your option) any later version. * 00017 * * 00018 ***************************************************************************/ 00019 00026 #ifndef _ROBOTTOOLS_H_ 00027 #define _ROBOTTOOLS_H_ 00028 00029 #include <car.h> 00030 #include <track.h> 00031 00032 #define RELAXATION2(target, prev, rate) \ 00033 do { \ 00034 tdble __tmp__; \ 00035 __tmp__ = target; \ 00036 target = (prev) + (rate) * ((target) - (prev)) * 0.01; \ 00037 prev = __tmp__; \ 00038 } while (0) 00039 00040 #define RELAXATION(target, prev, rate) \ 00041 do { \ 00042 target = (prev) + (rate) * ((target) - (prev)) * 0.01; \ 00043 prev = (target); \ 00044 } while (0) 00045 00046 /* 00047 * Track Utilities 00048 */ 00049 00050 /* for variable width segments */ 00051 extern tdble RtTrackGetWidth(tTrackSeg *seg, tdble toStart); 00052 00053 /* 00054 * Convert a Local position (segment, toRight, toStart) 00055 * into a Global one (X, Y) 00056 * 00057 * The ToStart position refers to the current segment, 00058 * the function will not search for next segment if toStart 00059 * is greater than the segment length. 00060 * toStart represent an angle in radian for curves 00061 * and a length in meters for straights. 00062 * 00063 */ 00064 extern void RtTrackLocal2Global(tTrkLocPos *p, tdble *X, tdble *Y, int flag); 00065 00066 /* 00067 * Convert a Global (segment, X, Y) position into a Local one (segment, toRight, toStart) 00068 * 00069 * The segment in the Global position is used to start the search of a good segment 00070 * in term of toStart value. 00071 * The segments are scanned in order to find a toStart value between 0 and the length 00072 * of the segment for straights or the arc of the curve. 00073 * 00074 * The sides parameters is to indicate wether to use the track sides (1) or not (0) in 00075 * the toRight computation. 00076 */ 00077 extern void RtTrackGlobal2Local(tTrackSeg *segment, tdble X, tdble Y, tTrkLocPos *p, int type); 00078 00079 00080 /* 00081 * Returns the absolute height in meters of the road 00082 * at the Local position p. 00083 * 00084 * If the point lies outside the track (and sides) 00085 * the height is computed using the tangent to the banking 00086 * of the segment (or side). 00087 00088 + Point given 00089 .^ 00090 . | 00091 . | 00092 . | 00093 / | heigth 00094 / | 00095 ______/ v 00096 ^ ^^ ^ 00097 | || | 00098 track side 00099 00100 */ 00101 extern tdble RtTrackHeightL(tTrkLocPos *p); 00102 00103 00104 /* 00105 * Returns the absolute height in meters of the road 00106 * at the Global position (segment, X, Y) 00107 */ 00108 extern tdble RtTrackHeightG(tTrackSeg *seg, tdble X, tdble Y); 00109 00110 00111 /* 00112 * Give the normal vector of the border of the track 00113 * including the sides. 00114 * 00115 * The side parameter is used to indicate the right (TR_RGT) 00116 * of the left (TR_LFT) side to consider. 00117 * 00118 * The Global position given (segment, X, Y) is used 00119 * to project the point on the border, it is not necessary 00120 * to give a point directly on the border itself. 00121 * 00122 * The vector is normalized. 00123 */ 00124 extern void RtTrackSideNormalG(tTrackSeg *seg, tdble X, tdble Y, int side, t3Dd *norm); 00125 00126 00127 /* 00128 * Used to get the tangent angle for a track position 00129 * The angle is given in radian. 00130 * 00131 * the angle 0 is parallel to the first segment start. 00132 */ 00133 extern tdble RtTrackSideTgAngleL(tTrkLocPos *p); 00134 00135 00136 /* 00137 * Used to get the normal vector of the road itself (pointing 00138 * upward). 00139 * 00140 * Local coordinates are used to locate the point where to 00141 * get the road normal vector. 00142 * 00143 * The vector is normalized. 00144 */ 00145 extern void RtTrackSurfaceNormalL(tTrkLocPos *p, t3Dd *norm); 00146 00147 extern int RtDistToPit(struct CarElt *car, tTrack *track, tdble *dL, tdble *dW); 00148 00149 extern tdble RtGetDistFromStart(tCarElt *car); 00150 extern tdble RtGetDistFromStart2(tTrkLocPos *p); 00151 00152 /**************** 00153 * Telemetry * 00154 ****************/ 00155 00161 extern void RtTelemInit(tdble ymin, tdble ymax); 00162 00165 tTrackSeg *RtTrackGetSeg(tTrkLocPos *p); 00166 00167 00168 00176 extern void RtTelemNewChannel(const char * name, tdble * var, tdble min, tdble max); 00177 extern void RtTelemStartMonitoring(const char * filename); 00178 extern void RtTelemStopMonitoring(void); 00179 extern void RtTelemUpdate(double time); 00180 extern void RtTelemShutdown(void); 00181 00182 #endif /* _ROBOTTOOLS_H_ */ 00183 00184 00185