source: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h @ 114

Revision 114, 5.3 KB checked in by mattausch, 19 years ago (diff)
Line 
1/**
2    \file
3        TestCullingTerrainApplication.h
4*/
5#include "CEGUIForwardRefs.h"
6#include "ExampleApplication.h"
7#include "OgreTerrainContentGenerator.h"
8#include "VisibilityEnvironment.h"
9#include <OgreRenderTargetListener.h>
10#include <vector>
11
12Real timeDelay = 0;
13#define KEY_PRESSED(_key,_timeDelay, _macro) \
14{ \
15    if (mInputDevice->isKeyDown(_key) && timeDelay <= 0) \
16{ \
17    timeDelay = _timeDelay; \
18    _macro ; \
19} \
20}
21
22String mCurrentAlgorithmCaptions[GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS] =
23{
24    "View Frustum Culling",
25        "Stop and Wait Culling",
26        "Coherent Hierarchical Culling"
27};
28
29/** The information about camera position and orienation per frame */
30typedef struct
31{
32        Vector3 position;
33        Quaternion orientation;
34        Real timeElapsed;
35} frame_info;
36
37
38class VisualizationRenderTargetListener: public RenderTargetListener
39{
40public:
41        VisualizationRenderTargetListener(SceneManager *sceneMgr);
42
43protected:
44        void preViewportUpdate (const RenderTargetViewportEvent &evt);
45        void postRenderTargetUpdate (const RenderTargetEvent &evt);
46
47        SceneManager *mSceneMgr;
48};
49
50class MouseQueryListener : public ExampleFrameListener, public MouseListener, public MouseMotionListener
51{
52public:
53       
54    MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager,
55                CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera,
56                SceneNode *camNode);
57
58    ~MouseQueryListener();
59
60        bool frameStarted(const FrameEvent& evt);
61        bool frameEnded(const FrameEvent& evt);
62        bool processUnbufferedKeyInput(const FrameEvent& evt);
63   
64
65    /* MouseListener callbacks. */
66    virtual void mouseClicked(MouseEvent* e) { }
67    virtual void mouseEntered(MouseEvent* e) { }
68    virtual void mouseExited(MouseEvent* e)  { }
69
70    // This is when the mouse button goes DOWN.
71    virtual void mousePressed(MouseEvent* e);
72
73    // This is when the mouse button is let UP.
74    virtual void mouseReleased(MouseEvent* e);
75
76    /* MouseMotionListener callbacks */
77    virtual void mouseMoved (MouseEvent *e);
78   
79    // This is when the mouse is clicked, held and dragged.
80    virtual void mouseDragged (MouseEvent *e);
81
82    void keyPressed(KeyEvent* e);
83
84        void keyReleased(KeyEvent* e);
85        void keyClicked(KeyEvent* e);
86
87        enum  {WALKTHROUGH, REPLAY, STATE_NUM};
88
89        // visualization modes for scene nodes
90        //enum {NODEVIZ_NONE, NODEVIZ_RENDER_NODES,
91        //        NODEVIZ_RENDER_NODES_AND_CONTENT, NODEVIZ_MODES_NUM};
92        enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM};
93
94        void nextAlgorithm();
95        void changeThreshold(int incr);
96        void updateStats();
97
98        void toggleUseOptimization();
99        void toggleShowOctree();
100        void toggleUseVisibilityCulling();
101        void toggleShowViz();
102        void nextNodeVizMode();
103        void toggleRecord();
104
105        void zoomVizCamera(int zoom);
106       
107        void addFrameInfo(SceneNode *camNode, Real timeElapsed);
108        void setCurrentFrameInfo(Real timeElapsed);
109
110        void setAppState(int state);
111        void nextAppState();
112
113        void setAlgorithm(int algorithm);
114
115        void moveCamera();
116       
117        void writeFrames();
118        void loadFrames();
119
120        void toggleUseShadows();
121
122protected:
123        void Clamp2Terrain();
124       
125    bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
126    SceneManager *mSceneMgr;           // A pointer to the scene manager
127   
128        CEGUI::Renderer *mGUIRenderer;     // cegui renderer
129       
130        bool mShutdownRequested;
131        int mCurrentAlgorithm;
132        int mVisibilityThreshold;
133       
134        OverlayElement *mAlgorithmInfo;
135        OverlayElement *mThresholdInfo;
136        OverlayElement *mFrustumCulledNodesInfo;
137        OverlayElement *mQueryCulledNodesInfo;
138    OverlayElement *mTraversedNodesInfo;
139        OverlayElement *mHierarchyNodesInfo;
140        OverlayElement *mUseOptimizationInfo;
141        OverlayElement *mRenderedNodesInfo;
142        OverlayElement *mObjectsInfo;
143        OverlayElement *mQueriesIssuedInfo;
144
145        SceneNode *mCurrentObject;    // the newly created object
146        int mObjectCount;             // The number of objects on the screen
147
148        RayQueryExecutor *mRayQueryExecutor;
149        TerrainContentGenerator *mTerrainContentGenerator;
150
151        bool mUseOptimization;
152        bool mShowOctree;
153        bool mUseVisibilityCulling;
154        bool mShowVisualization;
155        int mNodeVizMode;
156        bool mCullCamera;
157
158        Real mVizCameraHeight;
159
160        Camera *mVizCamera;
161        SceneNode *mCamNode;
162       
163        //std::deque<Vector3> mWalkList;   // The list of points we are walking to
164        std::vector<frame_info> mFrameInfo;
165               
166        int mCurrentFrame;
167        // the current application state
168        int mAppState;
169        bool mRecord;
170        Real mTimeElapsed;
171        bool mUseShadows;
172
173        bool mVisualizeCulledNodes;
174};
175
176
177class TestCullingTerrainApplication : public ExampleApplication
178{
179public:
180        ~TestCullingTerrainApplication();
181
182protected:
183        //-- inherited from ExampleApplication
184        bool setup();
185        void createScene();
186        void createFrameListener();
187        void createCamera();
188        //void createViewports();
189       
190        virtual void createRenderTargetListener();
191
192        /** cegui setup */
193        void setupGui();
194
195        CEGUI::OgreCEGUIRenderer *mGUIRenderer;
196        CEGUI::System *mGUISystem;
197
198        Vector3 mMinTranslation;
199        Vector3 mMaxTranslation;
200
201        Vector3 mMinAngle;
202        Vector3 mMaxAngle;
203
204        TerrainContentGenerator *mTerrainContentGenerator;
205       
206        Camera *mVizCamera;
207        SceneNode *mCamNode;
208        Light *mSunLight;
209        VisualizationRenderTargetListener *mRenderTargetListener;
210
211private:
212        void chooseSceneManager(void);
213};
Note: See TracBrowser for help on using the repository browser.