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

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