1 | #ifndef _TerrainFrameListener_H__
|
---|
2 | #define _TerrainFrameListener_H__
|
---|
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"
|
---|
11 | #include "VisibilityManager.h"
|
---|
12 | #include "OgreTerrainContentGenerator.h"
|
---|
13 | #include "OgrePlatformQueryManager.h"
|
---|
14 |
|
---|
15 | using namespace Ogre;
|
---|
16 |
|
---|
17 | // z order index of visualizaion viewport
|
---|
18 | #define VIZ_VIEWPORT_Z_ORDER 10
|
---|
19 |
|
---|
20 |
|
---|
21 | /** Mouse query listener for terrain
|
---|
22 | */
|
---|
23 | class TerrainFrameListener: public FrameListener, public MouseListener, public MouseMotionListener, public KeyListener
|
---|
24 | {
|
---|
25 | public:
|
---|
26 |
|
---|
27 | TerrainFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager,
|
---|
28 | CEGUI::Renderer *renderer, TerrainContentGenerator *contentGenerator, Camera *vizCamera,
|
---|
29 | SceneNode *camNode, Light *sunLight);
|
---|
30 |
|
---|
31 | ~TerrainFrameListener();
|
---|
32 |
|
---|
33 |
|
---|
34 | bool frameStarted(const FrameEvent& evt);
|
---|
35 | bool frameEnded(const FrameEvent& evt);
|
---|
36 | //bool processUnbufferedKeyInput(const FrameEvent& evt);
|
---|
37 |
|
---|
38 |
|
---|
39 | /* MouseListener callbacks. */
|
---|
40 | virtual void mouseClicked(MouseEvent* e) { }
|
---|
41 | virtual void mouseEntered(MouseEvent* e) { }
|
---|
42 | virtual void mouseExited(MouseEvent* e) { }
|
---|
43 |
|
---|
44 | // This is when the mouse button goes DOWN.
|
---|
45 | virtual void mousePressed(MouseEvent* e);
|
---|
46 |
|
---|
47 | // This is when the mouse button is let UP.
|
---|
48 | virtual void mouseReleased(MouseEvent* e);
|
---|
49 |
|
---|
50 | /* MouseMotionListener callbacks */
|
---|
51 | virtual void mouseMoved (MouseEvent *e);
|
---|
52 |
|
---|
53 | // This is when the mouse is clicked, held and dragged.
|
---|
54 | virtual void mouseDragged (MouseEvent *e);
|
---|
55 |
|
---|
56 | void keyPressed(KeyEvent* e);
|
---|
57 |
|
---|
58 | void keyReleased(KeyEvent* e);
|
---|
59 | void keyClicked(KeyEvent* e);
|
---|
60 |
|
---|
61 | /** The information about camera position and orienation per frame */
|
---|
62 | typedef struct
|
---|
63 | {
|
---|
64 | Vector3 position;
|
---|
65 | Quaternion orientation;
|
---|
66 | Real timeElapsed;
|
---|
67 | } frame_info;
|
---|
68 |
|
---|
69 | enum {WALKTHROUGH, REPLAY, STATE_NUM};
|
---|
70 |
|
---|
71 | // visualization modes for scene nodes
|
---|
72 | enum {NODEVIZ_NONE, NODEVIZ_RENDER_NODES, NODEVIZ_RENDER_NODES_AND_CONTENT, NODEVIZ_MODES_NUM};
|
---|
73 | //enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM};
|
---|
74 |
|
---|
75 | void zoomVizCamera(int zoom);
|
---|
76 |
|
---|
77 | void addFrameInfo(SceneNode *camNode, Real timeElapsed);
|
---|
78 | void setCurrentFrameInfo(Real timeElapsed);
|
---|
79 |
|
---|
80 | void setAlgorithm(int algorithm);
|
---|
81 |
|
---|
82 | void moveCamera();
|
---|
83 |
|
---|
84 | void writeFrames();
|
---|
85 | void loadFrames();
|
---|
86 |
|
---|
87 |
|
---|
88 | // Constructor takes a RenderWindow because it uses that to determine input context
|
---|
89 | //ExampleFrameListener(RenderWindow* win, Camera* cam, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false)
|
---|
90 |
|
---|
91 | bool processUnbufferedKeyInput(const FrameEvent& evt);
|
---|
92 | bool processUnbufferedMouseInput(const FrameEvent& evt);
|
---|
93 |
|
---|
94 | void showStats(bool show);
|
---|
95 |
|
---|
96 | void updateStats();
|
---|
97 |
|
---|
98 | void toggleShowHelp();
|
---|
99 | void toggleShowStats();
|
---|
100 |
|
---|
101 | void toggleShowShadows();
|
---|
102 | void toggleDisplayCameraDetails();
|
---|
103 | void takeScreenShot();
|
---|
104 | void nextSceneDetailLevel();
|
---|
105 | void nextFilter();
|
---|
106 | void nextAlgorithm();
|
---|
107 | void nextNodeVizMode();
|
---|
108 | void nextAppState();
|
---|
109 | void changeThreshold(int incr);
|
---|
110 | void changeAssumedVisibility(int incr);
|
---|
111 | void toggleUseOptimization();
|
---|
112 | void toggleShowOctree();
|
---|
113 | void toggleUseDepthPass();
|
---|
114 | void toggleShowViz();
|
---|
115 | void toggleRecord();
|
---|
116 |
|
---|
117 | /** Applies visibility query. Collects the visible objects
|
---|
118 | and their visibility information.
|
---|
119 | @param fromnPoint if query should be from point or from camera
|
---|
120 | @param projectedPixels if query should return number of visible pixels or the ratio
|
---|
121 | visible pixels / projected pixels.
|
---|
122 | */
|
---|
123 | void ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility);
|
---|
124 |
|
---|
125 | void toggleShowQueryStats();
|
---|
126 |
|
---|
127 | protected:
|
---|
128 |
|
---|
129 | void resetStats();
|
---|
130 |
|
---|
131 | /** Clamp camera to terrain.
|
---|
132 | */
|
---|
133 | void Clamp2Terrain();
|
---|
134 |
|
---|
135 | SceneManager *mSceneMgr; // A pointer to the scene manager
|
---|
136 |
|
---|
137 | CEGUI::Renderer *mGUIRenderer; // cegui renderer
|
---|
138 |
|
---|
139 | int mCurrentAlgorithm;
|
---|
140 | int mVisibilityThreshold;
|
---|
141 | int mAssumedVisibility;
|
---|
142 | // the current frame number
|
---|
143 | int mCurrentFrame;
|
---|
144 | // the current application state
|
---|
145 | int mAppState;
|
---|
146 | // The number of objects on the screen
|
---|
147 | int mObjectCount;
|
---|
148 | // visualization mode
|
---|
149 | int mNodeVizMode;
|
---|
150 |
|
---|
151 | SceneNode *mCurrentObject; // the newly created object
|
---|
152 |
|
---|
153 | OverlayElement *mAlgorithmInfo;
|
---|
154 | OverlayElement *mThresholdInfo;
|
---|
155 | OverlayElement *mAssumedVisibilityInfo;
|
---|
156 | OverlayElement *mFrustumCulledNodesInfo;
|
---|
157 | OverlayElement *mQueryCulledNodesInfo;
|
---|
158 | OverlayElement *mTraversedNodesInfo;
|
---|
159 | OverlayElement *mHierarchyNodesInfo;
|
---|
160 | OverlayElement *mUseOptimizationInfo;
|
---|
161 | OverlayElement *mUseDepthPassInfo;
|
---|
162 | OverlayElement *mRenderedNodesInfo;
|
---|
163 | OverlayElement *mObjectsInfo;
|
---|
164 | OverlayElement *mQueriesIssuedInfo;
|
---|
165 |
|
---|
166 | OverlayElement *mQueryTypeInfo;
|
---|
167 | OverlayElement *mQueryVisibleNodesInfo;
|
---|
168 | OverlayElement *mQueryVisibleGeometryInfo;
|
---|
169 | OverlayElement *mQueryVisiblityInfo;
|
---|
170 | OverlayElement *mQueryNodeVisibilityInfo;
|
---|
171 | OverlayElement *mQueryGeometryVisibilityInfo;
|
---|
172 |
|
---|
173 | RayQueryExecutor *mRayQueryExecutor;
|
---|
174 | TerrainContentGenerator *mTerrainContentGenerator;
|
---|
175 |
|
---|
176 | bool mUseOptimization;
|
---|
177 | bool mShowOctree;
|
---|
178 | bool mUseDepthPass;
|
---|
179 | bool mShowVisualization;
|
---|
180 | bool mCullCamera;
|
---|
181 | bool mRecord;
|
---|
182 | bool mShowShadows;
|
---|
183 | bool mVisualizeCulledNodes;
|
---|
184 | bool mShowHelp;
|
---|
185 | bool mStatsOn;
|
---|
186 | bool mLMouseDown, mRMouseDown; // True if the mouse buttons are down
|
---|
187 | bool mShutdownRequested;
|
---|
188 | bool mDisplayCameraDetails;
|
---|
189 |
|
---|
190 | Real mVizCameraHeight;
|
---|
191 |
|
---|
192 | Camera *mVizCamera;
|
---|
193 | SceneNode *mCamNode;
|
---|
194 |
|
---|
195 | //std::deque<Vector3> mWalkList; // The list of points we are walking to
|
---|
196 | std::vector<frame_info> mFrameInfo;
|
---|
197 |
|
---|
198 | Real mTimeElapsed;
|
---|
199 | //EventProcessor* mEventProcessor;
|
---|
200 | InputReader* mInputDevice;
|
---|
201 | Camera* mCamera;
|
---|
202 |
|
---|
203 | Vector3 mTranslateVector;
|
---|
204 | RenderWindow* mWindow;
|
---|
205 |
|
---|
206 | //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
|
---|
207 | unsigned int mNumScreenShots;
|
---|
208 | int mSceneDetailIndex;
|
---|
209 | int mAniso;
|
---|
210 |
|
---|
211 | float mMoveScale;
|
---|
212 | Degree mRotScale;
|
---|
213 | // just to stop toggles flipping too fast
|
---|
214 | Real mTimeDelay;
|
---|
215 | Radian mRotX, mRotY;
|
---|
216 | TextureFilterOptions mFiltering;
|
---|
217 |
|
---|
218 | Real mMoveSpeed;
|
---|
219 | Degree mRotateSpeed;
|
---|
220 |
|
---|
221 | Overlay* mDebugOverlay;
|
---|
222 | Overlay* mHelpOverlay;
|
---|
223 | Overlay* mCullStatsOverlay;
|
---|
224 | Overlay* mQueryOverlay;
|
---|
225 |
|
---|
226 | Light *mSunLight;
|
---|
227 | GtpVisibility::VisibilityManager *mVisibilityManager;
|
---|
228 | EventProcessor* mEventProcessor;
|
---|
229 |
|
---|
230 | bool mShiftPressed;
|
---|
231 | bool mShowQueryStats;
|
---|
232 |
|
---|
233 | unsigned long mAvgFps;
|
---|
234 | unsigned long mFrameCount;
|
---|
235 | //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
|
---|
236 | PlatformQueryManager *mQueryManager;
|
---|
237 | };
|
---|
238 |
|
---|
239 |
|
---|
240 | #endif //_TerrainFrameListener_H__ |
---|