[61] | 1 | /**
|
---|
| 2 | \file
|
---|
| 3 | TestCullingTerrainApplication.h
|
---|
| 4 | */
|
---|
| 5 | #include "CEGUIForwardRefs.h"
|
---|
| 6 | #include "ExampleApplication.h"
|
---|
[107] | 7 | #include "OgreTerrainContentGenerator.h"
|
---|
[74] | 8 | #include "VisibilityEnvironment.h"
|
---|
[99] | 9 | #include <OgreRenderTargetListener.h>
|
---|
[106] | 10 | #include <vector>
|
---|
[61] | 11 |
|
---|
| 12 | Real 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 |
|
---|
[74] | 22 | String mCurrentAlgorithmCaptions[GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS] =
|
---|
[61] | 23 | {
|
---|
[74] | 24 | "View Frustum Culling",
|
---|
| 25 | "Stop and Wait Culling",
|
---|
| 26 | "Coherent Hierarchical Culling"
|
---|
[61] | 27 | };
|
---|
[106] | 28 |
|
---|
| 29 | /** The information about camera position and orienation per frame */
|
---|
| 30 | typedef struct
|
---|
[105] | 31 | {
|
---|
[106] | 32 | Vector3 position;
|
---|
| 33 | Quaternion orientation;
|
---|
[107] | 34 | Real timeElapsed;
|
---|
[106] | 35 | } frame_info;
|
---|
[61] | 36 |
|
---|
[106] | 37 |
|
---|
[99] | 38 | class VisualizationRenderTargetListener: public RenderTargetListener
|
---|
| 39 | {
|
---|
| 40 | public:
|
---|
| 41 | VisualizationRenderTargetListener(SceneManager *sceneMgr);
|
---|
| 42 |
|
---|
| 43 | protected:
|
---|
| 44 | void preViewportUpdate (const RenderTargetViewportEvent &evt);
|
---|
| 45 | void postRenderTargetUpdate (const RenderTargetEvent &evt);
|
---|
| 46 |
|
---|
| 47 | SceneManager *mSceneMgr;
|
---|
| 48 | };
|
---|
| 49 |
|
---|
[61] | 50 | class MouseQueryListener : public ExampleFrameListener, public MouseListener, public MouseMotionListener
|
---|
| 51 | {
|
---|
| 52 | public:
|
---|
[106] | 53 |
|
---|
[61] | 54 | MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager,
|
---|
[100] | 55 | CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera,
|
---|
| 56 | SceneNode *camNode);
|
---|
[61] | 57 |
|
---|
[80] | 58 | ~MouseQueryListener();
|
---|
[61] | 59 |
|
---|
| 60 | bool frameStarted(const FrameEvent& evt);
|
---|
| 61 | bool frameEnded(const FrameEvent& evt);
|
---|
[100] | 62 | bool processUnbufferedKeyInput(const FrameEvent& evt);
|
---|
| 63 |
|
---|
[61] | 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 |
|
---|
[107] | 87 | enum {WALKTHROUGH, REPLAY, STATE_NUM};
|
---|
| 88 |
|
---|
[113] | 89 | // visualization modes for scene nodes
|
---|
| 90 | enum {NODEVIZ_NONE, NODEVIZ_RENDER_NODES,
|
---|
| 91 | NODEVIZ_RENDER_NODES_AND_CONTENT, NODEVIZ_MODES_NUM};
|
---|
| 92 |
|
---|
[85] | 93 | void nextAlgorithm();
|
---|
[61] | 94 | void changeThreshold(int incr);
|
---|
[87] | 95 | void updateStats();
|
---|
[107] | 96 |
|
---|
[86] | 97 | void toggleUseOptimization();
|
---|
| 98 | void toggleShowOctree();
|
---|
[99] | 99 | void toggleUseVisibilityCulling();
|
---|
| 100 | void toggleShowViz();
|
---|
[113] | 101 | void nextNodeVizMode();
|
---|
[107] | 102 | void toggleRecord();
|
---|
| 103 |
|
---|
[100] | 104 | void zoomVizCamera(int zoom);
|
---|
[107] | 105 |
|
---|
| 106 | void addFrameInfo(SceneNode *camNode, Real timeElapsed);
|
---|
| 107 | void setCurrentFrameInfo(Real timeElapsed);
|
---|
[61] | 108 |
|
---|
[107] | 109 | void setAppState(int state);
|
---|
| 110 | void nextAppState();
|
---|
[104] | 111 |
|
---|
[107] | 112 | void setAlgorithm(int algorithm);
|
---|
[106] | 113 |
|
---|
[107] | 114 | void moveCamera();
|
---|
| 115 |
|
---|
| 116 | void writeFrames();
|
---|
| 117 | void loadFrames();
|
---|
| 118 |
|
---|
[111] | 119 | void toggleUseShadows();
|
---|
| 120 |
|
---|
[61] | 121 | protected:
|
---|
[104] | 122 | void Clamp2Terrain();
|
---|
[106] | 123 |
|
---|
[61] | 124 | bool mLMouseDown, mRMouseDown; // True if the mouse buttons are down
|
---|
| 125 | SceneManager *mSceneMgr; // A pointer to the scene manager
|
---|
| 126 |
|
---|
| 127 | CEGUI::Renderer *mGUIRenderer; // cegui renderer
|
---|
| 128 |
|
---|
| 129 | bool mShutdownRequested;
|
---|
| 130 | int mCurrentAlgorithm;
|
---|
[85] | 131 | int mVisibilityThreshold;
|
---|
[106] | 132 |
|
---|
[61] | 133 | OverlayElement *mAlgorithmInfo;
|
---|
| 134 | OverlayElement *mThresholdInfo;
|
---|
| 135 | OverlayElement *mFrustumCulledNodesInfo;
|
---|
| 136 | OverlayElement *mQueryCulledNodesInfo;
|
---|
| 137 | OverlayElement *mTraversedNodesInfo;
|
---|
| 138 | OverlayElement *mHierarchyNodesInfo;
|
---|
[86] | 139 | OverlayElement *mUseOptimizationInfo;
|
---|
[61] | 140 | OverlayElement *mRenderedNodesInfo;
|
---|
[87] | 141 | OverlayElement *mObjectsInfo;
|
---|
| 142 | OverlayElement *mQueriesIssuedInfo;
|
---|
[61] | 143 |
|
---|
[107] | 144 | SceneNode *mCurrentObject; // the newly created object
|
---|
| 145 | int mObjectCount; // The number of objects on the screen
|
---|
[61] | 146 |
|
---|
| 147 | RayQueryExecutor *mRayQueryExecutor;
|
---|
[82] | 148 | TerrainContentGenerator *mTerrainContentGenerator;
|
---|
[86] | 149 |
|
---|
| 150 | bool mUseOptimization;
|
---|
| 151 | bool mShowOctree;
|
---|
[99] | 152 | bool mUseVisibilityCulling;
|
---|
| 153 | bool mShowVisualization;
|
---|
[113] | 154 | int mNodeVizMode;
|
---|
[100] | 155 | bool mCullCamera;
|
---|
[93] | 156 |
|
---|
[100] | 157 | Real mVizCameraHeight;
|
---|
| 158 |
|
---|
| 159 | Camera *mVizCamera;
|
---|
| 160 | SceneNode *mCamNode;
|
---|
[106] | 161 |
|
---|
[105] | 162 | //std::deque<Vector3> mWalkList; // The list of points we are walking to
|
---|
[107] | 163 | std::vector<frame_info> mFrameInfo;
|
---|
[106] | 164 |
|
---|
| 165 | int mCurrentFrame;
|
---|
| 166 | // the current application state
|
---|
[107] | 167 | int mAppState;
|
---|
| 168 | bool mRecord;
|
---|
| 169 | Real mTimeElapsed;
|
---|
[111] | 170 | bool mUseShadows;
|
---|
[112] | 171 |
|
---|
| 172 | bool mVisualizeCulledNodes;
|
---|
[61] | 173 | };
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | class TestCullingTerrainApplication : public ExampleApplication
|
---|
| 177 | {
|
---|
| 178 | public:
|
---|
| 179 | ~TestCullingTerrainApplication();
|
---|
| 180 |
|
---|
| 181 | protected:
|
---|
[99] | 182 | //-- inherited from ExampleApplication
|
---|
| 183 | bool setup();
|
---|
[85] | 184 | void createScene();
|
---|
| 185 | void createFrameListener();
|
---|
[99] | 186 | void createCamera();
|
---|
| 187 | //void createViewports();
|
---|
| 188 |
|
---|
| 189 | virtual void createRenderTargetListener();
|
---|
| 190 |
|
---|
| 191 | /** cegui setup */
|
---|
[85] | 192 | void setupGui();
|
---|
[61] | 193 |
|
---|
| 194 | CEGUI::OgreCEGUIRenderer *mGUIRenderer;
|
---|
| 195 | CEGUI::System *mGUISystem;
|
---|
| 196 |
|
---|
[87] | 197 | Vector3 mMinTranslation;
|
---|
| 198 | Vector3 mMaxTranslation;
|
---|
| 199 |
|
---|
| 200 | Vector3 mMinAngle;
|
---|
[61] | 201 | Vector3 mMaxAngle;
|
---|
| 202 |
|
---|
[82] | 203 | TerrainContentGenerator *mTerrainContentGenerator;
|
---|
[99] | 204 |
|
---|
[100] | 205 | Camera *mVizCamera;
|
---|
| 206 | SceneNode *mCamNode;
|
---|
[109] | 207 | Light *mSunLight;
|
---|
[99] | 208 | VisualizationRenderTargetListener *mRenderTargetListener;
|
---|
[75] | 209 |
|
---|
[61] | 210 | private:
|
---|
| 211 | void chooseSceneManager(void);
|
---|
[99] | 212 | }; |
---|