TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
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
30class cGrCamera;
31class cGrScreen;
32
34
35/* Camera interface */
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;
53 class cGrScreen *screen; /* screen where the camera is attached */
56
57 public:
58 cGrCamera(class cGrScreen *myscreen, int myid = 0, int mydrawCurrent = 0, int mydrawdrv = 0, int mydrawBackground = 0, int mymirrorAllowed = 0) {
59 screen = myscreen;
60 id = myid;
61 drawCurrent = mydrawCurrent;
62 drawDriver = mydrawdrv;
63 drawBackground = mydrawBackground;
64 mirrorAllowed = mymirrorAllowed;
65 speed[0] = speed[1] = speed[2] = 0.0;
66 eye[0] = eye[1] = eye[2] = 0.0;
67 center[0] = center[1] = center[2] = 0.0;
68 up[0] = up[1] = 0.0; up[2] = 1.0;
70 renderOrigin[0] = renderOrigin[1] = renderOrigin[2] = 0.0f;
71 }
72
73 virtual ~cGrCamera() {};
74
75 virtual void update(tCarElt *car, tSituation *s) = 0; /* Change the camera if necessary */
76 virtual void setProjection(void) = 0;
77 virtual void setModelView(void) = 0;
78 virtual void setZoom(int cmd) = 0; /* Set the zoom with commands */
79 virtual void loadDefaults(char *attr) = 0; /* Load the default values from parameter file */
80 virtual void onSelect(tCarElt *car, tSituation *s) = 0; /* called when the camera is selected */
81
82 virtual float getLODFactor(float x, float y, float z) = 0; /* Get the LOD factor for an object located at x,y,z */
83
84 /* Set the camera view */
85 void action(void) {
88 }
89
90 /* Get the camera info */
91 int getId(void) { return id; }
92 int getDrawCurrent(void) { return drawCurrent; }
93 int getDrawDriver(void) { return drawDriver; }
94 int getDrawBackground(void) { return drawBackground; }
95 int isMirrorAllowed(void) { return mirrorAllowed; }
96
97 t3Dd *getPos(void) {
98 static t3Dd pos;
99 pos.x = eye[0] + renderOrigin[0];
100 pos.y = eye[1] + renderOrigin[1];
101 pos.z = eye[2] + renderOrigin[2];
102 return &pos;
103 }
104 sgVec3 *getPosv(void) {
105 return &eye;
106 }
107 sgVec3 *getWorldPosv(void) {
109 return &eye;
110 }
111 static sgVec3 pos;
112 sgAddVec3(pos, eye, renderOrigin);
113 return &pos;
114 }
115 sgVec3 *getSpeedv(void) {
116 return &speed;
117 }
119 static t3Dd pos;
120 pos.x = center[0] + renderOrigin[0];
121 pos.y = center[1] + renderOrigin[1];
122 pos.z = center[2] + renderOrigin[2];
123 return &pos;
124 }
125 sgVec3 *getCenterv(void) {
126 return &center;
127 }
128 t3Dd *getUp(void) {
129 static t3Dd pos;
130 pos.x = up[0];
131
132 pos.y = up[1];
133 pos.z = up[2];
134 return &pos;
135 }
136 sgVec3 *getUpv(void) {
137 return &up;
138 }
139
140 virtual float getFovY(void) {
141 return 67.5; // override in perspective camera
142 }
143
144 /* Add the camera in the corresponding list */
145 void add(tGrCamHead *head) {
146 GF_TAILQ_INSERT_TAIL(head, this, link);
147 }
148
149 /* Remove the camera from the corresponding list */
150 void remove(tGrCamHead *head) {
151 GF_TAILQ_REMOVE(head, this, link);
152 }
153
154 /* Get the squared distance between the car and the camera */
155 float getDist2(tCarElt *car);
156
158 return GF_TAILQ_NEXT(this, link);
159 }
160};
161
162
164{
165 protected:
166 float fovy;
167 float fovymin;
168 float fovymax;
169 float fovydflt;
170 float fnear;
171 float ffar;
172 float fogstart;
173 float fogend;
174
175 public:
176 cGrPerspCamera(class cGrScreen *myscreen, int id, int drawCurr, int drawDrv, int drawBG, int mirrorAllowed,
177 float myfovy, float myfovymin, float myfovymax,
178 float myfnear, float myffar = 1500.0, float myfogstart = 1400.0, float myfogend = 1500.0);
179
180 virtual void update(tCarElt *car, tSituation *s) = 0; /* Change the camera if necessary */
181 void setProjection(void);
182 void setModelView(void);
183 void loadDefaults(char *attr);
184 void setZoom(int cmd);
185 float getLODFactor(float x, float y, float z);
186 float getFogStart(void) { return fogstart; }
187 float getFogEnd(void) { return fogend; }
188
191 }
192
193 void limitFov(void) {}
194 void onSelect(tCarElt *car, tSituation *s) {}
195
196 virtual float getFovY(void) {
197 return fovy;
198 }
199
200};
201
202
203
205{
206 protected:
207 float left;
208 float right;
209 float bottom;
210 float top;
211
212 public:
213 cGrOrthoCamera(class cGrScreen *myscreen, float myleft, float myright, float mybottom, float mytop)
214 : cGrCamera(myscreen) {
215 left = myleft;
216 right = myright;
217 bottom = mybottom;
218 top = mytop;
219 }
220
221 void setProjection(void);
222 void setModelView(void);
223
224 void update(tCarElt *car, tSituation *s) { }
225 float getLODFactor(float x, float y, float z) { return 1; }
226 void loadDefaults(char *attr) { }
227 void setZoom(int cmd) { }
228 void onSelect(tCarElt *car, tSituation *s) {}
229};
230
232{
233 public:
235 : cGrPerspCamera(myscreen, 0, 0, 0, 1, 0,
236 67.5f, 67.5f, 67.5f,
237 0.1f, 2000.0f, 100000.0f, 100000.0f) {
239 }
240
241 void update(tCarElt *car, tSituation *s) {}
242
243 void update(cGrCamera *curCam);
244 void limitFov(void) { }
245};
246
248{
249 protected:
250 int vpx, vpy, vpw, vph; /* viewport size */
251 int tw, th; /* texture size */
252 int mx, my, mw, mh; /* drawing area */
253 float tsu, tsv, teu, tev; /* texture coord */
254 GLuint tex; /* texture */
256
257 public:
258 cGrCarCamMirror(cGrScreen *myscreen, int id, int drawCurr, int drawBG,
259 float myfovy, float myfovymin, float myfovymax,
260 float myfnear, float myffar = 1500.0,
261 float myfogstart = 1400.0, float myfogend = 1500.0)
262 : cGrPerspCamera(myscreen, id, drawCurr, 1, drawBG, 1,
263 myfovy, myfovymin, myfovymax,
264 myfnear, myffar, myfogstart, myfogend) {
265 glGenTextures (1, &tex);
266 limitFov();
267 viewCam = NULL;
268 }
269 virtual ~cGrCarCamMirror ();
270
271 void update (tCarElt *car, tSituation *s);
272 void limitFov (void);
273
274 void setViewport (int x, int y, int w, int h);
275 void setPos (int x, int y, int w, int h);
276 void activateViewport (void);
277 void store (void);
278 void display (void);
279};
280
281
282#define GR_ZOOM_IN 0
283#define GR_ZOOM_OUT 1
284#define GR_ZOOM_MAX 2
285#define GR_ZOOM_MIN 3
286#define GR_ZOOM_DFLT 4
287
288void grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fovFactor);
289
290#endif /* _GRCAM_H_ */
291
292
293
static Vector y[4]
Definition Convex.cpp:56
struct CarElt tCarElt
Car structure (tCarElt).
cGrBackgroundCam(class cGrScreen *myscreen)
Definition grcam.h:234
void limitFov(void)
Definition grcam.h:244
void update(tCarElt *car, tSituation *s)
Definition grcam.h:241
t3Dd * getCenter(void)
Definition grcam.h:118
sgVec3 speed
Definition grcam.h:47
sgVec3 * getUpv(void)
Definition grcam.h:136
void action(void)
Definition grcam.h:85
sgVec3 * getSpeedv(void)
Definition grcam.h:115
virtual void setProjection(void)=0
cGrCamera * next(void)
Definition grcam.h:157
sgVec3 center
Definition grcam.h:49
cGrCamera(class cGrScreen *myscreen, int myid=0, int mydrawCurrent=0, int mydrawdrv=0, int mydrawBackground=0, int mymirrorAllowed=0)
Definition grcam.h:58
int isMirrorAllowed(void)
Definition grcam.h:95
int id
Definition grcam.h:40
t3Dd * getUp(void)
Definition grcam.h:128
virtual float getFovY(void)
Definition grcam.h:140
int getId(void)
Definition grcam.h:91
void remove(tGrCamHead *head)
Definition grcam.h:150
void rebaseLocalRenderCoordinates(void)
Definition grcam.cpp:63
int drawCurrent
Definition grcam.h:41
int renderCoordinatesLocal
Definition grcam.h:51
sgVec3 up
Definition grcam.h:50
virtual void loadDefaults(char *attr)=0
virtual void setZoom(int cmd)=0
sgVec3 * getCenterv(void)
Definition grcam.h:125
void add(tGrCamHead *head)
Definition grcam.h:145
t3Dd * getPos(void)
Definition grcam.h:97
int drawDriver
Definition grcam.h:42
virtual void onSelect(tCarElt *car, tSituation *s)=0
float getDist2(tCarElt *car)
Definition grcam.cpp:45
virtual void setModelView(void)=0
sgVec3 eye
Definition grcam.h:48
sgVec3 * getPosv(void)
Definition grcam.h:104
virtual float getLODFactor(float x, float y, float z)=0
int mirrorAllowed
Definition grcam.h:44
int getDrawBackground(void)
Definition grcam.h:94
sgVec3 renderOrigin
Definition grcam.h:52
GF_TAILQ_ENTRY(cGrCamera) link
int getDrawCurrent(void)
Definition grcam.h:92
void setLocalRenderCoordinates(void)
Definition grcam.cpp:55
class cGrScreen * screen
Definition grcam.h:53
virtual ~cGrCamera()
Definition grcam.h:73
int drawBackground
Definition grcam.h:43
int getDrawDriver(void)
Definition grcam.h:93
virtual void update(tCarElt *car, tSituation *s)=0
sgVec3 * getWorldPosv(void)
Definition grcam.h:107
virtual ~cGrCarCamMirror()
Definition grcam.cpp:334
GLuint tex
Definition grcam.h:254
void activateViewport(void)
Definition grcam.cpp:409
void setViewport(int x, int y, int w, int h)
Definition grcam.cpp:358
cGrOrthoCamera * viewCam
Definition grcam.h:255
void setPos(int x, int y, int w, int h)
Definition grcam.cpp:373
void store(void)
Definition grcam.cpp:418
void limitFov(void)
Definition grcam.cpp:341
void update(tCarElt *car, tSituation *s)
Definition grcam.cpp:346
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:258
void display(void)
Definition grcam.cpp:432
float right
Definition grcam.h:208
void setProjection(void)
Definition grcam.cpp:274
float getLODFactor(float x, float y, float z)
Definition grcam.h:225
void setModelView(void)
Definition grcam.cpp:281
float top
Definition grcam.h:210
void onSelect(tCarElt *car, tSituation *s)
Definition grcam.h:228
void update(tCarElt *car, tSituation *s)
Definition grcam.h:224
cGrOrthoCamera(class cGrScreen *myscreen, float myleft, float myright, float mybottom, float mytop)
Definition grcam.h:213
void setZoom(int cmd)
Definition grcam.h:227
float bottom
Definition grcam.h:209
float left
Definition grcam.h:207
void loadDefaults(char *attr)
Definition grcam.h:226
void onSelect(tCarElt *car, tSituation *s)
Definition grcam.h:194
void setProjection(void)
Definition grcam.cpp:158
float ffar
Definition grcam.h:171
float getFogStart(void)
Definition grcam.h:186
float fogstart
Definition grcam.h:172
void setModelView(void)
Definition grcam.cpp:172
void limitFov(void)
Definition grcam.h:193
float getFogEnd(void)
Definition grcam.h:187
float fovy
Definition grcam.h:166
void loadDefaults(char *attr)
Definition grcam.cpp:187
virtual void update(tCarElt *car, tSituation *s)=0
virtual float getFovY(void)
Definition grcam.h:196
float getLODFactor(float x, float y, float z)
Definition grcam.cpp:199
void setZoom(int cmd)
Definition grcam.cpp:225
float fogend
Definition grcam.h:173
float fovymax
Definition grcam.h:168
float fnear
Definition grcam.h:170
float fovymin
Definition grcam.h:167
float fovydflt
Definition grcam.h:169
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:142
cGrPerspCamera * next(void)
Definition grcam.h:189
void grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fovFactor)
Definition grcam.cpp:1452
float tdble
Floating point type used in TORCS.
Definition tgf.h:47
#define GF_TAILQ_INSERT_TAIL(head, elm, field)
Insert an element at the tail.
Definition tgf.h:510
#define GF_TAILQ_HEAD(name, type)
Head type definition.
Definition tgf.h:447
#define GF_TAILQ_NEXT(elm, field)
Next element of a TAILQ.
Definition tgf.h:466
#define GF_TAILQ_REMOVE(head, elm, field)
Remove an element.
Definition tgf.h:540
struct Situation tSituation
cars situation used to inform the GUI and the drivers
3D point.
Definition tgf.h:114
tdble y
y coordinate
Definition tgf.h:116
tdble z
z coordinate
Definition tgf.h:117
tdble x
x coordinate
Definition tgf.h:115