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

Revision 113, 5.2 KB checked in by mattausch, 19 years ago (diff)

fixed problems with visualization

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
93        void nextAlgorithm();
94        void changeThreshold(int incr);
95        void updateStats();
96
97        void toggleUseOptimization();
98        void toggleShowOctree();
99        void toggleUseVisibilityCulling();
100        void toggleShowViz();
101        void nextNodeVizMode();
102        void toggleRecord();
103
104        void zoomVizCamera(int zoom);
105       
106        void addFrameInfo(SceneNode *camNode, Real timeElapsed);
107        void setCurrentFrameInfo(Real timeElapsed);
108
109        void setAppState(int state);
110        void nextAppState();
111
112        void setAlgorithm(int algorithm);
113
114        void moveCamera();
115       
116        void writeFrames();
117        void loadFrames();
118
119        void toggleUseShadows();
120
121protected:
122        void Clamp2Terrain();
123       
124    bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
125    SceneManager *mSceneMgr;           // A pointer to the scene manager
126   
127        CEGUI::Renderer *mGUIRenderer;     // cegui renderer
128       
129        bool mShutdownRequested;
130        int mCurrentAlgorithm;
131        int mVisibilityThreshold;
132       
133        OverlayElement *mAlgorithmInfo;
134        OverlayElement *mThresholdInfo;
135        OverlayElement *mFrustumCulledNodesInfo;
136        OverlayElement *mQueryCulledNodesInfo;
137    OverlayElement *mTraversedNodesInfo;
138        OverlayElement *mHierarchyNodesInfo;
139        OverlayElement *mUseOptimizationInfo;
140        OverlayElement *mRenderedNodesInfo;
141        OverlayElement *mObjectsInfo;
142        OverlayElement *mQueriesIssuedInfo;
143
144        SceneNode *mCurrentObject;    // the newly created object
145        int mObjectCount;             // The number of objects on the screen
146
147        RayQueryExecutor *mRayQueryExecutor;
148        TerrainContentGenerator *mTerrainContentGenerator;
149
150        bool mUseOptimization;
151        bool mShowOctree;
152        bool mUseVisibilityCulling;
153        bool mShowVisualization;
154        int mNodeVizMode;
155        bool mCullCamera;
156
157        Real mVizCameraHeight;
158
159        Camera *mVizCamera;
160        SceneNode *mCamNode;
161       
162        //std::deque<Vector3> mWalkList;   // The list of points we are walking to
163        std::vector<frame_info> mFrameInfo;
164               
165        int mCurrentFrame;
166        // the current application state
167        int mAppState;
168        bool mRecord;
169        Real mTimeElapsed;
170        bool mUseShadows;
171
172        bool mVisualizeCulledNodes;
173};
174
175
176class TestCullingTerrainApplication : public ExampleApplication
177{
178public:
179        ~TestCullingTerrainApplication();
180
181protected:
182        //-- inherited from ExampleApplication
183        bool setup();
184        void createScene();
185        void createFrameListener();
186        void createCamera();
187        //void createViewports();
188       
189        virtual void createRenderTargetListener();
190
191        /** cegui setup */
192        void setupGui();
193
194        CEGUI::OgreCEGUIRenderer *mGUIRenderer;
195        CEGUI::System *mGUISystem;
196
197        Vector3 mMinTranslation;
198        Vector3 mMaxTranslation;
199
200        Vector3 mMinAngle;
201        Vector3 mMaxAngle;
202
203        TerrainContentGenerator *mTerrainContentGenerator;
204       
205        Camera *mVizCamera;
206        SceneNode *mCamNode;
207        Light *mSunLight;
208        VisualizationRenderTargetListener *mRenderTargetListener;
209
210private:
211        void chooseSceneManager(void);
212};
Note: See TracBrowser for help on using the repository browser.