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

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