[1163] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | You may use this sample code for anything you like, it is not covered by the
|
---|
| 11 | LGPL like the rest of the engine.
|
---|
| 12 | -----------------------------------------------------------------------------
|
---|
| 13 | */
|
---|
| 14 | /*
|
---|
| 15 | -----------------------------------------------------------------------------
|
---|
| 16 | Filename: ExampleFrameListener.h
|
---|
| 17 | Description: Defines an example frame listener which responds to frame events.
|
---|
| 18 | This frame listener just moves a specified camera around based on
|
---|
| 19 | keyboard and mouse movements.
|
---|
| 20 | Mouse: Freelook
|
---|
| 21 | W or Up: Forward
|
---|
| 22 | S or Down:Backward
|
---|
| 23 | A: Step left
|
---|
| 24 | D: 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 |
|
---|
[1220] | 38 | #include <Ogre.h>
|
---|
| 39 | #include <OgreKeyEvent.h>
|
---|
| 40 | #include <OgreEventListeners.h>
|
---|
| 41 | #include <OgreStringConverter.h>
|
---|
| 42 | #include <OgreException.h>
|
---|
[1258] | 43 | #include <OgreTextAreaOverlayElement.h>
|
---|
[1163] | 44 |
|
---|
[1220] | 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)
|
---|
[1187] | 49 | #define VIZ_VIEWPORT_Z_ORDER 10
|
---|
| 50 |
|
---|
[1273] | 51 | #define TERRAIN_SCENE "terrain"
|
---|
| 52 |
|
---|
[1163] | 53 | using namespace Ogre;
|
---|
| 54 |
|
---|
[1202] | 55 | struct 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 |
|
---|
| 66 | typedef std::list<FrameInfo> FrameList;
|
---|
| 67 |
|
---|
[1285] | 68 | class KdTreeApp;
|
---|
| 69 |
|
---|
[1163] | 70 | class KdTreeAppListener: public FrameListener, public KeyListener
|
---|
| 71 | {
|
---|
[1204] | 72 |
|
---|
| 73 | public:
|
---|
| 74 | // visualization modes for scene nodes
|
---|
| 75 | enum VizMode
|
---|
| 76 | {
|
---|
| 77 | NODEVIZ_NONE,
|
---|
| 78 | NODEVIZ_RENDER_NODES,
|
---|
| 79 | NODEVIZ_RENDER_NODES_AND_CONTENT,
|
---|
| 80 | NODEVIZ_MODES_NUM
|
---|
| 81 | };
|
---|
| 82 |
|
---|
[1296] | 83 | enum SceneType
|
---|
| 84 | {
|
---|
| 85 | ST_SIMPLE,
|
---|
| 86 | ST_TERRAIN,
|
---|
| 87 | ST_GEOMETRY
|
---|
| 88 | };
|
---|
| 89 |
|
---|
[1220] | 90 | enum SceneMgr
|
---|
| 91 | {
|
---|
| 92 | SM_KDT,
|
---|
[1273] | 93 | SM_KTE,
|
---|
[1220] | 94 | SM_OCM,
|
---|
| 95 | SM_OCT,
|
---|
[1273] | 96 | SM_TER,
|
---|
[1220] | 97 | SM_GEN,
|
---|
| 98 | SM_SIZE,
|
---|
| 99 | SM_NOTSET
|
---|
| 100 | };
|
---|
| 101 |
|
---|
[1300] | 102 | enum ViewCellsMode
|
---|
| 103 | {
|
---|
| 104 | VCM_OFF,
|
---|
| 105 | VCM_ON,
|
---|
| 106 | VCM_FILTER,
|
---|
| 107 | VCM_SIZE,
|
---|
| 108 | VCM_NOTSET
|
---|
| 109 | };
|
---|
| 110 |
|
---|
[1211] | 111 | enum ShowTree
|
---|
| 112 | {
|
---|
| 113 | SHOWTREE_OFF,
|
---|
| 114 | SHOWTREE_HILITE,
|
---|
| 115 | SHOWTREE_ALL,
|
---|
| 116 | SHOWTREE_MODES_NUM
|
---|
| 117 | };
|
---|
| 118 |
|
---|
[1204] | 119 | enum AppState
|
---|
| 120 | {
|
---|
| 121 | AS_NORMAL,
|
---|
| 122 | AS_RECORD,
|
---|
| 123 | AS_PLAYBACK
|
---|
| 124 | };
|
---|
| 125 |
|
---|
| 126 | struct Options
|
---|
| 127 | {
|
---|
| 128 | Options():
|
---|
| 129 | mRotateSpeed(36.0f),
|
---|
| 130 | mMoveSpeed(100.0f),
|
---|
| 131 | mRotationPeriod(30.0f),
|
---|
| 132 | mKT(2.0f),
|
---|
| 133 | mKI(1.0f),
|
---|
[1220] | 134 | mMaxDepth(12),
|
---|
| 135 | mSceneManager(SM_KDT),
|
---|
| 136 | mRenderMethod(KdTree::KDRM_GTP_CHC),
|
---|
| 137 | mBuildMethod(KdTree::KDBM_PRIORITYQUEUE),
|
---|
[1296] | 138 | mSceneType(ST_SIMPLE),
|
---|
[1300] | 139 | mViewCells(VCM_OFF),
|
---|
[1296] | 140 | mFastStart(false),
|
---|
| 141 | mBurnIn(false),
|
---|
[1220] | 142 | mDemoMode(false),
|
---|
[1250] | 143 | mEnhancedVisibility(false),
|
---|
[1285] | 144 | mDemoInterval(1.0f),
|
---|
| 145 | myApp(0)
|
---|
[1204] | 146 | {
|
---|
| 147 |
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[1285] | 150 | String mSceneOutfileName;
|
---|
[1204] | 151 | String mDemoInfileName;
|
---|
| 152 | String mDemoOutfileName;
|
---|
| 153 | String mDemoLogfileName;
|
---|
[1220] | 154 | String mComment;
|
---|
[1204] | 155 | Degree mRotateSpeed;
|
---|
| 156 | Real mMoveSpeed;
|
---|
| 157 | Real mRotationPeriod;
|
---|
| 158 | Real mKT;
|
---|
| 159 | Real mKI;
|
---|
[1220] | 160 | int mMaxDepth;
|
---|
| 161 | int mSceneManager;
|
---|
| 162 | int mRenderMethod;
|
---|
| 163 | int mBuildMethod;
|
---|
[1296] | 164 | int mSceneType;
|
---|
[1300] | 165 | int mViewCells;
|
---|
[1296] | 166 | bool mFastStart;
|
---|
| 167 | bool mBurnIn;
|
---|
[1220] | 168 | bool mDemoMode;
|
---|
| 169 | bool mEnhancedVisibility;
|
---|
[1250] | 170 | Real mDemoInterval;
|
---|
[1285] | 171 | KdTreeApp *myApp;
|
---|
[1204] | 172 | };
|
---|
| 173 |
|
---|
[1250] | 174 | struct DemoStats
|
---|
| 175 | {
|
---|
| 176 | unsigned int mTotalNumFrames;
|
---|
| 177 | unsigned int mNumFrames;
|
---|
| 178 | Real mTotalEllapsedTime;
|
---|
| 179 | Real mEllapsedTime;
|
---|
| 180 | } mDemoStats;
|
---|
| 181 |
|
---|
[1204] | 182 | // Constructor takes a RenderWindow because it uses that to determine input context
|
---|
| 183 | KdTreeAppListener(RenderWindow* win, SceneManager* sm, const Options& options,
|
---|
| 184 | bool useBufferedInputKeys = false, bool useBufferedInputMouse = false);
|
---|
| 185 |
|
---|
[1211] | 186 | virtual ~KdTreeAppListener(void);
|
---|
[1204] | 187 |
|
---|
| 188 | void initOverlayElement(OverlayElement **elInfo, String ext,
|
---|
| 189 | String name, int top, String caption);
|
---|
| 190 |
|
---|
[1211] | 191 | void initStatsOverlay(void);
|
---|
[1204] | 192 |
|
---|
[1211] | 193 | void initKdTreeOverlay(void);
|
---|
[1204] | 194 |
|
---|
| 195 | void showDebugOverlay(bool show);
|
---|
| 196 |
|
---|
[1296] | 197 | void toggleUseViewCells(void);
|
---|
| 198 |
|
---|
| 199 | void toggleUseVisibilityFilter(void);
|
---|
| 200 |
|
---|
[1211] | 201 | void toggleVizCamera(void);
|
---|
[1204] | 202 |
|
---|
[1211] | 203 | void toggleShowBoxes(void);
|
---|
| 204 |
|
---|
| 205 | void toggleEnhancedVisibility(void);
|
---|
| 206 |
|
---|
| 207 | void toggleBuildMethod(void);
|
---|
| 208 |
|
---|
| 209 | void toggleRenderMethod(void);
|
---|
| 210 |
|
---|
[1204] | 211 | virtual bool processUnbufferedKeyInput(const FrameEvent& evt);
|
---|
| 212 |
|
---|
| 213 | bool processUnbufferedMouseInput(const FrameEvent& evt);
|
---|
| 214 |
|
---|
[1211] | 215 | void moveCamera(void);
|
---|
[1204] | 216 |
|
---|
| 217 | // Override frameStarted event to process that (don't care about frameEnded)
|
---|
| 218 | bool frameStarted(const FrameEvent& evt);
|
---|
| 219 |
|
---|
| 220 | bool frameEnded(const FrameEvent& evt);
|
---|
| 221 |
|
---|
[1211] | 222 | void switchMouseMode(void);
|
---|
[1204] | 223 |
|
---|
[1211] | 224 | void switchKeyMode(void);
|
---|
[1204] | 225 |
|
---|
| 226 | void keyClicked(KeyEvent* e);
|
---|
| 227 |
|
---|
| 228 | void keyPressed(KeyEvent* e) {};
|
---|
| 229 | void keyReleased(KeyEvent* e) {};
|
---|
| 230 |
|
---|
[1220] | 231 | const static Real DEMO_WAIT;
|
---|
[1211] | 232 | const static String NA;
|
---|
[1220] | 233 | const static String RENDERMETHOD[];
|
---|
| 234 | const static String RENDERMETHODCAPTION[];
|
---|
| 235 | const static String BUILDMETHOD[];
|
---|
| 236 | const static String BUILDMETHODCAPTION[];
|
---|
| 237 | const static String SCENEMANAGER[];
|
---|
| 238 | const static String SCENEMANAGERNAME[];
|
---|
[1163] | 239 | protected:
|
---|
[1204] | 240 | // basic
|
---|
| 241 | RenderWindow* mWindow;
|
---|
| 242 | SceneManager *mSceneMgr;
|
---|
| 243 | Options mOptions;
|
---|
| 244 | bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
|
---|
| 245 |
|
---|
| 246 | // elements
|
---|
| 247 | SceneNode *mCamNode;
|
---|
| 248 | Camera* mCamera;
|
---|
| 249 | Camera* mTopCam;
|
---|
| 250 |
|
---|
| 251 | // toggle
|
---|
| 252 | bool mStatsOn;
|
---|
| 253 |
|
---|
| 254 | bool mVizCamera;
|
---|
[1170] | 255 | bool mFreeMove;
|
---|
[1195] | 256 | bool mTopCamFollow;
|
---|
[1163] | 257 |
|
---|
[1211] | 258 | int mShowTree;
|
---|
| 259 |
|
---|
[1296] | 260 | // view cells
|
---|
[1300] | 261 | bool mViewCellsLoaded;
|
---|
[1296] | 262 | bool mUseViewCells;
|
---|
| 263 | bool mUseVisibilityFilter;
|
---|
| 264 |
|
---|
[1204] | 265 | // counters
|
---|
| 266 | int mSeqNum;
|
---|
| 267 | unsigned int mNumScreenShots;
|
---|
| 268 |
|
---|
| 269 | // rendering/texture options
|
---|
| 270 | int mSceneDetailIndex;
|
---|
| 271 | TextureFilterOptions mFiltering;
|
---|
| 272 | int mAniso;
|
---|
| 273 |
|
---|
| 274 | // chc stats
|
---|
[1183] | 275 | Real mDelayedQueriesIssued;
|
---|
| 276 | Real mDelayedTraversedNodes;
|
---|
| 277 |
|
---|
[1204] | 278 | // overlays
|
---|
| 279 | Overlay *mDemoOverlay;
|
---|
| 280 | Overlay *mDebugOverlay;
|
---|
| 281 | Overlay *mKdTreeOverlay;
|
---|
[1300] | 282 | Overlay *mLoadingOverlay;
|
---|
[1163] | 283 |
|
---|
[1300] | 284 | OverlayElement *mMyLoadingInfo;
|
---|
[1204] | 285 | OverlayElement *mDemoStatus;
|
---|
[1258] | 286 | TextAreaOverlayElement *mDemoTime;
|
---|
[1274] | 287 | TextAreaOverlayElement *mDemoFPSDisp;
|
---|
[1183] | 288 |
|
---|
[1211] | 289 | OverlayElement *mRenderMethodInfo;
|
---|
| 290 | OverlayElement *mEnhancedVisInfo;
|
---|
| 291 | OverlayElement *mBuildMethodInfo;
|
---|
[1183] | 292 | OverlayElement *mKdTreeMaxDepthInfo;
|
---|
[1211] | 293 | OverlayElement *mHighlightLevelInfo;
|
---|
[1183] | 294 | OverlayElement *mKTInfo;
|
---|
| 295 | OverlayElement *mKIInfo;
|
---|
| 296 | OverlayElement *mMovementInfo;
|
---|
[1195] | 297 | OverlayElement *mTopCamInfo;
|
---|
[1296] | 298 | OverlayElement *mViewCellsInfo;
|
---|
| 299 | OverlayElement *mViewFilterInfo;
|
---|
[1183] | 300 |
|
---|
| 301 | OverlayElement *mFrustumCulledNodesInfo;
|
---|
| 302 | OverlayElement *mQueryCulledNodesInfo;
|
---|
| 303 | OverlayElement *mTraversedNodesInfo;
|
---|
| 304 | OverlayElement *mHierarchyNodesInfo;
|
---|
| 305 | OverlayElement *mRenderedNodesInfo;
|
---|
| 306 | OverlayElement *mObjectsCountInfo;
|
---|
| 307 | OverlayElement *mQueriesIssuedInfo;
|
---|
| 308 |
|
---|
[1204] | 309 | // input
|
---|
[1187] | 310 | EventProcessor* mEventProcessor;
|
---|
| 311 | InputReader* mInputDevice;
|
---|
[1183] | 312 |
|
---|
[1204] | 313 | // movement
|
---|
[1187] | 314 | Vector3 mTranslateVector;
|
---|
[1204] | 315 | Vector3 mVizCamTransVect;
|
---|
| 316 | Radian mRotX, mRotY;
|
---|
[1187] | 317 | float mMoveScale;
|
---|
| 318 | Degree mRotScale;
|
---|
[1204] | 319 | Radian mDeathAngle;
|
---|
[1273] | 320 | // for terrain
|
---|
| 321 | RaySceneQuery *mRaySceneQuery;
|
---|
[1204] | 322 |
|
---|
[1187] | 323 | // just to stop toggles flipping too fast
|
---|
| 324 | Real mTimeUntilNextToggle ;
|
---|
[1163] | 325 |
|
---|
[1195] | 326 | // stuff for walkthrough recording/playback
|
---|
[1204] | 327 | //std::ofstream mDemoFramesLog;
|
---|
| 328 | std::list<Real> mDemoFPS;
|
---|
| 329 | Real mTimeUntilNextLogWrite;
|
---|
[1195] | 330 | FrameList mFrameList;
|
---|
[1200] | 331 | FrameList::iterator mCurrFrame;
|
---|
| 332 | Real mTimeRemaining;
|
---|
[1204] | 333 | Real mWaitBeforeDemoStart;
|
---|
[1195] | 334 |
|
---|
| 335 | AppState mAppState;
|
---|
| 336 |
|
---|
[1202] | 337 | void setDemoOverlay();
|
---|
| 338 |
|
---|
[1195] | 339 | void toggleRecord();
|
---|
| 340 | void togglePlayback();
|
---|
[1200] | 341 |
|
---|
[1205] | 342 | /** write FPS stats to log file (csv) **/
|
---|
| 343 | void saveLog();
|
---|
| 344 |
|
---|
[1195] | 345 | void saveFrameInfo(Real elapsedTime);
|
---|
[1204] | 346 |
|
---|
[1202] | 347 | /** save demo frame data to file **/
|
---|
| 348 | static void saveFrames(const String& filename, FrameList& framelist);
|
---|
| 349 | static void saveFramesAscii(const String& filename, FrameList& framelist);
|
---|
| 350 | static void saveFramesBinary(const String& filename, FrameList& framelist);
|
---|
[1195] | 351 |
|
---|
[1202] | 352 | /** load demo frame data from file **/
|
---|
| 353 | static void loadFrames(const String& filename, FrameList& framelist);
|
---|
| 354 | static void loadFramesAscii(const String& filename, FrameList& framelist);
|
---|
| 355 | static void loadFramesBinary(const String& filename, FrameList& framelist);
|
---|
[1200] | 356 |
|
---|
[1204] | 357 | void updateStats(void);
|
---|
[1163] | 358 | };
|
---|
| 359 |
|
---|
| 360 | #endif
|
---|
| 361 |
|
---|