source: GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h @ 1609

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