Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
DynTerrain.h
1 //
2 // DynTerrain class : Dynamically rendering terrain
3 //
4 // Copyright (c) 2001-2007 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef DYNTERRAINH
9 #define DYNTERRAINH
10 
11 #include "vtdata/ElevationGrid.h"
12 #include "vtdata/HeightField.h"
13 
19 
20 // A set of errors that may be returned from the dynamic terrain classes.
21 enum DTErr
22 {
23  DTErr_OK,
24  DTErr_EMPTY_EXTENTS,
25  DTErr_NOTSQUARE,
26  DTErr_NOTPOWER2,
27  DTErr_NOMEM
28 };
29 
37 {
38 public:
40 
41  // Each subclass must implement this initialization method
42  virtual DTErr Init(const vtElevationGrid *pGrid, float fZScale) = 0;
43  virtual void Init2() {}
44  DTErr BasicInit(const vtElevationGrid *pGrid);
45  virtual void SetVerticalExag(float fExag) {}
46  virtual float GetVerticalExag() const = 0;
47 
48  virtual void SetPolygonTarget(int iPolygonCount);
49  int GetPolygonTarget();
50 
52 
53  void SetDetailMaterial(vtMaterial *pApp, float fTiling, float fDistance);
54  void EnableDetail(bool bOn);
55  bool GetDetail() { return m_bDetailTexture; }
56  void SetupTexGen(float fTiling);
57  void DisableTexGen();
58 
59  // overrides for vtDynGeom
60  void DoCalcBoundBox(FBox3 &box);
61  void DoCull(const vtCamera *pCam);
62 
63  // overrides for HeightField
64  bool FindAltitudeOnEarth(const DPoint2 &p, float &fAltitude, bool bTrue = false) const;
65 
66  // overrides for HeightField3d
67  bool FindAltitudeAtPoint(const FPoint3 &p3, float &fAltitude,
68  bool bTrue = false, int iCultureFlags = 0,
69  FPoint3 *vNormal = NULL) const;
70 
71  // overridables
72  virtual void DoCulling(const vtCamera *pCam) = 0;
73  virtual void SetElevation(int i, int j, float fValue, bool bTrue = false) {}
74 
75  // control
76  void SetCull(bool bOnOff);
77  void CullOnce();
78 
79  void PreRender() const;
80  void PostRender() const;
81 
82  // statistics
83  int m_iTotalTriangles;
84  int m_iDrawnTriangles;
85 
86 protected:
87  // tables for quick conversion from x,y index to output X,Z coordinates
88  float *m_fXLookup, *m_fZLookup;
89 
90  // this determines the overall level of detail
91  int m_iPolygonTarget;
92 
93  // flags
94  bool m_bCulleveryframe;
95  bool m_bCullonce;
96 
97  // detail texture
98  float m_fDetailTiling;
99  float m_fDetailDistance;
100  bool m_bDetailTexture;
101  vtMaterial *m_pDetailMat;
102 
103 protected:
104  ~vtDynTerrainGeom();
105 };
106 typedef osg::ref_ptr<vtDynTerrainGeom> vtDynTerrainGeomPtr;
107  // Group dynterr
109 
110 #endif // DYNTERRAINH
111