00001
00002
00003
00004 #ifndef TE_ENGINE_H
00005 #define TE_ENGINE_H
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00042 #include <Inventor/lists/SbList.h>
00043 #include <Inventor/SbTime.h>
00044 #include <Inventor/SbBSPTree.h>
00045
00046 #include "generators/TeGenerator.h"
00047 #include "generators/TeFaultFormation.h"
00048 #include "generators/TeLinearFilter.h"
00049 #include "objects/TeObject.h"
00050 #include "TeHeightMap.h"
00051 #include "TePatch.h"
00052
00053 class SoNode;
00054 class SoSeparator;
00055 class SoPerspectiveCamera;
00056
00082 class TeEngine {
00083
00084 public:
00085
00087 enum GenMethod { FAULT_FORMATION = 0
00088 };
00089
00091 enum FilterMethod { NONE = 0,
00092 LINEAR = 1
00093 };
00094
00095 private:
00096
00098 struct TeETask {
00100 enum TeETaskStatus { BM0 = 0,
00101 BM0G = 1,
00102 BM0F = 2,
00103 BM1 = 3,
00104 BM1G = 4,
00105 BM1F = 5,
00106 BM2 = 6,
00107 BM2G = 7,
00108 BM2F = 8,
00109 BM3 = 9,
00110 BM3G = 10,
00111 BM3F = 11,
00112 HM = 13,
00113 GRAPH = 14,
00114 SEAMS = 15
00115 };
00116 TePatch *p;
00117 SbVec2f patchPos;
00118 TeETaskStatus status;
00119 GenMethod gm;
00120 FilterMethod fm;
00121 };
00122
00124 TePatch *root;
00126 int rootLevel;
00127
00129 SbVec2s hmapResolution;
00131 SbVec2f patch0Size;
00132
00133
00134
00136 public: TeFaultFormation faultFormation;
00137 private:
00139 TeLinearFilter linearFilter;
00140
00142 TeGenerator *generator;
00143
00144
00146 GenMethod currGen;
00148 FilterMethod currFilter;
00149
00151 SbList<TeETask> taskQueue;
00152
00154 SbList<TeObject *> objectList;
00155
00157 TeObject *activeObject;
00158
00160 SoSeparator *sceneRoot;
00162 SoPerspectiveCamera *sceneCamera;
00163
00165 SoSeparator *HUDRoot;
00167 SoPerspectiveCamera *HUDCamera;
00168
00170 SbBSPTree patchReadyTree;
00171
00173 SbBSPTree patchScheduledTree;
00174
00175
00176 SbBool isReady(SbVec2f patchPos);
00177 SbBool isScheduled(SbVec2f patchPos);
00178
00179
00180 void schedule(SbVec2f patchPos);
00181 void done();
00182 void prepareNeighbours(SbVec2f patchPos);
00183
00184
00185 void updateGraph(TeObject *obj);
00186
00187
00188 SbVec2f computePatchPosUnderPoint(SbVec3f pt);
00189 SbVec2f computeNeighbourPos(SbVec2f patchPos, TePatch::Direction which);
00190 TePatch::Direction computePosInsidePatch(SbVec2f patchPos, SbVec3f pt);
00191
00192 public:
00193
00194 TeEngine(SbVec2s hmapResolution = SbVec2s(65,65),
00195 SbVec2f patch0Size = SbVec2f(64.f,64.f));
00196 ~TeEngine();
00197
00198
00200 float fps;
00202 unsigned int tasksInQueue;
00204 unsigned int patchesNum;
00205
00206
00207 const SbVec2s& getHMapResolution() const;
00208 SbVec2s getBuildMapResolution() const;
00209 const SbVec2f& getPatch0Size() const;
00210
00211
00212 GenMethod getCurrGen();
00213 void setCurrGen(GenMethod m);
00214 FilterMethod getCurrFilter();
00215 void setCurrFilter(FilterMethod m);
00216
00217
00218 void addObject(TeObject *obj);
00219 TeObject *getObject(int idx);
00220 void removeObject(TeObject *obj);
00221 void setActiveObject(TeObject *obj);
00222 TeObject *getActiveObject();
00223
00224
00225 void setSceneRoot(SoSeparator *sep);
00226 SoSeparator* getSceneRoot();
00227 void addNode(SoNode *node);
00228 void removeNode(SoNode *node);
00229 void removePatch(TePatch *p);
00230
00231
00232 void setHUDRoot(SoSeparator *sep);
00233 SoSeparator* getHUDRoot();
00234
00235
00236 void setSceneCamera(SoPerspectiveCamera *c);
00237 SoPerspectiveCamera *getSceneCamera();
00238 void setHUDCamera(SoPerspectiveCamera *c);
00239 SoPerspectiveCamera *getHUDCamera();
00240
00241 TePatch* getPatch(const SbVec2f &pos, const int level = 0,
00242 TePatch::PatchMissedPolicy policy = TePatch::CREATE);
00243
00244 TePatch* getRootPatch();
00245 int getRootLevel() const;
00246 void advanceRootToPos(const SbVec2f &pos);
00247
00248
00249 TeHeightMap* generateHMap(const SbVec2s &res);
00250
00251
00252 TeHeightMap* generateHMapFF();
00253 TeHeightMap* generateHMapFF(const SbVec2s &res);
00254 TeHeightMap* generateHMapFF(const SbVec2s &res,
00255 const unsigned int seed, const int num_faults,
00256 const float min_delta, const float max_delta);
00257
00258
00259 void initialize();
00260
00261
00262 void timeTick(const SbTime delta);
00263
00264
00265
00266
00267 SbBool genTick();
00268
00270 void onRootDestroy() { root = NULL; }
00271 };
00272
00273
00274 #endif