TORCS  1.3.9
The Open Racing Car Simulator
grcam.h
Go to the documentation of this file.
1 /***************************************************************************
2 
3  file : grcam.h
4  created : Mon Aug 21 20:55:02 CEST 2000
5  copyright : (C) 2000 by Eric Espie
6  email : torcs@free.fr
7  version : $Id$
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #ifndef _GRCAM_H_
21 #define _GRCAM_H_
22 
23 #include <track.h>
24 #include <car.h>
25 #include <raceman.h>
26 #ifdef WIN32
27 #include <float.h>
28 #endif
29 
30 class cGrCamera;
31 class cGrScreen;
32 
33 GF_TAILQ_HEAD(GrCamHead, cGrCamera);
34 
35 /* Camera interface */
36 class cGrCamera
37 {
38  private:
40  int id; /* Camera Id */
41  int drawCurrent; /* flag to draw the current car */
42  int drawDriver; /* flag to draw the driver */
43  int drawBackground; /* flag to draw the background */
44  int mirrorAllowed; /* flag to allox the display of mirror */
45 
46  protected:
47  sgVec3 speed;
48  sgVec3 eye;
49  sgVec3 center;
50  sgVec3 up;
51  class cGrScreen *screen; /* screen where the camera is attached */
52 
53  public:
54  cGrCamera(class cGrScreen *myscreen, int myid = 0, int mydrawCurrent = 0, int mydrawdrv = 0, int mydrawBackground = 0, int mymirrorAllowed = 0) {
55  screen = myscreen;
56  id = myid;
57  drawCurrent = mydrawCurrent;
58  drawDriver = mydrawdrv;
59  drawBackground = mydrawBackground;
60  mirrorAllowed = mymirrorAllowed;
61  speed[0] = speed[1] = speed[2] = 0.0;
62  eye[0] = eye[1] = eye[2] = 0.0;
63  center[0] = center[1] = center[2] = 0.0;
64  up[0] = up[1] = 0.0; up[2] = 1.0;
65  }
66 
67  virtual ~cGrCamera() {};
68 
69  virtual void update(tCarElt *car, tSituation *s) = 0; /* Change the camera if necessary */
70  virtual void setProjection(void) = 0;
71  virtual void setModelView(void) = 0;
72  virtual void setZoom(int cmd) = 0; /* Set the zoom with commands */
73  virtual void loadDefaults(char *attr) = 0; /* Load the default values from parameter file */
74  virtual void onSelect(tCarElt *car, tSituation *s) = 0; /* called when the camera is selected */
75 
76  virtual float getLODFactor(float x, float y, float z) = 0; /* Get the LOD factor for an object located at x,y,z */
77 
78  /* Set the camera view */
79  void action(void) {
80  setProjection();
81  setModelView();
82  }
83 
84  /* Get the camera info */
85  int getId(void) { return id; }
86  int getDrawCurrent(void) { return drawCurrent; }
87  int getDrawDriver(void) { return drawDriver; }
88  int getDrawBackground(void) { return drawBackground; }
89  int isMirrorAllowed(void) { return mirrorAllowed; }
90 
91  t3Dd *getPos(void) {
92  static t3Dd pos;
93  pos.x = eye[0];
94  pos.y = eye[1];
95  pos.z = eye[2];
96  return &pos;
97  }
98  sgVec3 *getPosv(void) {
99  return &eye;
100  }
101  sgVec3 *getSpeedv(void) {
102  return &speed;
103  }
104  t3Dd *getCenter(void) {
105  static t3Dd pos;
106  pos.x = center[0];
107  pos.y = center[1];
108  pos.z = center[2];
109  return &pos;
110  }
111  sgVec3 *getCenterv(void) {
112  return &center;
113  }
114  t3Dd *getUp(void) {
115  static t3Dd pos;
116  pos.x = up[0];
117 
118  pos.y = up[1];
119  pos.z = up[2];
120  return &pos;
121  }
122  sgVec3 *getUpv(void) {
123  return &up;
124  }
125 
126  virtual float getFovY(void) {
127  return 67.5; // override in perspective camera
128  }
129 
130  /* Add the camera in the corresponding list */
131  void add(tGrCamHead *head) {
132  GF_TAILQ_INSERT_TAIL(head, this, link);
133  }
134 
135  /* Remove the camera from the corresponding list */
136  void remove(tGrCamHead *head) {
137  GF_TAILQ_REMOVE(head, this, link);
138  }
139 
140  /* Get the squared distance between the car and the camera */
141  float getDist2(tCarElt *car);
142 
143  cGrCamera *next(void) {
144  return GF_TAILQ_NEXT(this, link);
145  }
146 };
147 
148 
149 class cGrPerspCamera : public cGrCamera
150 {
151  protected:
152  float fovy;
153  float fovymin;
154  float fovymax;
155  float fovydflt;
156  float fnear;
157  float ffar;
158  float fogstart;
159  float fogend;
160 
161  public:
162  cGrPerspCamera(class cGrScreen *myscreen, int id, int drawCurr, int drawDrv, int drawBG, int mirrorAllowed,
163  float myfovy, float myfovymin, float myfovymax,
164  float myfnear, float myffar = 1500.0, float myfogstart = 1400.0, float myfogend = 1500.0);
165 
166  virtual void update(tCarElt *car, tSituation *s) = 0; /* Change the camera if necessary */
167  void setProjection(void);
168  void setModelView(void);
169  void loadDefaults(char *attr);
170  void setZoom(int cmd);
171  float getLODFactor(float x, float y, float z);
172  float getFogStart(void) { return fogstart; }
173  float getFogEnd(void) { return fogend; }
174 
176  return (cGrPerspCamera *)cGrCamera::next();
177  }
178 
179  void limitFov(void) {}
180  void onSelect(tCarElt *car, tSituation *s) {}
181 
182  virtual float getFovY(void) {
183  return fovy;
184  }
185 
186 };
187 
188 
189 
190 class cGrOrthoCamera : public cGrCamera
191 {
192  protected:
193  float left;
194  float right;
195  float bottom;
196  float top;
197 
198  public:
199  cGrOrthoCamera(class cGrScreen *myscreen, float myleft, float myright, float mybottom, float mytop)
200  : cGrCamera(myscreen) {
201  left = myleft;
202  right = myright;
203  bottom = mybottom;
204  top = mytop;
205  }
206 
207  void setProjection(void);
208  void setModelView(void);
209 
210  void update(tCarElt *car, tSituation *s) { }
211  float getLODFactor(float x, float y, float z) { return 1; }
212  void loadDefaults(char *attr) { }
213  void setZoom(int cmd) { }
214  void onSelect(tCarElt *car, tSituation *s) {}
215 };
216 
218 {
219  public:
220  cGrBackgroundCam(class cGrScreen *myscreen)
221  : cGrPerspCamera(myscreen, 0, 0, 0, 1, 0,
222  67.5f, 67.5f, 67.5f,
223  0.1f, 2000.0f, 100000.0f, 100000.0f) {
224  }
225 
226  void update(tCarElt *car, tSituation *s) {}
227 
228  void update(cGrCamera *curCam);
229  void limitFov(void) { }
230 };
231 
233 {
234  protected:
235  int vpx, vpy, vpw, vph; /* viewport size */
236  int tw, th; /* texture size */
237  int mx, my, mw, mh; /* drawing area */
238  float tsu, tsv, teu, tev; /* texture coord */
239  GLuint tex; /* texture */
241 
242  public:
243  cGrCarCamMirror(cGrScreen *myscreen, int id, int drawCurr, int drawBG,
244  float myfovy, float myfovymin, float myfovymax,
245  float myfnear, float myffar = 1500.0,
246  float myfogstart = 1400.0, float myfogend = 1500.0)
247  : cGrPerspCamera(myscreen, id, drawCurr, 1, drawBG, 1,
248  myfovy, myfovymin, myfovymax,
249  myfnear, myffar, myfogstart, myfogend) {
250  glGenTextures (1, &tex);
251  limitFov();
252  viewCam = NULL;
253  }
254  virtual ~cGrCarCamMirror ();
255 
256  void update (tCarElt *car, tSituation *s);
257  void limitFov (void);
258 
259  void setViewport (int x, int y, int w, int h);
260  void setPos (int x, int y, int w, int h);
261  void activateViewport (void);
262  void store (void);
263  void display (void);
264 };
265 
266 
267 #define GR_ZOOM_IN 0
268 #define GR_ZOOM_OUT 1
269 #define GR_ZOOM_MAX 2
270 #define GR_ZOOM_MIN 3
271 #define GR_ZOOM_DFLT 4
272 
273 void grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fovFactor);
274 
275 #endif /* _GRCAM_H_ */
276 
277 
278 
cGrCarCamMirror(cGrScreen *myscreen, int id, int drawCurr, int drawBG, float myfovy, float myfovymin, float myfovymax, float myfnear, float myffar=1500.0, float myfogstart=1400.0, float myfogend=1500.0)
Definition: grcam.h:243
float tsu
Definition: grcam.h:238
float right
Definition: grcam.h:194
int getDrawCurrent(void)
Definition: grcam.h:86
float getLODFactor(float x, float y, float z)
Definition: grcam.cpp:144
int getDrawBackground(void)
Definition: grcam.h:88
int getId(void)
Definition: grcam.h:85
virtual void setModelView(void)=0
void setProjection(void)
Definition: grcam.cpp:110
void limitFov(void)
Definition: grcam.h:229
float fovy
Definition: grcam.h:152
cars situation used to inform the GUI and the drivers
Definition: raceman.h:85
float fogstart
Definition: grcam.h:158
void setModelView(void)
Definition: grcam.cpp:221
class cGrScreen * screen
Definition: grcam.h:51
#define GF_TAILQ_INSERT_TAIL(head, elm, field)
Insert an element at the tail.
Definition: tgf.h:511
virtual void loadDefaults(char *attr)=0
sgVec3 * getSpeedv(void)
Definition: grcam.h:101
float bottom
Definition: grcam.h:195
Car structure (tCarElt).
Definition: car.h:455
float tev
Definition: grcam.h:238
void activateViewport(void)
Definition: grcam.cpp:381
sgVec3 eye
Definition: grcam.h:48
virtual ~cGrCarCamMirror()
Definition: grcam.cpp:290
sgVec3 speed
Definition: grcam.h:47
float tsv
Definition: grcam.h:238
virtual float getFovY(void)
Definition: grcam.h:126
void setProjection(void)
Definition: grcam.cpp:214
float fovymin
Definition: grcam.h:153
int mirrorAllowed
Definition: grcam.h:44
int drawDriver
Definition: grcam.h:42
float fovydflt
Definition: grcam.h:155
float ffar
Definition: grcam.h:157
void loadDefaults(char *attr)
Definition: grcam.h:212
virtual void update(tCarElt *car, tSituation *s)=0
GLuint tex
Definition: grcam.h:239
void update(tCarElt *car, tSituation *s)
Definition: grcam.h:226
void add(tGrCamHead *head)
Definition: grcam.h:131
cGrPerspCamera * next(void)
Definition: grcam.h:175
float tdble
Floating point type used in TORCS.
Definition: tgf.h:48
virtual ~cGrCamera()
Definition: grcam.h:67
void update(tCarElt *car, tSituation *s)
Definition: grcam.cpp:302
void setViewport(int x, int y, int w, int h)
Definition: grcam.cpp:330
int isMirrorAllowed(void)
Definition: grcam.h:89
GF_TAILQ_HEAD(GrCamHead, cGrCamera)
void store(void)
Definition: grcam.cpp:390
float getFogStart(void)
Definition: grcam.h:172
cGrPerspCamera(class cGrScreen *myscreen, int id, int drawCurr, int drawDrv, int drawBG, int mirrorAllowed, float myfovy, float myfovymin, float myfovymax, float myfnear, float myffar=1500.0, float myfogstart=1400.0, float myfogend=1500.0)
Definition: grcam.cpp:94
void grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fovFactor)
Definition: grcam.cpp:1292
void setZoom(int cmd)
Definition: grcam.cpp:166
virtual void setZoom(int cmd)=0
tdble y
y coordinate
Definition: tgf.h:117
cGrOrthoCamera * viewCam
Definition: grcam.h:240
virtual void setProjection(void)=0
float left
Definition: grcam.h:193
tdble z
z coordinate
Definition: tgf.h:118
int id
Definition: grcam.h:40
This is the car structure.
void setZoom(int cmd)
Definition: grcam.h:213
This is the race information structures.
void onSelect(tCarElt *car, tSituation *s)
Definition: grcam.h:214
void limitFov(void)
Definition: grcam.cpp:297
void update(tCarElt *car, tSituation *s)
Definition: grcam.h:210
sgVec3 center
Definition: grcam.h:49
int drawBackground
Definition: grcam.h:43
void onSelect(tCarElt *car, tSituation *s)
Definition: grcam.h:180
cGrBackgroundCam(class cGrScreen *myscreen)
Definition: grcam.h:220
t3Dd * getCenter(void)
Definition: grcam.h:104
int drawCurrent
Definition: grcam.h:41
sgVec3 * getPosv(void)
Definition: grcam.h:98
#define GF_TAILQ_REMOVE(head, elm, field)
Remove an element.
Definition: tgf.h:541
void action(void)
Definition: grcam.h:79
static Vector y[4]
Definition: Convex.cpp:56
void limitFov(void)
Definition: grcam.h:179
int getDrawDriver(void)
Definition: grcam.h:87
float fnear
Definition: grcam.h:156
float top
Definition: grcam.h:196
void setPos(int x, int y, int w, int h)
Definition: grcam.cpp:345
float getFogEnd(void)
Definition: grcam.h:173
#define GF_TAILQ_NEXT(elm, field)
Next element of a TAILQ.
Definition: tgf.h:467
t3Dd * getPos(void)
Definition: grcam.h:91
float fovymax
Definition: grcam.h:154
virtual void onSelect(tCarElt *car, tSituation *s)=0
cGrOrthoCamera(class cGrScreen *myscreen, float myleft, float myright, float mybottom, float mytop)
Definition: grcam.h:199
float teu
Definition: grcam.h:238
sgVec3 up
Definition: grcam.h:50
3D point.
Definition: tgf.h:115
void display(void)
Definition: grcam.cpp:404
void loadDefaults(char *attr)
Definition: grcam.cpp:132
cGrCamera(class cGrScreen *myscreen, int myid=0, int mydrawCurrent=0, int mydrawdrv=0, int mydrawBackground=0, int mymirrorAllowed=0)
Definition: grcam.h:54
virtual float getLODFactor(float x, float y, float z)=0
sgVec3 * getUpv(void)
Definition: grcam.h:122
GF_TAILQ_ENTRY(cGrCamera) link
virtual float getFovY(void)
Definition: grcam.h:182
virtual void update(tCarElt *car, tSituation *s)=0
float getDist2(tCarElt *car)
Definition: grcam.cpp:46
Track Structure and Track Loader Module Definition.
void setModelView(void)
Definition: grcam.cpp:124
cGrCamera * next(void)
Definition: grcam.h:143
tdble x
x coordinate
Definition: tgf.h:116
float getLODFactor(float x, float y, float z)
Definition: grcam.h:211
t3Dd * getUp(void)
Definition: grcam.h:114
sgVec3 * getCenterv(void)
Definition: grcam.h:111
float fogend
Definition: grcam.h:159