torcs - 1.2.2

src/modules/graphic/ssggraph/grcam.h

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003     file                 : grcam.h
00004     created              : Mon Aug 21 20:55:02 CEST 2000
00005     copyright            : (C) 2000 by Eric Espie
00006     email                : torcs@free.fr
00007     version              : $Id: grcam.h,v 1.18 2004/01/15 18:16:54 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 
00020 #ifndef _GRCAM_H_
00021 #define _GRCAM_H_
00022 
00023 #include <track.h>
00024 #include <car.h>
00025 #include <raceman.h>
00026 #ifdef WIN32
00027 #include <float.h>
00028 #endif
00029 
00030 class cGrCamera;
00031 class cGrScreen;
00032 
00033 GF_TAILQ_HEAD(GrCamHead, cGrCamera);
00034 
00035 /* Camera interface */
00036 class cGrCamera 
00037 {
00038  private:
00039     GF_TAILQ_ENTRY(cGrCamera) link;
00040     int                 id;             /* Camera Id */
00041     int                 drawCurrent;    /* flag to draw the current car */
00042     int                 drawDriver;     /* flag to draw the driver */
00043     int                 drawBackground; /* flag to draw the background */
00044     int                 mirrorAllowed;  /* flag to allox the display of mirror */
00045 
00046  protected:
00047     sgVec3 speed;
00048     sgVec3 eye;
00049     sgVec3 center;
00050     sgVec3 up;
00051     class cGrScreen     *screen;        /* screen where the camera is attached */
00052     
00053  public:
00054     cGrCamera(class cGrScreen *myscreen, int myid = 0, int mydrawCurrent = 0, int mydrawdrv = 0, int mydrawBackground = 0, int mymirrorAllowed = 0) {
00055         screen = myscreen;
00056         id = myid;
00057         drawCurrent = mydrawCurrent;
00058         drawDriver = mydrawdrv;
00059         drawBackground = mydrawBackground;
00060         mirrorAllowed = mymirrorAllowed;
00061     }
00062 
00063     virtual ~cGrCamera() {};
00064     
00065     virtual void update(tCarElt *car, tSituation *s) = 0;       /* Change the camera if necessary */
00066     virtual void setProjection(void) = 0;
00067     virtual void setModelView(void) = 0;
00068     virtual void setZoom(int cmd) = 0;                          /* Set the zoom with commands */
00069     virtual void loadDefaults(char *attr) = 0;                  /* Load the default values from parameter file */
00070     virtual void onSelect(tCarElt *car, tSituation *s) = 0;     /* called when the camera is selected */
00071 
00072     virtual float getLODFactor(float x, float y, float z) = 0;  /* Get the LOD factor for an object located at x,y,z */
00073 
00074     /* Set the camera view */
00075     void action(void) {
00076         setProjection();
00077         setModelView();
00078     }
00079     
00080     /* Get the camera info */
00081     int getId(void)             { return id; }
00082     int getDrawCurrent(void)    { return drawCurrent; }
00083     int getDrawDriver(void)     { return drawDriver; }
00084     int getDrawBackground(void) { return drawBackground; }
00085     int isMirrorAllowed(void)   { return mirrorAllowed; }
00086 
00087     t3Dd *getPos(void) {
00088         static t3Dd pos;
00089         pos.x = eye[0];
00090         pos.y = eye[1];
00091         pos.z = eye[2];
00092         return &pos;
00093     }
00094     sgVec3 *getPosv(void) {
00095         return &eye;
00096     }
00097     sgVec3 *getSpeedv(void) {
00098         return &speed;
00099     }
00100     t3Dd *getCenter(void) {
00101         static t3Dd pos;
00102         pos.x = center[0];
00103         pos.y = center[1];
00104         pos.z = center[2];
00105         return &pos;
00106     }
00107     sgVec3 *getCenterv(void) {
00108         return &center;
00109     }
00110     t3Dd *getUp(void) {
00111         static t3Dd pos;
00112         pos.x = up[0];
00113 
00114         pos.y = up[1];
00115         pos.z = up[2];
00116         return &pos;
00117     }
00118     sgVec3 *getUpv(void) {
00119         return &up;
00120     }
00121     
00122     /* Add the camera in the corresponding list */
00123     void add(tGrCamHead *head) {
00124         GF_TAILQ_INSERT_TAIL(head, this, link);
00125     }
00126     
00127     /* Remove the camera from the corresponding list */
00128     void remove(tGrCamHead *head) {
00129         GF_TAILQ_REMOVE(head, this, link);
00130     }
00131 
00132     /* Get the squared distance between the car and the camera */
00133     float getDist2(tCarElt *car);
00134 
00135     cGrCamera *next(void) {
00136         return GF_TAILQ_NEXT(this, link);
00137     }
00138 };
00139 
00140 
00141 class cGrPerspCamera : public cGrCamera
00142 {
00143  protected:
00144     float fovy;
00145     float fovymin;
00146     float fovymax;
00147     float fovydflt;
00148     float fnear;
00149     float ffar;
00150     float fogstart;
00151     float fogend;
00152     
00153  public:
00154     cGrPerspCamera(class cGrScreen *myscreen, int id, int drawCurr, int drawDrv, int drawBG, int mirrorAllowed,
00155                    float myfovy, float myfovymin, float myfovymax,
00156                    float myfnear, float myffar = 1500.0, float myfogstart = 1400.0, float myfogend = 1500.0);
00157     
00158     virtual void update(tCarElt *car, tSituation *s) = 0;       /* Change the camera if necessary */
00159     void setProjection(void);
00160     void setModelView(void);
00161     void loadDefaults(char *attr);
00162     void setZoom(int cmd);
00163     float getLODFactor(float x, float y, float z);
00164     float getFogStart(void) { return fogstart; }
00165     float getFogEnd(void) { return fogend; }
00166 
00167     cGrPerspCamera *next(void) {
00168         return (cGrPerspCamera *)cGrCamera::next();
00169     }
00170 
00171    void limitFov(void)  {}
00172    void onSelect(tCarElt *car, tSituation *s) {}
00173 
00174 };
00175 
00176 
00177 
00178 class cGrOrthoCamera : public cGrCamera
00179 {
00180  protected:
00181     float left;
00182     float right;
00183     float bottom;
00184     float top;
00185 
00186  public:
00187     cGrOrthoCamera(class cGrScreen *myscreen, float myleft, float myright, float mybottom, float mytop)
00188         : cGrCamera(myscreen) {
00189         left   = myleft;
00190         right  = myright;
00191         bottom = mybottom;
00192         top    = mytop;
00193     }
00194 
00195     void setProjection(void);
00196     void setModelView(void);
00197 
00198     void update(tCarElt *car, tSituation *s) { }
00199     float getLODFactor(float x, float y, float z) { return 1; }
00200     void loadDefaults(char *attr) { }
00201     void setZoom(int cmd) { }
00202     void onSelect(tCarElt *car, tSituation *s) {}
00203 };
00204 
00205 class cGrBackgroundCam : public cGrPerspCamera
00206 {
00207  public:
00208     cGrBackgroundCam(class cGrScreen *myscreen)
00209         : cGrPerspCamera(myscreen, 0, 0, 0, 1, 0,
00210                          67.5, 67.5, 67.5,
00211                          0.1, 2000.0, 100000, 100000) {
00212     }
00213     
00214     void update(tCarElt *car, tSituation *s) {}
00215 
00216     void update(cGrCamera *curCam);
00217     void limitFov(void) { }
00218 };
00219 
00220 class cGrCarCamMirror : public cGrPerspCamera
00221 {
00222  protected:
00223     int         vpx, vpy, vpw, vph;     /* viewport size */
00224     int         mx, my, mw, mh;         /* drawing area */
00225     float       tsu, tsv, teu, tev;     /* texture coord */
00226     GLuint      tex;                    /* texture */
00227     cGrOrthoCamera *viewCam;
00228     
00229  public:
00230     cGrCarCamMirror(cGrScreen *myscreen, int id, int drawCurr, int drawBG,
00231                     float myfovy, float myfovymin, float myfovymax,
00232                     float myfnear, float myffar = 1500.0,
00233                     float myfogstart = 1400.0, float myfogend = 1500.0)
00234         : cGrPerspCamera(myscreen, id, drawCurr, 1, drawBG, 1,
00235                          myfovy, myfovymin, myfovymax,
00236                          myfnear, myffar, myfogstart, myfogend) {
00237         glGenTextures (1, &tex);
00238         limitFov();
00239         viewCam = NULL;
00240     }
00241     ~cGrCarCamMirror ();
00242 
00243     void update (tCarElt *car, tSituation *s);
00244     void limitFov (void);
00245 
00246     void setViewport (int x, int y, int w, int h);
00247     void setPos (int x, int y, int w, int h);
00248     void activateViewport (void);
00249     void store (void);
00250     void display (void);
00251 };
00252 
00253 
00254 #define GR_ZOOM_IN      0
00255 #define GR_ZOOM_OUT     1
00256 #define GR_ZOOM_MAX     2
00257 #define GR_ZOOM_MIN     3
00258 #define GR_ZOOM_DFLT    4
00259 
00260 void grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fovFactor);
00261 
00262 #endif /* _GRCAM_H_ */ 
00263 
00264 
00265 

Generated at Thu Feb 26 21:52:29 2004 for torcs by doxygen 1.3.3 written by Dimitri van Heesch, © 1997-1999
TORCS © Eric Espié 1999, 2002.