1 | #ifndef _TestCullingTerrainApplication_H__
|
---|
2 | #define _TestCullingTerrainApplication_H__
|
---|
3 |
|
---|
4 | #include "CEGUIForwardRefs.h"
|
---|
5 | #include <OgreRenderTargetListener.h>
|
---|
6 | #include "ExampleApplication.h"
|
---|
7 |
|
---|
8 | #include "OgreTerrainContentGenerator.h"
|
---|
9 | #include "TerrainFrameListener.h"
|
---|
10 |
|
---|
11 | #include <OgreEntity.h>
|
---|
12 | #include <string>
|
---|
13 |
|
---|
14 | // z order index of visualizaion viewport
|
---|
15 | #define VIZ_VIEWPORT_Z_ORDER 10
|
---|
16 |
|
---|
17 | class IVReader;
|
---|
18 |
|
---|
19 | //-- constants for animation
|
---|
20 | const float walk_duration = 10.0f;
|
---|
21 | const float wait_duration = 2.0f;
|
---|
22 | const float rotate_factor = 0.7f;
|
---|
23 | const float move_factor = 0.03;
|
---|
24 |
|
---|
25 |
|
---|
26 | /** Rendertarget listener which shows a visualization.
|
---|
27 | */
|
---|
28 | class VisualizationRenderTargetListener: public RenderTargetListener
|
---|
29 | {
|
---|
30 | public:
|
---|
31 | VisualizationRenderTargetListener(SceneManager *sceneMgr);
|
---|
32 |
|
---|
33 | protected:
|
---|
34 | void preViewportUpdate (const RenderTargetViewportEvent &evt);
|
---|
35 | void postRenderTargetUpdate (const RenderTargetEvent &evt);
|
---|
36 |
|
---|
37 | SceneManager *mSceneMgr;
|
---|
38 |
|
---|
39 | ShadowTechnique mSavedShadowTechnique;
|
---|
40 | ColourValue mSavedAmbientLight;
|
---|
41 | };
|
---|
42 |
|
---|
43 | /** Class storing the current state of an entity.
|
---|
44 | */
|
---|
45 | class EntityState
|
---|
46 | {
|
---|
47 | public:
|
---|
48 | enum State {STOP, WAITING, MOVING};
|
---|
49 |
|
---|
50 | EntityState(Entity *ent, State entityState, Real speed);
|
---|
51 | ~EntityState();
|
---|
52 | /** Update the entity state.
|
---|
53 | */
|
---|
54 | void update(Real timeSinceLastFrame);
|
---|
55 |
|
---|
56 | /** Returns entity.
|
---|
57 | */
|
---|
58 | Entity *GetEntity();
|
---|
59 |
|
---|
60 | /** Returns entity state index.
|
---|
61 | */
|
---|
62 | EntityState::State GetState();
|
---|
63 |
|
---|
64 | static bool OutOfBounds(SceneNode *node);
|
---|
65 |
|
---|
66 | static Vector3 msMinPos;
|
---|
67 | static Vector3 msMaxPos;
|
---|
68 |
|
---|
69 | protected:
|
---|
70 |
|
---|
71 | void SetAnimationState(String stateStr, bool loop);
|
---|
72 |
|
---|
73 | AnimationState *mAnimationState;
|
---|
74 | Entity *mEntity;
|
---|
75 |
|
---|
76 | State mState;
|
---|
77 | Real mAnimationSpeed;
|
---|
78 | Real mTimeElapsed;
|
---|
79 | };
|
---|
80 |
|
---|
81 | typedef std::vector<EntityState *> EntityStates;
|
---|
82 |
|
---|
83 | class TestCullingTerrainApplication: public ExampleApplication
|
---|
84 | {
|
---|
85 | public:
|
---|
86 | TestCullingTerrainApplication();
|
---|
87 | ~TestCullingTerrainApplication();
|
---|
88 |
|
---|
89 | /** Generates a scene using num entities of a type.
|
---|
90 | @param num the number of objects
|
---|
91 | @parma objectType the type of objects
|
---|
92 | */
|
---|
93 | void generateScene(int num, int objectType);
|
---|
94 |
|
---|
95 | /** Returns the caption of the given id of a scene object type.
|
---|
96 | */
|
---|
97 | String getCurrentObjectCaption(int id);
|
---|
98 |
|
---|
99 | /** Returns state vector of scene entities.
|
---|
100 | */
|
---|
101 | EntityStates &getEntityStates();
|
---|
102 |
|
---|
103 | /** Updates all animations according to time elapsed since last frame.
|
---|
104 | */
|
---|
105 | void updateAnimations(Real timeSinceLastFrame);
|
---|
106 |
|
---|
107 | /** Deletes vector of scene entity states.
|
---|
108 | */
|
---|
109 | void deleteEntityStates();
|
---|
110 |
|
---|
111 | // object types
|
---|
112 | enum {ROBOT, TREE, NINJA};
|
---|
113 |
|
---|
114 |
|
---|
115 | /** Clamps scene node to terrain.
|
---|
116 | @param sceneNode the node to be clamped
|
---|
117 | @param terrainOffs the offset of the node over the terrain
|
---|
118 | @returns if clamping was successful (i.e., the ray hit the terrain)
|
---|
119 | */
|
---|
120 | bool Clamp2Terrain(SceneNode *node, int terrainOffs);
|
---|
121 |
|
---|
122 | /** Clamps camera to floor plane: used for vienna set.
|
---|
123 | */
|
---|
124 | bool Clamp2FloorPlane();
|
---|
125 |
|
---|
126 | /** Loads iv geometry.
|
---|
127 | */
|
---|
128 | bool LoadSceneIV(const String &filename, SceneNode *root, const int index);
|
---|
129 |
|
---|
130 | bool LoadSceneCollada(const String &filename, SceneNode *root, const int index);
|
---|
131 |
|
---|
132 | bool LoadScene(const String &filename);
|
---|
133 |
|
---|
134 | bool LoadViewCells(const String &filename);
|
---|
135 |
|
---|
136 | /** Loads configuration from disc.
|
---|
137 | */
|
---|
138 | void loadConfig(const String& filename);
|
---|
139 |
|
---|
140 |
|
---|
141 | /// if hilly terrain should be loaded
|
---|
142 | static bool msShowHillyTerrain;
|
---|
143 |
|
---|
144 | String mFilename;
|
---|
145 | String mViewCellsFilename;
|
---|
146 | /// name of the visibility environment file
|
---|
147 | String mEnvironmentFilename;
|
---|
148 |
|
---|
149 | int mAlgorithm;
|
---|
150 |
|
---|
151 |
|
---|
152 | protected:
|
---|
153 |
|
---|
154 | //-- inherited from ExampleApplication
|
---|
155 | bool setup();
|
---|
156 | void createScene();
|
---|
157 | void createFrameListener();
|
---|
158 | void createCamera();
|
---|
159 | //void createViewports();
|
---|
160 |
|
---|
161 | virtual void createRenderTargetListener();
|
---|
162 |
|
---|
163 | void BakeSceneIntoStaticGeometry(const String &staticGeomName,
|
---|
164 | const String &nodeName);
|
---|
165 |
|
---|
166 | std::vector<EntityState *> mEntityStates;
|
---|
167 |
|
---|
168 | /** cegui setup
|
---|
169 | */
|
---|
170 | void setupGui();
|
---|
171 |
|
---|
172 | CEGUI::OgreCEGUIRenderer *mGUIRenderer;
|
---|
173 | CEGUI::System *mGUISystem;
|
---|
174 |
|
---|
175 | Vector3 mMinTranslation;
|
---|
176 | Vector3 mMaxTranslation;
|
---|
177 |
|
---|
178 | Vector3 mMinAngle;
|
---|
179 | Vector3 mMaxAngle;
|
---|
180 |
|
---|
181 | TerrainContentGenerator *mTerrainContentGenerator;
|
---|
182 |
|
---|
183 | Camera *mVizCamera;
|
---|
184 | SceneNode *mCamNode;
|
---|
185 | Light *mSunLight;
|
---|
186 |
|
---|
187 | TerrainFrameListener *mTerrainFrameListener;
|
---|
188 | ColourValue mAmbientLight;
|
---|
189 | RayQueryExecutor *mRayQueryExecutor;
|
---|
190 |
|
---|
191 | Vector3 mTerrainMinPos;
|
---|
192 | Vector3 mTerrainMaxPos;
|
---|
193 |
|
---|
194 | IVReader *mIVReader;
|
---|
195 |
|
---|
196 | StaticGeometry *mStaticGeometry;
|
---|
197 |
|
---|
198 |
|
---|
199 | private:
|
---|
200 | void chooseSceneManager(void);
|
---|
201 | };
|
---|
202 |
|
---|
203 | #endif // TestCullingTerrainApplication |
---|