source: GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.h @ 2455

Revision 2455, 12.6 KB checked in by mattausch, 17 years ago (diff)
RevLine 
[133]1#ifndef _TerrainFrameListener_H__
2#define _TerrainFrameListener_H__
[115]3
4#include "CEGUIForwardRefs.h"
5#include <Ogre.h>
6#include <OgreKeyEvent.h>
7#include <OgreEventListeners.h>
8#include <OgreStringConverter.h>
9#include <OgreException.h>
10#include "VisibilityEnvironment.h"
[130]11#include "VisibilityManager.h"
[115]12#include "OgreTerrainContentGenerator.h"
[151]13#include "OgrePlatformQueryManager.h"
[115]14
[173]15
[160]16class TestCullingTerrainApplication;
17
18
[115]19using namespace Ogre;
20
[259]21/** Struct storing walktrough statistics
22*/
23struct WalkthroughStats
24{
25public:
[115]26
[259]27        unsigned long mAccFps;
28        unsigned long mBestFps;
29        unsigned long mWorstFps;
30        unsigned long mAccTris;
31        unsigned long mAccQueryCulledNodes;
32        unsigned long mAccFrustumCulledNodes;
33        unsigned long mFrameCount;
34        unsigned long mAccRenderedNodes;
35       
36        WalkthroughStats():
37        mAccFps(0), mBestFps(0), mWorstFps(0), mAccTris(0),
38        mAccQueryCulledNodes(0), mAccFrustumCulledNodes(0),
39        mFrameCount(0), mAccRenderedNodes(0)
40        {}
[254]41
[259]42        void Reset()
43        {
[2305]44                mAccFps = 0;
45                mBestFps = 0;
46                mWorstFps = 0;
47                mAccTris = 0;
48                mAccQueryCulledNodes = 0;
49                mAccFrustumCulledNodes = 0;
50                mFrameCount = mAccRenderedNodes = 0;
[259]51        }
52
[2305]53        void UpdateFrame(int currentFps,
54                                         int bestFps,
55                                         int worstFps,
56                                         int renderedTris,
57                                         int renderedNodes,
58                                         int queryCulledNodes,
59                                         int frustumCulledNodes)
[259]60        {
61                mAccFps += currentFps;
62                mBestFps = bestFps;
63                mWorstFps = worstFps;
64
65                // accumulated #triangles (M)
66                mAccTris += renderedTris / 1000;
67                mAccRenderedNodes += renderedNodes;
68                mAccQueryCulledNodes += queryCulledNodes;
69                mAccFrustumCulledNodes += frustumCulledNodes;
70       
71                ++ mFrameCount;
72        }
73
74        void Print(std::ostream &d, const std::string &algorithmName) const
75        {
76                // compuate average fps and triangle count
77                float avgFps = (float)mAccFps / (float)mFrameCount;
78                float avgTris = (float)mAccTris / (float)mFrameCount;
79                float avgFrustumCulledNodes = 0;
80                float avgRenderedNodes = 0;
81                float avgQueryCulledNodes = 0;
82               
83                if (mFrameCount != 0)
84                {
85                        avgFrustumCulledNodes = (float)mAccFrustumCulledNodes / (float)mFrameCount;
86                        avgQueryCulledNodes  = (float)mAccQueryCulledNodes / (float)mFrameCount;
87                        avgRenderedNodes = (float)mAccRenderedNodes / (float) mFrameCount;
88                }
89
90                //-- write out stats for recorded walkthrough
91                d << "Algorithm: " << algorithmName << "\n"
[2108]92                  << "avg. FPS: " << avgFps << "\n"
93                  << "best FPS: " << mBestFps << "\n"
94                  << "worst FPS: " << mWorstFps << "\n"
95                  << "#frames: " << mFrameCount << "\n"
96                  << "avg. #triangles: " << avgTris << " M\n"
97                  << "avg. #query culled nodes: " << avgFrustumCulledNodes << "\n"
98                  << "avg. #frustum culled nodes: " << avgQueryCulledNodes << "\n"
99                  << "avg. #rendered nodes: " << avgRenderedNodes << "\n";
[259]100        }
101
102};
103
[161]104/** Frame listener specialised for terrains.
[115]105*/
[161]106class TerrainFrameListener: public FrameListener, public MouseListener,
107                                                        public MouseMotionListener, public KeyListener
[115]108{
109public:
110       
[160]111   TerrainFrameListener(RenderWindow* win,
112                                                Camera* cam,
113                                                SceneManager *sceneManager,
114                                                CEGUI::Renderer *renderer,
115                                                TerrainContentGenerator *contentGenerator,
116                                                Camera *vizCamera,
117                                                SceneNode *camNode,
118                                                Light *sunLight,
119                                                TestCullingTerrainApplication *app);
[115]120
[133]121   ~TerrainFrameListener();
[115]122
123   bool frameStarted(const FrameEvent& evt);
124   bool frameEnded(const FrameEvent& evt);
[417]125     
[115]126
127   /* MouseListener callbacks. */
128   virtual void mouseClicked(MouseEvent* e) { }
129   virtual void mouseEntered(MouseEvent* e) { }
130   virtual void mouseExited(MouseEvent* e)  { }
131
132   // This is when the mouse button goes DOWN.
[161]133   void mousePressed(MouseEvent* e);
[115]134
135   // This is when the mouse button is let UP.
[161]136   void mouseReleased(MouseEvent* e);
[115]137
138   /* MouseMotionListener callbacks */
[161]139   void mouseMoved(MouseEvent *e);
[115]140   
141   // This is when the mouse is clicked, held and dragged.
[161]142   void mouseDragged(MouseEvent *e);
[115]143
[161]144   void mouseDragDropped(MouseEvent *e);
[115]145   void keyPressed(KeyEvent* e);
146
147   void keyReleased(KeyEvent* e);
148   void keyClicked(KeyEvent* e);
149 
[161]150   /** The information about camera position and orienation per frame.
151   */
[115]152   typedef struct
153   {
154           Vector3 position;
155           Quaternion orientation;
156           Real timeElapsed;
[254]157           Real fps;
[115]158   } frame_info;
159
[254]160   typedef std::vector<frame_info> FrameInfoContainer;
161
[115]162   enum  {WALKTHROUGH, REPLAY, STATE_NUM};
163
164   // visualization modes for scene nodes
[723]165   enum {
[2359]166                 NODEVIZ_NONE,
167         NODEVIZ_RENDER_NODES,
168                 NODEVIZ_RENDER_NODES_AND_CONTENT,
169                 NODEVIZ_RENDER_PVS,
[723]170                 NODEVIZ_MODES_NUM};
171
[115]172   //enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM};
173
[173]174   void zoomVizCamera(int zoom);
[115]175       
[254]176   void addFrameInfo(FrameInfoContainer &frameInfos, SceneNode *camNode, Real timeElapsed);
[115]177   void setCurrentFrameInfo(Real timeElapsed);
178
[1271]179   void applyCurrentAlgorithm();
[115]180
181   void moveCamera();
182
[723]183   void writeFrames(const std::string filename, const FrameInfoContainer &frameInfo) const;
184   void loadFrames(const std::string filename, FrameInfoContainer &frameInfo);
[115]185
186    bool processUnbufferedKeyInput(const FrameEvent& evt);
187    bool processUnbufferedMouseInput(const FrameEvent& evt);
188
[723]189        void switchMouseMode();
190       
[254]191        /** Shows the frame / algorithm statistics.
192        */
[120]193    void showStats(bool show);
[115]194
[254]195        /** Updates frame statistics and the frame statistics display.
196        */
[120]197        void updateStats();
198
[867]199        /** Toggles whether help screen is shown or not.
[254]200        */
[120]201        void toggleShowHelp();
[254]202       
[867]203        /** Toggles whether shadows are shown or not.
[254]204        */
[139]205        void toggleShowShadows();
[867]206        /** if camera stats (e.g, location, orientation, ...) should be displayed-
207        */
[120]208        void toggleDisplayCameraDetails();
[254]209        /** Takes screenshot of the current scene.
210        */
[164]211        void takeScreenshot();
[254]212        /** Takes one video frame.
213        */
[2352]214
215        void showBoundingBoxes();
[254]216        void takeVideoFrame(std::ofstream &ofstr);
217
[120]218        void nextSceneDetailLevel();
219        void nextFilter();
220        void nextAlgorithm();
221        void nextNodeVizMode();
222        void nextAppState();
223    void changeThreshold(int incr);
[146]224        void changeAssumedVisibility(int incr);
[723]225        void changeVizScale(const int incr);
[2455]226       
[187]227        void setTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves);
[2455]228       
229        void setTestGeometryBounds(bool testGeometryBounds);
230
[1604]231        /** Shows visualization of octree hierarchy nodes.
[254]232        */
[120]233        void toggleShowOctree();
[2455]234
[1604]235        /** Shows visualization of the view cells.
236        */
237        void toggleShowViewCells();
[2455]238       
[901]239        /** Toggles between view cells / no view cells.
240        */
241        void toggleUseViewCells();
242
[867]243        /** Toggles whether we use the initial depth pass.
[254]244        */
[120]245        void toggleUseDepthPass();
[2145]246
247        void toggleFlushQueue();
248
[867]249        /** Toggles whether the visualization is shown.
[343]250        */
[120]251        void toggleShowViz();
[2145]252
[867]253        /** Toggles whether the frames are recorded.
[254]254        */
[120]255        void toggleRecord();
256
[1607]257        void changeFloorDist(const float incr);
258
[133]259        /** Applies visibility query. Collects the visible objects
260                and their visibility information.
[154]261                @param fromPoint if query should be from point or from camera
262                @param relativeVisibility if query should return number of visible pixels or
263                the ratio visible / projected pixels.
264                @param useItemBuffer if item buffer should be used or occlusion queries
[133]265        */
[160]266        void applyVisibilityQuery(bool fromPoint, bool relativeVisibility, bool useItemBuffer);
[130]267
[254]268        /** Shows result from visibility queries.
269        */
[135]270        void toggleShowQueryStats();
271
[160]272        /** Sets the type of the objects generated in the scene.
273        */
[1271]274        void applyObjectType();
[160]275
[1271]276        void setAlgorithm(const int algorithm);
277
278
[173]279        static String msAlgorithmCaptions[];
[723]280        static String msApprevAlgorithmCaptions[];
[173]281        static String msQueryTypeCaptions[];
282        static String msQueryRelativeVisCaptions[];
283        static String msQueryMethodCaptions[];
284        static Real msObjectTerrainOffsets[];
285        static Real msObjectScales[];
286        static String msObjectCaptions[];
287
[115]288protected:
289
[160]290        void initHelpOverlayElement(String name, int top);
[173]291        void initOverlayElement(OverlayElement **elInfo, String ext, String name,
292                                                        int top, String caption);
[160]293
294        //-- initialise overlays
295        void initHelpOverlay();
296        void initVisStatsOverlay();
297        void initQueryOverlay();
[115]298       
[120]299        SceneManager *mSceneMgr;           // A pointer to the scene manager
[115]300   
301        CEGUI::Renderer *mGUIRenderer;     // cegui renderer
302       
303        int mCurrentAlgorithm;
304        int mVisibilityThreshold;
[146]305        int mAssumedVisibility;
[254]306        /// the current frame number
[120]307        int mCurrentFrame;
[254]308        /// the current application state
[120]309        int mAppState;
[254]310        /// The number of objects on the screen
[120]311        int mObjectCount;           
[254]312        /// visualization mode
[120]313        int mNodeVizMode;
[254]314        /// number of video frames
315        int mNumVideoFrames;
316        /// the newly created object
[2352]317        int m_iShowBoundingBoxes;
318        int m_iBoundingBoxLevel;
[254]319        SceneNode *mCurrentObject;   
[259]320
321        WalkthroughStats mWalkthroughStats;
322
[723]323        /// visualization scale
324        float mVizScale;
[259]325
[723]326        ////////////////////////////////////////////////////////////////////////
327
328        /** HACK for recording demo:
329                1) the walkthrough must be recorded.
330                2) the walktrough must be replayed using the different options, e.g., CHC
[915]331                   with the mSavePrecomputedFps (key "E") option. This saves the frame rates
[723]332                   for the different methods.
[915]333            3) the walkthrough must then be replayed with the mRecordDemo (KEY "M") options turned on.
[723]334                   for the video recording we are using FRAPS.
335        */
336
337        /// the currently interpolated FPS
338        float mPrecomputedFps;
339        /// saves the precomputed fps for the different methods.
340        bool mSavePrecomputedFps;
341        /// displayes the precomputed fps
342        bool mRecordDemo;
343       
344        ////////////////////////////////////////////////////////////////////////////
345
346
[115]347        OverlayElement *mAlgorithmInfo;
348        OverlayElement *mThresholdInfo;
[146]349        OverlayElement *mAssumedVisibilityInfo;
[115]350        OverlayElement *mFrustumCulledNodesInfo;
351        OverlayElement *mQueryCulledNodesInfo;
352    OverlayElement *mTraversedNodesInfo;
353        OverlayElement *mHierarchyNodesInfo;
[155]354        OverlayElement *mTestGeometryForVisibleLeavesInfo;
[115]355        OverlayElement *mUseDepthPassInfo;
356        OverlayElement *mRenderedNodesInfo;
[160]357        OverlayElement *mObjectsCountInfo;
[115]358        OverlayElement *mQueriesIssuedInfo;
[155]359        OverlayElement *mDelayedQueriesIssuedInfo;
360        OverlayElement *mDelayedTraversedNodesInfo;
[160]361        OverlayElement *mCurrentObjectTypeInfo;
[945]362        OverlayElement *mViewCellsInfo;
[115]363
[723]364        OverlayElement *mMyStatsAlgorithmInfo;
365        OverlayElement *mMyStatsFpsInfo;
366
[945]367        OverlayElement *mMyLoadingInfo;
368       
[135]369        OverlayElement *mQueryTypeInfo;
370        OverlayElement *mQueryVisibleNodesInfo;
[159]371        OverlayElement *mQueryVisibleGeometryInfo;
372        OverlayElement *mQueryVisiblePatchInfo;
373
[135]374        OverlayElement *mQueryVisiblityInfo;
375        OverlayElement *mQueryNodeVisibilityInfo;
376        OverlayElement *mQueryGeometryVisibilityInfo;
[159]377        OverlayElement *mQueryPatchVisibilityInfo;
[135]378
[115]379        RayQueryExecutor *mRayQueryExecutor;
380        TerrainContentGenerator *mTerrainContentGenerator;
381
[155]382        bool mTestGeometryForVisibleLeaves;
[2455]383        bool mTestGeometryBounds;
384
[115]385        bool mShowOctree;
[1604]386        bool mShowViewCells;
[115]387        bool mUseDepthPass;
[2145]388        bool mFlushQueue;
[115]389        bool mShowVisualization;
390        bool mCullCamera;
[254]391        bool mRecordFrames;
[139]392        bool mShowShadows;
[120]393        bool mVisualizeCulledNodes;
394        bool mShowHelp;
395        bool mStatsOn;
[2455]396       
397
398        ////////
399        //-- true if the mouse buttons are down
400       
[723]401        bool mLMouseDown;
[2168]402        bool mRMouseDown;   
[120]403        bool mShutdownRequested;
404        bool mDisplayCameraDetails;
[159]405        bool mUseItemBuffer;
[161]406        bool mUseAnimation;
[174]407       
[2455]408
[174]409        int mItemBufferMode;
[159]410
[115]411        Real mVizCameraHeight;
412
413        Camera *mVizCamera;
414        SceneNode *mCamNode;
415       
[254]416        /// Per frame data stored for a walkthrough
417        FrameInfoContainer mFrameInfo;
[723]418        /// HACK for demo
419        FrameInfoContainer mPrecomputedFpsFrameInfo;
[254]420       
[160]421        Real mReplayTimeElapsed;
[115]422    InputReader* mInputDevice;
423    Camera* mCamera;
424
425    Vector3 mTranslateVector;
426    RenderWindow* mWindow;
[120]427   
[115]428        unsigned int mNumScreenShots;
[120]429    int mSceneDetailIndex;
430        int mAniso;
431
432        float mMoveScale;
[115]433    Degree mRotScale;
[164]434
[115]435    // just to stop toggles flipping too fast
[120]436    Real mTimeDelay;
[115]437    Radian mRotX, mRotY;
438    TextureFilterOptions mFiltering;
[120]439 
440        Real mMoveSpeed;
[115]441    Degree mRotateSpeed;
[120]442   
443        Overlay* mDebugOverlay;
444        Overlay* mHelpOverlay;
445        Overlay* mCullStatsOverlay;
[135]446        Overlay* mQueryOverlay;
[723]447        Overlay* mMyStatsOverlay;
[945]448        Overlay *mLoadingOverlay;
[121]449
450        Light *mSunLight;
[130]451        GtpVisibility::VisibilityManager *mVisibilityManager;
452        EventProcessor* mEventProcessor;
453       
[133]454        bool mShiftPressed;
[135]455        bool mShowQueryStats;
[259]456       
[151]457        PlatformQueryManager *mQueryManager;
[155]458
459        float mDelayedQueriesIssued;
460        float mDelayedTraversedNodes;
[159]461
[160]462        int mCurrentObjectType;
[945]463       
[164]464        bool mDeleteObjects;
[254]465        bool mRecordVideo;
[164]466
[254]467        Timer *mTimer;
468        long mTimeFrameEnded;
469        long mTimeFrameStarted;
470        float mPureRenderTimeFps;
[160]471        TestCullingTerrainApplication *mApplication;
[417]472
473        bool mUseBufferedInputMouse;
[901]474       
475        bool mUseViewCells;
[937]476        bool mViewCellsLoaded;
[1607]477
478        float mFloorDist;
[115]479};
480
481
[133]482#endif //_TerrainFrameListener_H__
Note: See TracBrowser for help on using the repository browser.