- Timestamp:
- 07/08/05 17:34:05 (19 years ago)
- Location:
- trunk/VUT
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/Ogre/include/OgreTerrainContentGenerator.h
r135 r161 4 4 #include "OgreSceneContentGenerator.h" 5 5 //#include <Ogre.h> 6 7 #define MAX_HEIGHT 5000 // maximal possible height for object position 6 8 7 9 namespace Ogre { … … 23 25 24 26 /** 25 Class which randomly fills a terrain with objects. 27 Thsi class used to fill a terrain with content, 28 e.g., it randomly fills a terrain with objects of a specific type. 26 29 */ 27 30 class __declspec(dllexport) TerrainContentGenerator: public SceneContentGenerator … … 31 34 ~TerrainContentGenerator(); 32 35 33 /** 34 Generates objects and places it on the terrain. 36 /** Generates objects and places it on the terrain. 35 37 */ 36 38 SceneNode *GenerateSceneObject(const Vector3 &position, 37 39 const Vector3 &rotation, const String &objName); 38 /** 39 Generates objects and optionally places it on the terrain. 40 /** Generates objects and optionally places it on the terrain. 40 41 @param clampToTerrain if true, scene object is clamped to the terrain 41 42 */ … … 43 44 const Vector3 &rotation, const String &objName, const bool clampToTerrain); 44 45 45 /** offset which is added to objects when put into the terrain */ 46 /** The offset is added to objects when they are put into the terrain. 47 */ 46 48 void SetOffset(Real offset); 47 48 RayQueryExecutor *GetRayQueryExecutor();49 49 50 50 protected: -
trunk/VUT/Ogre/resources/VisibilityDemo.overlay
r160 r161 326 326 caption [F4] Start / End frame recording 327 327 } 328 element TextArea(Example/Visibility/Help/Animation): Example/Visibility/Templates/BasicText 329 { 330 left 5 331 width 180 332 height 30 333 caption [F9] Start / End animation 334 } 328 335 element TextArea(Example/Visibility/Help/Screenshots): Example/Visibility/Templates/BasicText 329 336 { -
trunk/VUT/Ogre/src/OgreTerrainContentGenerator.cpp
r135 r161 1 1 #include "OgreTerrainContentGenerator.h" 2 2 3 #define MAX_HEIGHT 5000 // maximal possible height4 3 5 4 namespace Ogre { … … 69 68 SceneNode *TerrainContentGenerator::GenerateSceneObject(const Vector3 &position, 70 69 const Vector3 &rotation, const String& objName, const bool clampToTerrain) 71 { 70 { 71 if (clampToTerrain) 72 return GenerateSceneObject(position, rotation, objName); 72 73 73 if (clampToTerrain) 74 { 75 return GenerateSceneObject(position, rotation, objName); 76 } 77 else 78 { 79 return SceneContentGenerator::GenerateSceneObject(position, rotation, objName); 80 } 74 return SceneContentGenerator::GenerateSceneObject(position, rotation, objName); 81 75 } 82 76 //----------------------------------------------------------------------- … … 103 97 } 104 98 //----------------------------------------------------------------------- 105 RayQueryExecutor *TerrainContentGenerator::GetRayQueryExecutor()106 {107 return mRayQueryExecutor;108 }109 //-----------------------------------------------------------------------110 99 void TerrainContentGenerator::SetOffset(Real offset) 111 100 { -
trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
r160 r161 58 58 0.07 59 59 }; 60 60 61 //----------------------------------------------------------------------- 61 62 TerrainFrameListener::TerrainFrameListener(RenderWindow* win, Camera* cam, … … 118 119 mRenderPatchesForItemBuffer(false), 119 120 mCurrentObjectType(0), 120 mApplication(app) 121 mApplication(app), 122 mUseAnimation(false) 121 123 { 122 124 //mInputDevice = PlatformManager::getSingleton().createInputReader(); … … 203 205 //Vector3 queryResult; mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay); 204 206 207 Real val = Math::RangeRandom(0, 360); // random rotation 205 208 // get results, create a node/entity on the position 206 209 mCurrentObject = mTerrainContentGenerator->GenerateSceneObject( 207 mouseRay.getOrigin()/*queryResult*/, Vector3 ::ZERO,210 mouseRay.getOrigin()/*queryResult*/, Vector3(val, 0, 0), 208 211 mApplication->getCurrentObjectCaption(mCurrentObjectType)); 209 212 210 if (mCurrentObjectType == 0) // only robot has animation phases211 {212 Entity *ent = mTerrainContentGenerator->GetGeneratedEntities()->back();213 AnimationState *st = ent->getAnimationState("Walk");214 215 st->setLoop(true);216 st->setEnabled(true);217 218 mApplication->getAnimationStates().push_back(st);219 mApplication->getAnimationSpeed().push_back(Math::RangeRandom(0.5, 1.5));220 }221 222 213 mLMouseDown = true; 223 214 } … … 228 219 mRMouseDown = true; 229 220 } 230 } 231 //----------------------------------------------------------------------- 232 void TerrainFrameListener::mouse Released(MouseEvent* e)233 { 234 221 } 222 //----------------------------------------------------------------------- 223 void TerrainFrameListener::mouseDragDropped(MouseEvent* e) 224 { 225 // Left mouse button up 235 226 if (e->getButtonID() & InputEvent::BUTTON0_MASK) 236 227 { 237 228 CEGUI::MouseCursor::getSingleton().show(); 238 mLMouseDown = false; 229 230 mLMouseDown = false; 239 231 } 240 232 // Right mouse button up … … 242 234 { 243 235 CEGUI::MouseCursor::getSingleton().show(); 236 237 mRMouseDown = false; 238 } 239 } 240 //----------------------------------------------------------------------- 241 void TerrainFrameListener::mouseReleased(MouseEvent* e) 242 { 243 // Left mouse button up 244 if (e->getButtonID() & InputEvent::BUTTON0_MASK) 245 { 246 CEGUI::MouseCursor::getSingleton().show(); 247 248 // start animation: only robot has animation phases 249 if (mCurrentObject && (mCurrentObjectType == TestCullingTerrainApplication::ROBOT)) 250 { 251 // HACK: not neccesary the last element 252 Entity *ent = mTerrainContentGenerator->GetGeneratedEntities()->back(); 253 EntityState *entState = new EntityState(ent, EntityState::MOVING, Math::RangeRandom(0.5, 1.5)); 254 mApplication->getEntityStates().push_back(entState); 255 } 256 257 mLMouseDown = false; 258 } 259 // Right mouse button up 260 else if (e->getButtonID() & InputEvent::BUTTON1_MASK) 261 { 262 CEGUI::MouseCursor::getSingleton().show(); 263 244 264 mRMouseDown = false; 245 265 } … … 251 271 if (mLMouseDown) 252 272 { 273 if (!mCurrentObject) 274 return; 275 253 276 Vector3 queryResult; 254 277 Ray mouseRay = mCamera->getCameraToViewportRay(e->getX(), e->getY()); … … 256 279 if (mRayQueryExecutor->executeRayQuery(&queryResult, mouseRay)) 257 280 { 258 if (mCurrentObject) 259 { 260 // apply offset so object is ON terrain 261 queryResult.y += currentObjectTerrainOffsets[mCurrentObjectType]; 262 263 mCurrentObject->setPosition(queryResult); 264 } 281 // apply offset so object is ON terrain 282 queryResult.y += currentObjectTerrainOffsets[mCurrentObjectType]; 283 mCurrentObject->setPosition(queryResult); 265 284 } 266 285 } … … 281 300 return false; 282 301 } 283 284 for (int i = 0; i < (int)mApplication->getAnimationStates().size(); ++i) 285 { 286 mApplication->getAnimationStates()[i]->addTime(evt.timeSinceLastFrame * 287 mApplication->getAnimationSpeed()[i]); 288 } 289 290 if (mDisplayCameraDetails) 291 { 292 // Print camera details 302 303 if (mUseAnimation) // update animations 304 { 305 mApplication->updateAnimations(evt.timeSinceLastFrame); 306 } 307 308 if (mDisplayCameraDetails) // Print camera details 309 { 293 310 mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + 294 311 " " + "O: " + StringConverter::toString(mCamera->getDerivedOrientation())); … … 369 386 // move camera according to input 370 387 moveCamera(); 388 371 389 // clamp camera so we always walk along the terrain 372 Clamp2Terrain();390 mApplication->Clamp2Terrain(mCamNode, 10); 373 391 break; 374 392 … … 524 542 delete mQueryManager; 525 543 } 526 //----------------------------------------------------------------------- 527 void TerrainFrameListener::Clamp2Terrain() 528 { 529 // clamp camera to terrain 530 Vector3 camPos = mCamNode->getPosition(); 531 Vector3 queryResult; 532 533 if (mRayQueryExecutor->executeRayQuery(&queryResult, 534 Vector3(camPos.x, 5000.0f, camPos.z), Vector3::NEGATIVE_UNIT_Y)) 535 { 536 const int terrainOffs = 10; 537 mCamNode->setPosition(camPos.x, queryResult.y + terrainOffs, camPos.z); 538 } 539 } 544 540 545 //----------------------------------------------------------------------- 541 546 bool TerrainFrameListener::frameEnded(const FrameEvent& evt) … … 771 776 //guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); 772 777 if (mTimeDelay < 0) // only update once per second 778 { 773 779 guiAvg->setCaption(avgFpsString + StringConverter::toString(avgFps) + " ms"); 780 } 781 774 782 guiCurr->setCaption(currFpsString + StringConverter::toString(stats.lastFPS)); 775 783 guiBest->setCaption(bestFpsString + StringConverter::toString(stats.bestFPS) … … 1025 1033 mApplication->generateScene(500, mCurrentObjectType); 1026 1034 break; 1027 1035 case KC_F9: 1036 toggleUseAnimation(); 1037 break; 1028 1038 case KC_F11: 1029 1039 takeScreenShot(); … … 1043 1053 break; 1044 1054 case KC_DELETE: 1055 mApplication->deleteEntityStates(); 1045 1056 mTerrainContentGenerator->RemoveGeneratedObjects(); 1046 mApplication->getAnimationStates().clear();1047 mApplication->getAnimationSpeed().clear();1048 1057 break; 1049 1058 //KEY_PRESSED(KC_F3, 0.3, writeFrames()); … … 1300 1309 initHelpOverlayElement("AppState", top); top += vert_space; 1301 1310 initHelpOverlayElement("Recorded", top); top += vert_space; 1311 initHelpOverlayElement("Animation", top); top += vert_space; 1302 1312 initHelpOverlayElement("Screenshots", top); top += vert_space; 1303 1313 initHelpOverlayElement("WriteOut", top); top += vert_space; … … 1358 1368 initOverlayElement(&mAssumedVisibilityInfo, ext, "AssumedVisibility", top, ": 0"); top += vert_space; 1359 1369 initOverlayElement(&mCurrentObjectTypeInfo, ext, "CurrentObjectType", top, ": "); top += vert_space; 1370 //initOverlayElement(&mHelpInfo, ext, "Help", top, ": "); top += vert_space; 1360 1371 1361 1372 OverlayElement *optionsPanel = OverlayManager::getSingleton(). … … 1404 1415 queryPanel->setHeight(top + border_height); 1405 1416 } 1417 //----------------------------------------------------------------------- 1418 void TerrainFrameListener::toggleUseAnimation() 1419 { 1420 mUseAnimation = !mUseAnimation; 1421 } -
trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
r160 r161 21 21 #define VIZ_VIEWPORT_Z_ORDER 10 22 22 23 24 /** Mouse query listener for terrain 23 /** Frame listener specialised for terrains. 25 24 */ 26 class TerrainFrameListener: public FrameListener, public MouseListener, public MouseMotionListener, public KeyListener 25 class TerrainFrameListener: public FrameListener, public MouseListener, 26 public MouseMotionListener, public KeyListener 27 27 { 28 28 public: … … 52 52 53 53 // This is when the mouse button goes DOWN. 54 v irtual void mousePressed(MouseEvent* e);54 void mousePressed(MouseEvent* e); 55 55 56 56 // This is when the mouse button is let UP. 57 v irtual void mouseReleased(MouseEvent* e);57 void mouseReleased(MouseEvent* e); 58 58 59 59 /* MouseMotionListener callbacks */ 60 v irtual void mouseMoved(MouseEvent *e);60 void mouseMoved(MouseEvent *e); 61 61 62 62 // This is when the mouse is clicked, held and dragged. 63 virtual void mouseDragged (MouseEvent *e); 64 63 void mouseDragged(MouseEvent *e); 64 65 void mouseDragDropped(MouseEvent *e); 65 66 void keyPressed(KeyEvent* e); 66 67 … … 68 69 void keyClicked(KeyEvent* e); 69 70 70 /** The information about camera position and orienation per frame */ 71 /** The information about camera position and orienation per frame. 72 */ 71 73 typedef struct 72 74 { … … 123 125 void toggleShowViz(); 124 126 void toggleRecord(); 127 void toggleUseAnimation(); 125 128 126 129 /** Applies visibility query. Collects the visible objects … … 150 153 151 154 void resetStats(); 152 153 /** Clamp camera to terrain.154 */155 void Clamp2Terrain();156 155 157 156 SceneManager *mSceneMgr; // A pointer to the scene manager … … 198 197 OverlayElement *mQueryGeometryVisibilityInfo; 199 198 OverlayElement *mQueryPatchVisibilityInfo; 199 //OverlayElement *mHelpInfo; 200 200 201 201 RayQueryExecutor *mRayQueryExecutor; … … 216 216 bool mDisplayCameraDetails; 217 217 bool mUseItemBuffer; 218 bool mUseAnimation; 219 bool mRenderPatchesForItemBuffer; 218 220 219 221 Real mVizCameraHeight; … … 268 270 float mDelayedTraversedNodes; 269 271 270 bool mRenderPatchesForItemBuffer;271 272 272 int mCurrentObjectType; 273 273 -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
r160 r161 7 7 8 8 #include <Ogre.h> 9 9 10 //#include "OgreReferenceAppLayer.h" 10 11 //#include "OgreRefAppWorld.h" … … 23 24 }; 24 25 26 /***************************************/ 27 /* EntityState implementation */ 28 /***************************************/ 29 EntityState::EntityState(Entity *ent, State entityState, Real speed): 30 mEntity(ent), mState(entityState), mAnimationSpeed(speed) 31 { 32 switch(entityState) 33 { 34 case MOVING: 35 mAnimationState = mEntity->getAnimationState("Walk"); 36 break; 37 case WAITING: 38 mAnimationState = mEntity->getAnimationState("Idle"); 39 break; 40 case STOP: 41 mAnimationState = NULL; 42 break; 43 default: 44 break; 45 } 46 // enable animation state 47 if (mAnimationState) 48 { 49 mAnimationState->setLoop(true); 50 mAnimationState->setEnabled(true); 51 } 52 mTimeElapsed = Math::RangeRandom(1, 5); 53 } 54 //----------------------------------------------------------------------- 55 Entity *EntityState::GetEntity() 56 { 57 return mEntity; 58 } 59 //----------------------------------------------------------------------- 60 EntityState::State EntityState::GetState() 61 { 62 return mState; 63 } 64 //----------------------------------------------------------------------- 65 void EntityState::update(Real timeSinceLastFrame) 66 { 67 mTimeElapsed -= timeSinceLastFrame * mAnimationSpeed; 68 69 if (mState == MOVING) // toggle between moving (longer) and waiting (short) 70 { 71 SceneNode *parent = mEntity->getParentSceneNode(); 72 73 if (mTimeElapsed <= 0) // toggle animation state 74 { 75 if (mAnimationState->getAnimationName() == "Idle") 76 { 77 SetAnimationState("Walk", true); 78 mTimeElapsed = 10; // walk for mTimeElapsed units 79 80 // choose random direction between zero and two pi 81 Radian rnd = Radian(Math::UnitRandom() * Math::HALF_PI); 82 83 //mEntity->getParentSceneNode()->rotate(); 84 parent->yaw(rnd); 85 } 86 else 87 { 88 SetAnimationState("Idle", true); 89 mTimeElapsed = 2; // wait for mTimeElapsed seconds 90 } 91 } 92 93 if (mAnimationState->getAnimationName() == "Walk") 94 { 95 Vector3 oldPos = parent->getPosition(); 96 97 parent->translate(parent->getLocalAxes(), Vector3(0.03 * mAnimationSpeed, 0, 0)); 98 99 // HACK: if out of bounds => go back to idle 100 if (OutOfBounds(parent)) 101 { 102 parent->setPosition(oldPos); 103 SetAnimationState("Idle); 104 105 mTimeElapsed = 2; 106 } 107 } 108 } 109 110 if (mAnimationState) // add time to drive animation 111 { 112 mAnimationState->addTime(timeSinceLastFrame * mAnimationSpeed); 113 } 114 } 115 //----------------------------------------------------------------------- 116 void EntityState::SetAnimationState(String stateStr, bool loop) 117 { 118 mAnimationState = mEntity->getAnimationState(stateStr); 119 mAnimationState->setLoop(loop); 120 mAnimationState->setEnabled(true); 121 } 122 //----------------------------------------------------------------------- 123 bool EntityState::OutOfBounds(SceneNode *node) 124 { 125 Vector3 pos = node->getPosition(); 126 127 if ((pos > msMinPos) && (pos < msMaxPos)) 128 return true; 129 130 return false; 131 } 25 132 /*********************************************************/ 26 133 /* TestCullingTerrainApplication implementation */ … … 35 142 TestCullingTerrainApplication::~TestCullingTerrainApplication() 36 143 { 37 if (mTerrainContentGenerator) 38 { 39 delete mTerrainContentGenerator; 40 mTerrainContentGenerator = NULL; 41 } 144 OGRE_DELETE(mTerrainContentGenerator); 145 OGRE_DELETE(mRayQueryExecutor); 146 deleteEntityStates(); 147 } 148 //----------------------------------------------------------------------- 149 void TestCullingTerrainApplication::deleteEntityStates() 150 { 151 for (int i = 0; i < (int)mEntityStates.size(); ++i) 152 { 153 delete mEntityStates[i]; 154 mEntityStates[i] = NULL; 155 } 156 mEntityStates.clear(); 42 157 } 43 158 //----------------------------------------------------------------------- … … 133 248 mSceneMgr->setWorldGeometry(terrain_cfg); 134 249 250 // ray query executor 251 mRayQueryExecutor = new RayQueryExecutor(mSceneMgr); 252 135 253 //-- CEGUI setup 136 254 setupGui(); … … 185 303 186 304 //-- add animation state for new robots (located at the end of the list) 187 for (int i = entList->size() - num; i < entList->size(); ++i) 188 { 189 Entity *ent = (*entList)[i]; 190 AnimationState *st = ent->getAnimationState("Idle"); 191 st->setEnabled(true); 192 st->setLoop(true); 193 194 mAnimationStates.push_back(st); 195 mAnimationSpeed.push_back(Math::RangeRandom(0.5, 1.5)); 196 } 197 } 198 //----------------------------------------------------------------------- 199 std::vector<AnimationState *> &TestCullingTerrainApplication::getAnimationStates() 200 { 201 return mAnimationStates; 202 } 203 //----------------------------------------------------------------------- 204 std::vector<Real> &TestCullingTerrainApplication::getAnimationSpeed() 205 { 206 return mAnimationSpeed; 305 for (int i = entList->size() - num; i < (int)entList->size(); ++i) 306 { 307 mEntityStates.push_back(new EntityState((*entList)[i], 308 EntityState::WAITING, Math::RangeRandom(0.5, 1.5))); 309 } 310 } 311 //----------------------------------------------------------------------- 312 void TestCullingTerrainApplication::updateAnimations(Real timeSinceLastFrame) 313 { 314 for (int i = 0; i < (int)mEntityStates.size(); ++i) 315 { 316 SceneNode *sm = mEntityStates[i]->GetEntity()->getParentSceneNode(); 317 318 mEntityStates[i]->update(timeSinceLastFrame); 319 320 if (mEntityStates[i]->GetState() == EntityState::MOVING) 321 { 322 Clamp2Terrain(sn, 0); 323 //sm->setNodeVisible(false); 324 } 325 } 326 } 327 //----------------------------------------------------------------------- 328 EntityStates &TestCullingTerrainApplication::getEntityStates() 329 { 330 return mEntityStates; 207 331 } 208 332 //----------------------------------------------------------------------- … … 239 363 mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE); 240 364 } 365 //----------------------------------------------------------------------- 366 bool TestCullingTerrainApplication::Clamp2Terrain(SceneNode *node, int terrainOffs) 367 { 368 // clamp scene node to terrain 369 Vector3 pos = node->getPosition(); 370 Vector3 queryResult; 371 372 if (mRayQueryExecutor->executeRayQuery(&queryResult, 373 Vector3(pos.x, MAX_HEIGHT, pos.z), Vector3::NEGATIVE_UNIT_Y)) 374 { 375 node->setPosition(pos.x, queryResult.y + terrainOffs, pos.z); 376 return true; 377 } 378 379 return false; 380 } 381 382 241 383 /**************************************************************/ 242 384 /* VisualizationRenderTargetListener implementation */ -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
r160 r161 8 8 #include "OgreTerrainContentGenerator.h" 9 9 #include "TerrainFrameListener.h" 10 11 #include <OgreEntity.h> 10 12 11 13 class VisualizationRenderTargetListener: public RenderTargetListener … … 24 26 }; 25 27 28 /** Class storing the current state of an entity. 29 */ 30 class EntityState 31 { 32 public: 33 enum State {STOP, WAITING, MOVING}; 34 35 EntityState(Entity *ent, State entityState, Real speed); 36 37 /** Update the entity state. 38 */ 39 void update(Real timeSinceLastFrame); 40 41 /** Returns entity. 42 */ 43 Entity *GetEntity(); 44 45 /** Returns entity state index. 46 */ 47 EntityState::State GetState(); 48 49 protected: 50 51 void SetAnimationState(String stateStr, bool loop); 52 53 AnimationState *mAnimationState; 54 Entity *mEntity; 55 56 State mState; 57 Real mAnimationSpeed; 58 Real mTimeElapsed; 59 }; 60 61 typedef std::vector<EntityState *> EntityStates; 26 62 27 63 class TestCullingTerrainApplication: public ExampleApplication … … 31 67 ~TestCullingTerrainApplication(); 32 68 69 /** Generates a scene using num entities of a type. 70 @param num the number of objects 71 @parma objectType the type of objects 72 */ 33 73 void generateScene(int num, int objectType); 34 74 75 /** Returns the caption of the given id of a scene object type. 76 */ 35 77 String getCurrentObjectCaption(int id); 36 78 37 std::vector<AnimationState *> &getAnimationStates(); 38 std::vector<Real> &getAnimationSpeed(); 79 /** Returns state vector of scene entities. 80 */ 81 EntityStates &getEntityStates(); 82 83 /** Updates all animations according to time elapsed since last frame. 84 */ 85 void updateAnimations(Real timeSinceLastFrame); 86 87 /** Deletes vector of scene entity states. 88 */ 89 void deleteEntityStates(); 90 91 // object types 92 enum {ROBOT, ATHENA, NINJA}; 93 94 95 /** Clamps scene node to terrain. 96 @param sceneNode the node to be clamped 97 @param terrainOffs the offset of the node over the terrain 98 @returns if clamping was successful (i.e., the ray hit the terrain) 99 */ 100 bool Clamp2Terrain(SceneNode *node, int terrainOffs); 39 101 40 102 protected: … … 49 111 virtual void createRenderTargetListener(); 50 112 51 std::vector<AnimationState *> mAnimationStates; 52 std::vector<Real> mAnimationSpeed; 113 std::vector<EntityState *> mEntityStates; 53 114 54 /** cegui setup */ 115 /** cegui setup 116 */ 55 117 void setupGui(); 56 118 … … 72 134 TerrainFrameListener *mTerrainFrameListener; 73 135 ColourValue mAmbientLight; 74 136 RayQueryExecutor *mRayQueryExecutor; 137 75 138 private: 76 139 void chooseSceneManager(void);
Note: See TracChangeset
for help on using the changeset viewer.