source: GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h @ 1296

Revision 1296, 8.0 KB checked in by szydlowski, 18 years ago (diff)

Implemented PVS support in kdtree scene manager - not complete, defunct
modified BoundingBoxConverter? to work with KdTreeSceneManager?

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL like the rest of the engine.
12-----------------------------------------------------------------------------
13*/
14/*
15-----------------------------------------------------------------------------
16Filename:    ExampleFrameListener.h
17Description: Defines an example frame listener which responds to frame events.
18This frame listener just moves a specified camera around based on
19keyboard and mouse movements.
20Mouse:    Freelook
21W or Up:  Forward
22S or Down:Backward
23A:        Step left
24D:        Step right
25             PgUp:     Move upwards
26             PgDown:   Move downwards
27             F:        Toggle frame rate stats on/off
28                         R:        Render mode
29             T:        Cycle texture filtering
30                       Bilinear, Trilinear, Anisotropic(8)
31             P:        Toggle on/off display of camera position / orientation
32-----------------------------------------------------------------------------
33*/
34
35#ifndef __KdTreeAppListener_H__
36#define __KdTreeAppListener_H__
37
38#include <Ogre.h>
39#include <OgreKeyEvent.h>
40#include <OgreEventListeners.h>
41#include <OgreStringConverter.h>
42#include <OgreException.h>
43#include <OgreTextAreaOverlayElement.h>
44
45#include <OgreKdTree.h>
46
47#define CONV_OCM_TO_KDT_ALG(i) (i == 0 ? 3 : i)
48#define CONV_KDT_TO_OCM_ALG(i) (i % 3)
49#define VIZ_VIEWPORT_Z_ORDER 10
50
51#define TERRAIN_SCENE "terrain"
52
53using namespace Ogre;
54
55struct FrameInfo
56{
57        FrameInfo(Vector3 pos, Quaternion or, Real time):
58        mPosition(pos), mOrientation(or), mElapsedTime(time)
59        { }
60
61        Vector3 mPosition;
62        Quaternion mOrientation;
63        Real    mElapsedTime;
64};
65
66typedef std::list<FrameInfo> FrameList;
67
68class KdTreeApp;
69
70class KdTreeAppListener: public FrameListener, public KeyListener
71{
72
73public:
74        // visualization modes for scene nodes
75        enum VizMode
76        {
77                NODEVIZ_NONE,
78                NODEVIZ_RENDER_NODES,
79                NODEVIZ_RENDER_NODES_AND_CONTENT,
80                NODEVIZ_MODES_NUM
81        };
82
83        enum SceneType
84        {
85                ST_SIMPLE,
86                ST_TERRAIN,
87                ST_GEOMETRY
88        };
89
90        enum SceneMgr
91        {
92                SM_KDT,
93                SM_KTE,
94                SM_OCM,
95                SM_OCT,
96                SM_TER,
97                SM_GEN,
98                SM_SIZE,
99                SM_NOTSET
100        };
101
102        enum ShowTree
103        {
104                SHOWTREE_OFF,
105                SHOWTREE_HILITE,
106                SHOWTREE_ALL,
107                SHOWTREE_MODES_NUM
108        };
109
110        enum AppState
111        {
112                AS_NORMAL,
113                AS_RECORD,
114                AS_PLAYBACK
115        };
116
117        struct Options
118        {
119                Options():
120                mRotateSpeed(36.0f),
121                mMoveSpeed(100.0f),
122                mRotationPeriod(30.0f),
123                mKT(2.0f),
124                mKI(1.0f),
125                mMaxDepth(12),
126                mSceneManager(SM_KDT),
127                mRenderMethod(KdTree::KDRM_GTP_CHC),
128                mBuildMethod(KdTree::KDBM_PRIORITYQUEUE),
129                mSceneType(ST_SIMPLE),
130                mFastStart(false),
131                mBurnIn(false),
132                mDemoMode(false),
133                mEnhancedVisibility(false),
134                mDemoInterval(1.0f),
135                myApp(0)
136                {
137
138                }
139
140                String mSceneOutfileName;
141                String mDemoInfileName;
142                String mDemoOutfileName;
143                String mDemoLogfileName;
144                String mComment;
145                Degree mRotateSpeed;
146                Real mMoveSpeed;
147                Real mRotationPeriod;
148                Real mKT;
149                Real mKI;
150                int mMaxDepth;
151                int mSceneManager;
152                int mRenderMethod;
153                int mBuildMethod;
154                int mSceneType;
155                bool mFastStart;
156                bool mBurnIn;
157                bool mDemoMode;
158                bool mEnhancedVisibility;
159                Real mDemoInterval;
160                KdTreeApp *myApp;
161        };
162
163        struct DemoStats
164        {
165                unsigned int mTotalNumFrames;
166                unsigned int mNumFrames;
167                Real mTotalEllapsedTime;
168                Real mEllapsedTime;
169        } mDemoStats;
170
171    // Constructor takes a RenderWindow because it uses that to determine input context
172    KdTreeAppListener(RenderWindow* win, SceneManager* sm, const Options& options, 
173                bool useBufferedInputKeys = false, bool useBufferedInputMouse = false);
174
175    virtual ~KdTreeAppListener(void);
176
177        void initOverlayElement(OverlayElement **elInfo, String ext,
178                String name, int top, String caption);
179
180        void initStatsOverlay(void);
181
182        void initKdTreeOverlay(void);
183
184        void showDebugOverlay(bool show);
185
186        void toggleUseViewCells(void);
187
188        void toggleUseVisibilityFilter(void);
189
190        void toggleVizCamera(void);
191
192        void toggleShowBoxes(void);
193
194        void toggleEnhancedVisibility(void);
195
196        void toggleBuildMethod(void);
197
198        void toggleRenderMethod(void);
199
200    virtual bool processUnbufferedKeyInput(const FrameEvent& evt);
201
202    bool processUnbufferedMouseInput(const FrameEvent& evt);
203
204        void moveCamera(void);
205
206    // Override frameStarted event to process that (don't care about frameEnded)
207    bool frameStarted(const FrameEvent& evt);
208
209    bool frameEnded(const FrameEvent& evt);
210
211        void switchMouseMode(void);
212
213        void switchKeyMode(void);
214
215        void keyClicked(KeyEvent* e);
216
217        void keyPressed(KeyEvent* e) {};
218        void keyReleased(KeyEvent* e) {};
219
220        const static Real       DEMO_WAIT;
221        const static String NA;
222        const static String RENDERMETHOD[];
223        const static String RENDERMETHODCAPTION[];
224        const static String BUILDMETHOD[];
225        const static String BUILDMETHODCAPTION[];
226        const static String SCENEMANAGER[];
227        const static String SCENEMANAGERNAME[];
228protected:
229        // basic
230        RenderWindow* mWindow;
231        SceneManager *mSceneMgr;
232        Options mOptions;
233        bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
234
235        // elements
236        SceneNode *mCamNode;
237        Camera* mCamera;
238        Camera* mTopCam;
239
240        // toggle
241        bool mStatsOn;
242
243        bool mVizCamera;
244        bool mFreeMove;
245        bool mTopCamFollow;
246
247        int mShowTree;
248
249        // view cells
250        bool mUseViewCells;
251        bool mUseVisibilityFilter;
252
253        // counters
254        int mSeqNum;
255        unsigned int mNumScreenShots;
256
257        // rendering/texture options
258        int mSceneDetailIndex;
259        TextureFilterOptions mFiltering;
260        int mAniso;
261
262        // chc stats
263        Real mDelayedQueriesIssued;
264        Real mDelayedTraversedNodes;
265
266        // overlays
267        Overlay *mDemoOverlay;
268        Overlay *mDebugOverlay;
269        Overlay *mKdTreeOverlay;
270
271        OverlayElement *mDemoStatus;
272        TextAreaOverlayElement *mDemoTime;
273        TextAreaOverlayElement *mDemoFPSDisp;
274
275        OverlayElement *mRenderMethodInfo;
276        OverlayElement *mEnhancedVisInfo;
277        OverlayElement *mBuildMethodInfo;
278        OverlayElement *mKdTreeMaxDepthInfo;
279        OverlayElement *mHighlightLevelInfo;
280        OverlayElement *mKTInfo;
281        OverlayElement *mKIInfo;
282        OverlayElement *mMovementInfo;
283        OverlayElement *mTopCamInfo;
284        OverlayElement *mViewCellsInfo;
285        OverlayElement *mViewFilterInfo;
286
287        OverlayElement *mFrustumCulledNodesInfo;
288        OverlayElement *mQueryCulledNodesInfo;
289        OverlayElement *mTraversedNodesInfo;
290        OverlayElement *mHierarchyNodesInfo;
291        OverlayElement *mRenderedNodesInfo;
292        OverlayElement *mObjectsCountInfo;
293        OverlayElement *mQueriesIssuedInfo;
294
295        // input
296        EventProcessor* mEventProcessor;
297        InputReader* mInputDevice;
298
299        // movement
300        Vector3 mTranslateVector;
301        Vector3 mVizCamTransVect;
302        Radian mRotX, mRotY;
303        float mMoveScale;
304        Degree mRotScale;
305        Radian mDeathAngle;
306        // for terrain
307        RaySceneQuery *mRaySceneQuery;
308
309        // just to stop toggles flipping too fast
310        Real mTimeUntilNextToggle ;
311
312        // stuff for walkthrough recording/playback
313        //std::ofstream mDemoFramesLog;
314        std::list<Real> mDemoFPS;
315        Real mTimeUntilNextLogWrite;
316        FrameList mFrameList;
317        FrameList::iterator mCurrFrame;
318        Real mTimeRemaining;
319        Real mWaitBeforeDemoStart;
320
321        AppState mAppState;
322
323        void setDemoOverlay();
324
325        void toggleRecord();
326        void togglePlayback();
327
328        /** write FPS stats to log file (csv) **/
329        void saveLog();
330
331        void saveFrameInfo(Real elapsedTime);
332
333        /** save demo frame data to file **/
334        static void saveFrames(const String& filename, FrameList& framelist);
335        static void saveFramesAscii(const String& filename, FrameList& framelist);
336        static void saveFramesBinary(const String& filename, FrameList& framelist);
337
338        /** load demo frame data from file **/
339        static void loadFrames(const String& filename, FrameList& framelist);
340        static void loadFramesAscii(const String& filename, FrameList& framelist);
341        static void loadFramesBinary(const String& filename, FrameList& framelist);
342
343        void updateStats(void);
344};
345
346#endif
347
Note: See TracBrowser for help on using the repository browser.