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

Revision 1273, 7.5 KB checked in by szydlowski, 18 years ago (diff)

Added the KdTerrainSceneManager?, a subclass of the KdTreeSceneManager? capable of rendering terrain like the TerrainSceneManager? from Ogre.
All the *Kd*Terrain* classes are identical to their octree counterparts, save prefixing all classes and structures with Kd to avoid namespace clashes.
This was necessary, since the TerrainSceneManager? was hard coded in these classes, and all references had to be replaced with the KdTerrainSceneManager?.
Also added a comprehensive README for the demo application.

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 KdTreeAppListener: public FrameListener, public KeyListener
69{
70
71public:
72        // visualization modes for scene nodes
73        enum VizMode
74        {
75                NODEVIZ_NONE,
76                NODEVIZ_RENDER_NODES,
77                NODEVIZ_RENDER_NODES_AND_CONTENT,
78                NODEVIZ_MODES_NUM
79        };
80
81        enum SceneMgr
82        {
83                SM_KDT,
84                SM_KTE,
85                SM_OCM,
86                SM_OCT,
87                SM_TER,
88                SM_GEN,
89                SM_SIZE,
90                SM_NOTSET
91        };
92
93        enum ShowTree
94        {
95                SHOWTREE_OFF,
96                SHOWTREE_HILITE,
97                SHOWTREE_ALL,
98                SHOWTREE_MODES_NUM
99        };
100
101        enum AppState
102        {
103                AS_NORMAL,
104                AS_RECORD,
105                AS_PLAYBACK
106        };
107
108        struct Options
109        {
110                Options():
111                mRotateSpeed(36.0f),
112                mMoveSpeed(100.0f),
113                mRotationPeriod(30.0f),
114                mKT(2.0f),
115                mKI(1.0f),
116                mMaxDepth(12),
117                mSceneManager(SM_KDT),
118                mRenderMethod(KdTree::KDRM_GTP_CHC),
119                mBuildMethod(KdTree::KDBM_PRIORITYQUEUE),
120                mDemoMode(false),
121                mEnhancedVisibility(false),
122                mDemoInterval(1.0f)
123                {
124
125                }
126
127                String mSceneFiles;
128                String mDemoInfileName;
129                String mDemoOutfileName;
130                String mDemoLogfileName;
131                String mComment;
132                Degree mRotateSpeed;
133                Real mMoveSpeed;
134                Real mRotationPeriod;
135                Real mKT;
136                Real mKI;
137                int mMaxDepth;
138                int mSceneManager;
139                int mRenderMethod;
140                int mBuildMethod;
141                bool mDemoMode;
142                bool mEnhancedVisibility;
143                Real mDemoInterval;
144        };
145
146        struct DemoStats
147        {
148                unsigned int mTotalNumFrames;
149                unsigned int mNumFrames;
150                Real mTotalEllapsedTime;
151                Real mEllapsedTime;
152        } mDemoStats;
153
154    // Constructor takes a RenderWindow because it uses that to determine input context
155    KdTreeAppListener(RenderWindow* win, SceneManager* sm, const Options& options, 
156                bool useBufferedInputKeys = false, bool useBufferedInputMouse = false);
157
158    virtual ~KdTreeAppListener(void);
159
160        void initOverlayElement(OverlayElement **elInfo, String ext,
161                String name, int top, String caption);
162
163        void initStatsOverlay(void);
164
165        void initKdTreeOverlay(void);
166
167        void showDebugOverlay(bool show);
168
169        void toggleVizCamera(void);
170
171        void toggleShowBoxes(void);
172
173        void toggleEnhancedVisibility(void);
174
175        void toggleBuildMethod(void);
176
177        void toggleRenderMethod(void);
178
179    virtual bool processUnbufferedKeyInput(const FrameEvent& evt);
180
181    bool processUnbufferedMouseInput(const FrameEvent& evt);
182
183        void moveCamera(void);
184
185    // Override frameStarted event to process that (don't care about frameEnded)
186    bool frameStarted(const FrameEvent& evt);
187
188    bool frameEnded(const FrameEvent& evt);
189
190        void switchMouseMode(void);
191
192        void switchKeyMode(void);
193
194        void keyClicked(KeyEvent* e);
195
196        void keyPressed(KeyEvent* e) {};
197        void keyReleased(KeyEvent* e) {};
198
199        const static Real       DEMO_WAIT;
200        const static String NA;
201        const static String RENDERMETHOD[];
202        const static String RENDERMETHODCAPTION[];
203        const static String BUILDMETHOD[];
204        const static String BUILDMETHODCAPTION[];
205        const static String SCENEMANAGER[];
206        const static String SCENEMANAGERNAME[];
207protected:
208        // basic
209        RenderWindow* mWindow;
210        SceneManager *mSceneMgr;
211        Options mOptions;
212        bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
213
214        // elements
215        SceneNode *mCamNode;
216        Camera* mCamera;
217        Camera* mTopCam;
218
219        // toggle
220        bool mStatsOn;
221
222        bool mVizCamera;
223        bool mFreeMove;
224        bool mTopCamFollow;
225
226        int mShowTree;
227
228        // counters
229        int mSeqNum;
230        unsigned int mNumScreenShots;
231
232        // rendering/texture options
233        int mSceneDetailIndex;
234        TextureFilterOptions mFiltering;
235        int mAniso;
236
237        // chc stats
238        Real mDelayedQueriesIssued;
239        Real mDelayedTraversedNodes;
240
241        // overlays
242        Overlay *mDemoOverlay;
243        Overlay *mDebugOverlay;
244        Overlay *mKdTreeOverlay;
245
246        OverlayElement *mDemoStatus;
247        TextAreaOverlayElement *mDemoTime;
248
249
250        OverlayElement *mRenderMethodInfo;
251        OverlayElement *mEnhancedVisInfo;
252        OverlayElement *mBuildMethodInfo;
253        OverlayElement *mKdTreeMaxDepthInfo;
254        OverlayElement *mHighlightLevelInfo;
255        OverlayElement *mKTInfo;
256        OverlayElement *mKIInfo;
257        OverlayElement *mMovementInfo;
258        OverlayElement *mTopCamInfo;
259
260        OverlayElement *mFrustumCulledNodesInfo;
261        OverlayElement *mQueryCulledNodesInfo;
262        OverlayElement *mTraversedNodesInfo;
263        OverlayElement *mHierarchyNodesInfo;
264        OverlayElement *mRenderedNodesInfo;
265        OverlayElement *mObjectsCountInfo;
266        OverlayElement *mQueriesIssuedInfo;
267
268        // input
269        EventProcessor* mEventProcessor;
270        InputReader* mInputDevice;
271
272        // movement
273        Vector3 mTranslateVector;
274        Vector3 mVizCamTransVect;
275        Radian mRotX, mRotY;
276        float mMoveScale;
277        Degree mRotScale;
278        Radian mDeathAngle;
279        // for terrain
280        RaySceneQuery *mRaySceneQuery;
281
282        // just to stop toggles flipping too fast
283        Real mTimeUntilNextToggle ;
284
285        // stuff for walkthrough recording/playback
286        //std::ofstream mDemoFramesLog;
287        std::list<Real> mDemoFPS;
288        Real mTimeUntilNextLogWrite;
289        FrameList mFrameList;
290        FrameList::iterator mCurrFrame;
291        Real mTimeRemaining;
292        Real mWaitBeforeDemoStart;
293
294        AppState mAppState;
295
296        void setDemoOverlay();
297
298        void toggleRecord();
299        void togglePlayback();
300
301        /** write FPS stats to log file (csv) **/
302        void saveLog();
303
304        void saveFrameInfo(Real elapsedTime);
305
306        /** save demo frame data to file **/
307        static void saveFrames(const String& filename, FrameList& framelist);
308        static void saveFramesAscii(const String& filename, FrameList& framelist);
309        static void saveFramesBinary(const String& filename, FrameList& framelist);
310
311        /** load demo frame data from file **/
312        static void loadFrames(const String& filename, FrameList& framelist);
313        static void loadFramesAscii(const String& filename, FrameList& framelist);
314        static void loadFramesBinary(const String& filename, FrameList& framelist);
315
316        void updateStats(void);
317};
318
319#endif
320
Note: See TracBrowser for help on using the repository browser.