Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

TeEngine.h

Go to the documentation of this file.
00001 //##################################################
00002 //# $Id: TeEngine.h 21 2005-04-20 07:40:35Z peciva $
00003 
00004 #ifndef TE_ENGINE_H
00005 #define TE_ENGINE_H
00006 
00007 /*****************************************************************************\
00008  *
00009  * TeEngine.h
00010  *
00011  * TeEngine - terrain engine class
00012  *
00013  * Authors: Martin Havlíček (xhavli15 AT stud.fit.vutbr.cz)
00014  *          PCJohn (peciva AT fit.vutbr.cz)
00015  * Contributors: 
00016  *
00017  * ----------------------------------------------------------------------------
00018  *
00019  * THIS SOFTWARE IS NOT COPYRIGHTED
00020  *
00021  * This source code is offered for use in the public domain.
00022  * You may use, modify or distribute it freely.
00023  *
00024  * This source code is distributed in the hope that it will be useful but
00025  * WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
00026  * DISCLAIMED.  This includes but is not limited to warranties of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00028  *
00029  * If you find the source code useful, authors will kindly welcome
00030  * if you give them credit and keep their names with their source code.
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   // instances of all usable generators, corresponds with GenMethod and
00134   // FilterMethod enums above
00136   public:  TeFaultFormation faultFormation;
00137   private:
00139   TeLinearFilter linearFilter;
00140 
00142   TeGenerator *generator;
00143 
00144   // currently selected generators (these will be used for next task)
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   // patch status queries
00176   SbBool isReady(SbVec2f patchPos);
00177   SbBool isScheduled(SbVec2f patchPos);
00178 
00179   // patch generation scheduling
00180   void schedule(SbVec2f patchPos);
00181   void done();
00182   void prepareNeighbours(SbVec2f patchPos);
00183 
00184   // update scene graph to match object needs
00185   void updateGraph(TeObject *obj);
00186 
00187   // additional useful routines
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   // data for explorer
00200   float fps;
00202   unsigned int tasksInQueue;
00204   unsigned int patchesNum;
00205 
00206   // default sizes
00207   const SbVec2s& getHMapResolution() const;
00208   SbVec2s getBuildMapResolution() const;
00209   const SbVec2f& getPatch0Size() const;
00210 
00211   // generators selecting
00212   GenMethod getCurrGen();
00213   void setCurrGen(GenMethod m);
00214   FilterMethod getCurrFilter();
00215   void setCurrFilter(FilterMethod m);
00216 
00217   // objects stuff
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   // scene
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   // HUD
00232   void setHUDRoot(SoSeparator *sep);
00233   SoSeparator* getHUDRoot();
00234 
00235   // cameras stuff
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   // generate heightmap
00249   TeHeightMap* generateHMap(const SbVec2s &res);
00250 
00251   // Fault-Formation generator calls
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   // init function
00259   void initialize();
00260 
00261   // time-tick function (called by timer in application that uses TeEngine)
00262   void timeTick(const SbTime delta);
00263 
00264   // generator tick function, called when scheduled task is waiting
00265   // in taskQueue
00266   // TRUE means "task is done, get result and start new one"
00267   SbBool genTick();
00268 
00270   void onRootDestroy()  { root = NULL; }
00271 };
00272 
00273 
00274 #endif /* TE_ENGINE_H */

Generated on Sun May 8 16:45:06 2005 for TerrainEngine by Doxygen 1.4.1