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 |
|
---|
13 | // z order index of visualizaion viewport
|
---|
14 | #define VIZ_VIEWPORT_Z_ORDER 10
|
---|
15 |
|
---|
16 |
|
---|
17 | //-- constants for animation
|
---|
18 | const float walk_duration = 10.0f;
|
---|
19 | const float wait_duration = 2.0f;
|
---|
20 | const float rotate_factor = 0.7f;
|
---|
21 | const float move_factor = 0.03;
|
---|
22 |
|
---|
23 |
|
---|
24 | /** Rendertarget listener which shows a visualization.
|
---|
25 | */
|
---|
26 | class VisualizationRenderTargetListener: public RenderTargetListener
|
---|
27 | {
|
---|
28 | public:
|
---|
29 | VisualizationRenderTargetListener(SceneManager *sceneMgr);
|
---|
30 |
|
---|
31 | protected:
|
---|
32 | void preViewportUpdate (const RenderTargetViewportEvent &evt);
|
---|
33 | void postRenderTargetUpdate (const RenderTargetEvent &evt);
|
---|
34 |
|
---|
35 | SceneManager *mSceneMgr;
|
---|
36 |
|
---|
37 | ShadowTechnique mSavedShadowTechnique;
|
---|
38 | ColourValue mSavedAmbientLight;
|
---|
39 | };
|
---|
40 |
|
---|
41 | /** Class storing the current state of an entity.
|
---|
42 | */
|
---|
43 | class EntityState
|
---|
44 | {
|
---|
45 | public:
|
---|
46 | enum State {STOP, WAITING, MOVING};
|
---|
47 |
|
---|
48 | EntityState(Entity *ent, State entityState, Real speed);
|
---|
49 | ~EntityState();
|
---|
50 | /** Update the entity state.
|
---|
51 | */
|
---|
52 | void update(Real timeSinceLastFrame);
|
---|
53 |
|
---|
54 | /** Returns entity.
|
---|
55 | */
|
---|
56 | Entity *GetEntity();
|
---|
57 |
|
---|
58 | /** Returns entity state index.
|
---|
59 | */
|
---|
60 | EntityState::State GetState();
|
---|
61 |
|
---|
62 | static bool OutOfBounds(SceneNode *node);
|
---|
63 |
|
---|
64 | static Vector3 msMinPos;
|
---|
65 | static Vector3 msMaxPos;
|
---|
66 |
|
---|
67 | protected:
|
---|
68 |
|
---|
69 | void SetAnimationState(String stateStr, bool loop);
|
---|
70 |
|
---|
71 | AnimationState *mAnimationState;
|
---|
72 | Entity *mEntity;
|
---|
73 |
|
---|
74 | State mState;
|
---|
75 | Real mAnimationSpeed;
|
---|
76 | Real mTimeElapsed;
|
---|
77 | };
|
---|
78 |
|
---|
79 | typedef std::vector<EntityState *> EntityStates;
|
---|
80 |
|
---|
81 | class TestCullingTerrainApplication: public ExampleApplication
|
---|
82 | {
|
---|
83 | public:
|
---|
84 | TestCullingTerrainApplication();
|
---|
85 | ~TestCullingTerrainApplication();
|
---|
86 |
|
---|
87 | /** Generates a scene using num entities of a type.
|
---|
88 | @param num the number of objects
|
---|
89 | @parma objectType the type of objects
|
---|
90 | */
|
---|
91 | void generateScene(int num, int objectType);
|
---|
92 |
|
---|
93 | /** Returns the caption of the given id of a scene object type.
|
---|
94 | */
|
---|
95 | String getCurrentObjectCaption(int id);
|
---|
96 |
|
---|
97 | /** Returns state vector of scene entities.
|
---|
98 | */
|
---|
99 | EntityStates &getEntityStates();
|
---|
100 |
|
---|
101 | /** Updates all animations according to time elapsed since last frame.
|
---|
102 | */
|
---|
103 | void updateAnimations(Real timeSinceLastFrame);
|
---|
104 |
|
---|
105 | /** Deletes vector of scene entity states.
|
---|
106 | */
|
---|
107 | void deleteEntityStates();
|
---|
108 |
|
---|
109 | // object types
|
---|
110 | enum {ROBOT, ATHENA, NINJA};
|
---|
111 |
|
---|
112 |
|
---|
113 | /** Clamps scene node to terrain.
|
---|
114 | @param sceneNode the node to be clamped
|
---|
115 | @param terrainOffs the offset of the node over the terrain
|
---|
116 | @returns if clamping was successful (i.e., the ray hit the terrain)
|
---|
117 | */
|
---|
118 | bool Clamp2Terrain(SceneNode *node, int terrainOffs);
|
---|
119 |
|
---|
120 | protected:
|
---|
121 |
|
---|
122 | //-- inherited from ExampleApplication
|
---|
123 | bool setup();
|
---|
124 | void createScene();
|
---|
125 | void createFrameListener();
|
---|
126 | void createCamera();
|
---|
127 | //void createViewports();
|
---|
128 |
|
---|
129 | virtual void createRenderTargetListener();
|
---|
130 |
|
---|
131 | std::vector<EntityState *> mEntityStates;
|
---|
132 |
|
---|
133 | /** cegui setup
|
---|
134 | */
|
---|
135 | void setupGui();
|
---|
136 |
|
---|
137 | CEGUI::OgreCEGUIRenderer *mGUIRenderer;
|
---|
138 | CEGUI::System *mGUISystem;
|
---|
139 |
|
---|
140 | Vector3 mMinTranslation;
|
---|
141 | Vector3 mMaxTranslation;
|
---|
142 |
|
---|
143 | Vector3 mMinAngle;
|
---|
144 | Vector3 mMaxAngle;
|
---|
145 |
|
---|
146 | TerrainContentGenerator *mTerrainContentGenerator;
|
---|
147 |
|
---|
148 | Camera *mVizCamera;
|
---|
149 | SceneNode *mCamNode;
|
---|
150 | Light *mSunLight;
|
---|
151 |
|
---|
152 | TerrainFrameListener *mTerrainFrameListener;
|
---|
153 | ColourValue mAmbientLight;
|
---|
154 | RayQueryExecutor *mRayQueryExecutor;
|
---|
155 |
|
---|
156 | Vector3 mTerrainMinPos;
|
---|
157 | Vector3 mTerrainMaxPos;
|
---|
158 |
|
---|
159 | private:
|
---|
160 | void chooseSceneManager(void);
|
---|
161 | };
|
---|
162 |
|
---|
163 | #endif // TestCullingTerrainApplication |
---|