include/track.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *            track.h
00003  *
00004  *  Sat Nov 19 10:45:47 2005
00005  *  Copyright  2005  Joe Venzon
00006  *  joe@venzon.net
00007  ****************************************************************************/
00008 
00009 /*
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024  
00025 #ifndef _TRACK_H
00026 
00027 #include "bezier.h"
00028 #include "objects.h"
00029 #include "configfile.h"
00030 
00031 #include <sstream>
00032 
00033 using namespace std;
00034 
00035 #include "globals.h"
00036 
00037 #define BEZIER_COLLIDE_FUNCTION CollideSubDivQuadSimpleNorm
00038 
00039 #define LEAVES_PER_BBOX 1
00040 
00041 class BEZIERNODE
00042 {
00043 public:
00044         BEZIER patch;
00045         BEZIERNODE * next;
00046         BEZIERNODE() {next = NULL;}
00047 };
00048 
00049 class BEZIERCOLBRANCH
00050 {
00051 public:
00052         BEZIERCOLBRANCH();
00053         void DeleteChildren();
00054         AABB bbox;
00055         BEZIERCOLBRANCH * left; 
00056         BEZIERCOLBRANCH * right;
00057         list <BEZIERNODE *> leaves;
00058 };
00059 
00060 class ROADSTRIP
00061 {
00062 private:
00063         void ClearPatches();
00064         void GenerateCollisionTree();
00065         BEZIERCOLBRANCH coltree;
00066         void GenerateBranches(BEZIERCOLBRANCH * branch);
00067         BEZIER * lastcolpatch;
00068         
00069 public:
00070         BEZIERNODE * patchnodes;
00071         ROADSTRIP();
00072         ~ROADSTRIP() {coltree.DeleteChildren();ClearPatches();}
00073         BEZIER * Add(BEZIER newpatch);
00074         BEZIER * AddNew();
00075         bool ReadFrom(ifstream &openfile);
00076         bool WriteTo(ofstream &openfile);
00077         bool DeleteLastPatch();
00078         void Visualize (bool wireframe, bool fill, VERTEX color);
00079         BEZIER * GetLastPatch();
00080         BEZIERNODE * GetFirstNode() {return patchnodes;}
00081         int NumPatches();
00082         bool Collide(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest);
00083         bool Collide(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, BEZIER * & colpatch, VERTEX & normal);
00084         bool CollideBruteForce(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, BEZIER * & colpatch);
00085         bool CollideBranch(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, BEZIER * & colpatch, BEZIERCOLBRANCH * branch, VERTEX & normal);
00086 };
00087 
00088 class ROADSTRIPNODE
00089 {
00090 public:
00091         ROADSTRIP road;
00092         ROADSTRIPNODE * next;
00093         ROADSTRIPNODE() {next = NULL;}
00094 };
00095 
00096 class TRACK
00097 {
00098 private:
00099         ROADSTRIPNODE * roads;
00100         int NumRoads();
00101         VERTEX startloc;
00102         double lastelev;
00103         QUATERNION startquat;
00104         bool cullfaces;
00105         vector <BEZIER *> lapsequence;
00106 
00107         float friction1; //the friction coefficient for non-treaded tires
00108         float friction2; //the friction coefficient for treaded tires
00109         
00110         BEZIER * GetBezier(int ridx, int pidx);
00111         
00112 public:
00113         TRACK();
00114         ~TRACK();
00115         ROADSTRIP * AddNewRoad();
00116         void VisualizeRoads(bool wireframe, bool fill, ROADSTRIP * selectedroad);
00117         void ClearRoads();
00118         void Write(string trackname);
00119         void Load(string trackname);
00120         void Delete(ROADSTRIP * striptodel);
00121         double Elevation(VERTEX origin);
00122         double Elevation(VERTEX origin, VERTEX & normal);
00123         double ElevationSeg(VERTEX origin, VERTEX & normal, float seglen);
00124         double ElevationSeg(VERTEX origin, VERTEX & normal, float seglen, BEZIER * &collidepatch, OBJECTNODE * &colnode);
00125         bool Collide(VERTEX origin, VERTEX direction, float seglen, VERTEX &outtri, bool closest, VERTEX & normal, float & dist);
00126         bool CollideD(VERTEXD origin, VERTEXD direction, double seglen, VERTEXD &outtri, bool closest, VERTEXD & normal, double & dist);
00127         bool CollideRoads(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, ROADSTRIP * &collideroad, BEZIER * &collidepatch, VERTEX & normal);
00128         bool CollideModel(VERTEX * modelverts, int numfaces, AABB bbox, VERTEX & outtri, bool closest, VERTEX & normal, float & depth);
00129         void SetStart(VERTEX newloc) {startloc = newloc;}
00130         VERTEX GetStart() {return startloc;}
00131         BEZIER * GetPatch(VERTEX corners[4]);
00132         QUATERNION GetStartOrientation() {return startquat;}
00133         void SetStartOrientation(QUATERNION newquat) {startquat = newquat;}
00134         bool GetCullFaces() {return cullfaces;}
00135         BEZIER * GetLapSequence(int idx);
00136         int NumSectors() {return lapsequence.size();}
00137         void GetFrictionParams(float & f1out, float & f2out) {f1out = friction1;f2out = friction2;}
00138 };
00139 
00140 #define _TRACK_H
00141 #endif /* _TRACK_H */

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6