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

Revision 107, 5.0 KB checked in by mattausch, 19 years ago (diff)

added frame interpolation

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
115protected:
116        void Clamp2Terrain();
117       
118    bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
119    SceneManager *mSceneMgr;           // A pointer to the scene manager
120   
121        CEGUI::Renderer *mGUIRenderer;     // cegui renderer
122       
123        bool mShutdownRequested;
124        int mCurrentAlgorithm;
125        int mVisibilityThreshold;
126       
127        OverlayElement *mAlgorithmInfo;
128        OverlayElement *mThresholdInfo;
129        OverlayElement *mFrustumCulledNodesInfo;
130        OverlayElement *mQueryCulledNodesInfo;
131    OverlayElement *mTraversedNodesInfo;
132        OverlayElement *mHierarchyNodesInfo;
133        OverlayElement *mUseOptimizationInfo;
134        OverlayElement *mRenderedNodesInfo;
135        OverlayElement *mObjectsInfo;
136        OverlayElement *mQueriesIssuedInfo;
137
138        SceneNode *mCurrentObject;    // the newly created object
139        int mObjectCount;             // The number of objects on the screen
140
141        RayQueryExecutor *mRayQueryExecutor;
142        TerrainContentGenerator *mTerrainContentGenerator;
143
144        bool mUseOptimization;
145        bool mShowOctree;
146        bool mUseVisibilityCulling;
147        bool mShowVisualization;
148        bool mRenderNodesForViz;
149        bool mCullCamera;
150
151        Real mVizCameraHeight;
152
153        Camera *mVizCamera;
154        SceneNode *mCamNode;
155       
156        //std::deque<Vector3> mWalkList;   // The list of points we are walking to
157        std::vector<frame_info> mFrameInfo;
158               
159        int mCurrentFrame;
160        // the current application state
161        int mAppState;
162        bool mRecord;
163        Real mTimeElapsed;
164};
165
166
167class TestCullingTerrainApplication : public ExampleApplication
168{
169public:
170        ~TestCullingTerrainApplication();
171
172protected:
173        //-- inherited from ExampleApplication
174        bool setup();
175        void createScene();
176        void createFrameListener();
177        void createCamera();
178        //void createViewports();
179       
180        virtual void createRenderTargetListener();
181
182        /** cegui setup */
183        void setupGui();
184
185        CEGUI::OgreCEGUIRenderer *mGUIRenderer;
186        CEGUI::System *mGUISystem;
187
188        Vector3 mMinTranslation;
189        Vector3 mMaxTranslation;
190
191        Vector3 mMinAngle;
192        Vector3 mMaxAngle;
193
194        TerrainContentGenerator *mTerrainContentGenerator;
195       
196        Camera *mVizCamera;
197        SceneNode *mCamNode;
198        VisualizationRenderTargetListener *mRenderTargetListener;
199
200private:
201        void chooseSceneManager(void);
202};
Note: See TracBrowser for help on using the repository browser.