Changeset 164 for trunk/VUT/work
- Timestamp:
- 07/11/05 03:25:50 (20 years ago)
- Location:
- trunk/VUT/work/TestCullingTerrain
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
r161 r164 120 120 mCurrentObjectType(0), 121 121 mApplication(app), 122 mUseAnimation(false) 122 mUseAnimation(false), 123 mDeleteObjects(false) 123 124 { 124 125 //mInputDevice = PlatformManager::getSingleton().createInputReader(); … … 206 207 207 208 Real val = Math::RangeRandom(0, 360); // random rotation 209 208 210 // get results, create a node/entity on the position 209 211 mCurrentObject = mTerrainContentGenerator->GenerateSceneObject( … … 301 303 } 302 304 305 if (mDeleteObjects) 306 { 307 mApplication->deleteEntityStates(); 308 mTerrainContentGenerator->RemoveGeneratedObjects(); 309 mDeleteObjects = false; 310 } 311 303 312 if (mUseAnimation) // update animations 304 313 { … … 1034 1043 break; 1035 1044 case KC_F9: 1036 toggleUseAnimation();1045 mUseAnimation = !mUseAnimation; 1037 1046 break; 1038 1047 case KC_F11: 1039 takeScreen Shot();1048 takeScreenshot(); 1040 1049 break; 1041 1050 case KC_F12: … … 1053 1062 break; 1054 1063 case KC_DELETE: 1055 mApplication->deleteEntityStates(); 1056 mTerrainContentGenerator->RemoveGeneratedObjects(); 1064 mDeleteObjects = true; 1057 1065 break; 1058 1066 //KEY_PRESSED(KC_F3, 0.3, writeFrames()); … … 1223 1231 } 1224 1232 //----------------------------------------------------------------------- 1225 void TerrainFrameListener::takeScreen Shot()1233 void TerrainFrameListener::takeScreenshot() 1226 1234 { 1227 1235 char tmp[20]; … … 1415 1423 queryPanel->setHeight(top + border_height); 1416 1424 } 1417 //-----------------------------------------------------------------------1418 void TerrainFrameListener::toggleUseAnimation()1419 {1420 mUseAnimation = !mUseAnimation;1421 } -
trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
r161 r164 112 112 void toggleShowShadows(); 113 113 void toggleDisplayCameraDetails(); 114 void takeScreen Shot();114 void takeScreenshot(); 115 115 void nextSceneDetailLevel(); 116 116 void nextFilter(); … … 125 125 void toggleShowViz(); 126 126 void toggleRecord(); 127 void toggleUseAnimation();128 127 129 128 /** Applies visibility query. Collects the visible objects … … 241 240 float mMoveScale; 242 241 Degree mRotScale; 242 243 243 // just to stop toggles flipping too fast 244 244 Real mTimeDelay; … … 272 272 int mCurrentObjectType; 273 273 274 bool mDeleteObjects; 275 274 276 TestCullingTerrainApplication *mApplication; 275 277 }; -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
r161 r164 24 24 }; 25 25 26 const float walk_duration = 10.0f; 27 const float wait_duration = 2.0f; 28 const float rotate_factor = 0.7f; 29 const float move_factor = 0.03; 30 26 31 /***************************************/ 27 32 /* EntityState implementation */ 28 33 /***************************************/ 34 Vector3 EntityState::msMinPos = Vector3::ZERO; 35 Vector3 EntityState::msMaxPos = Vector3::ZERO; 36 29 37 EntityState::EntityState(Entity *ent, State entityState, Real speed): 30 38 mEntity(ent), mState(entityState), mAnimationSpeed(speed) … … 53 61 } 54 62 //----------------------------------------------------------------------- 63 EntityState::~EntityState() 64 { 65 mAnimationState = NULL; 66 mEntity = NULL; 67 } 68 //----------------------------------------------------------------------- 55 69 Entity *EntityState::GetEntity() 56 70 { … … 66 80 { 67 81 mTimeElapsed -= timeSinceLastFrame * mAnimationSpeed; 82 83 if (!mEntity || !mAnimationState) 84 return; 68 85 69 86 if (mState == MOVING) // toggle between moving (longer) and waiting (short) 70 87 { 71 88 SceneNode *parent = mEntity->getParentSceneNode(); 89 90 if (!parent) 91 return; 72 92 73 93 if (mTimeElapsed <= 0) // toggle animation state … … 76 96 { 77 97 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); 98 99 mTimeElapsed = walk_duration; // walk for mTimeElapsed units 100 101 // choose random rotation 102 Radian rnd = Radian(Math::UnitRandom() * Math::PI * rotate_factor); 82 103 83 104 //mEntity->getParentSceneNode()->rotate(); … … 87 108 { 88 109 SetAnimationState("Idle", true); 89 mTimeElapsed = 2; // wait for mTimeElapsed seconds110 mTimeElapsed = wait_duration; // wait for mTimeElapsed seconds 90 111 } 91 112 } 92 113 93 if (mAnimationState->getAnimationName() == "Walk") 114 if (mAnimationState->getAnimationName() == "Walk") // move forward 94 115 { 116 // store old position, just in case we get out of bounds 95 117 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 118 parent->translate(parent->getLocalAxes(), Vector3(move_factor * mAnimationSpeed, 0, 0)); 119 120 // HACK: if out of bounds => reset to old position and set animationstate to idle 100 121 if (OutOfBounds(parent)) 101 122 { 102 123 parent->setPosition(oldPos); 103 SetAnimationState("Idle );124 SetAnimationState("Idle", true); 104 125 105 mTimeElapsed = 2;126 mTimeElapsed = wait_duration; 106 127 } 107 128 } 108 129 } 109 130 110 if (mAnimationState) // add time to drive animation 111 { 112 mAnimationState->addTime(timeSinceLastFrame * mAnimationSpeed); 113 } 131 // add time to drive animation 132 mAnimationState->addTime(timeSinceLastFrame * mAnimationSpeed); 114 133 } 115 134 //----------------------------------------------------------------------- 116 135 void EntityState::SetAnimationState(String stateStr, bool loop) 117 136 { 137 if (!mEntity) 138 return; 139 118 140 mAnimationState = mEntity->getAnimationState(stateStr); 119 141 mAnimationState->setLoop(loop); … … 126 148 127 149 if ((pos > msMinPos) && (pos < msMaxPos)) 128 return true; 129 130 return false; 131 } 150 return false; 151 152 return true; 153 } 154 155 156 132 157 /*********************************************************/ 133 158 /* TestCullingTerrainApplication implementation */ … … 136 161 137 162 TestCullingTerrainApplication::TestCullingTerrainApplication(): 138 mTerrainContentGenerator(NULL) 163 mTerrainContentGenerator(NULL), mRayQueryExecutor(NULL) 139 164 { 140 165 } … … 144 169 OGRE_DELETE(mTerrainContentGenerator); 145 170 OGRE_DELETE(mRayQueryExecutor); 171 146 172 deleteEntityStates(); 147 173 } … … 151 177 for (int i = 0; i < (int)mEntityStates.size(); ++i) 152 178 { 153 delete mEntityStates[i];154 mEntityStates[i] = NULL;155 } 179 OGRE_DELETE(mEntityStates[i]); 180 } 181 156 182 mEntityStates.clear(); 157 183 } … … 248 274 mSceneMgr->setWorldGeometry(terrain_cfg); 249 275 250 // ray query executor251 mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);252 276 253 277 //-- CEGUI setup … … 274 298 mSceneMgr->_renderScene(mCamera, mWindow->getViewport(0), true); 275 299 300 // ray query executor: needed to clamp to terrain 301 mRayQueryExecutor = new RayQueryExecutor(mSceneMgr); 302 303 mTerrainMinPos = EntityState::msMinPos = Vector3(0, 0, 0); 304 mTerrainMaxPos = EntityState::msMaxPos = Vector3(3000, 5000, 3000); 305 276 306 mTerrainContentGenerator = new TerrainContentGenerator(mSceneMgr); 277 307 … … 280 310 { 281 311 // to provide much occlusion, 282 // height is restricted to 50 => no objects appear on peaks 283 mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 50.0f, 3000.0f)); 312 // height is restricted to 50 => no objects are created on peaks 313 mTerrainContentGenerator->SetMinPos(Vector3(mTerrainMinPos)); 314 mTerrainContentGenerator->SetMaxPos(Vector3(mTerrainMaxPos.x, 50.0f, mTerrainMaxPos.z)); 284 315 mTerrainContentGenerator->SetOffset(0); 285 316 … … 288 319 } 289 320 290 // no limitations needed anymore: the user can set291 // objects also on peaks of terrain292 mTerrainContentGenerator->SetMaxPos( Vector3(3000.0f, 5000.0f, 3000.0f));321 // no limitations anymore => it is possible for the user to put single 322 // objects on peaks of the terrain (only few, not relevant for occlusion) 323 mTerrainContentGenerator->SetMaxPos(mTerrainMaxPos); 293 324 } 294 325 //----------------------------------------------------------------------- … … 314 345 for (int i = 0; i < (int)mEntityStates.size(); ++i) 315 346 { 316 SceneNode *s m= mEntityStates[i]->GetEntity()->getParentSceneNode();347 SceneNode *sn = mEntityStates[i]->GetEntity()->getParentSceneNode(); 317 348 318 349 mEntityStates[i]->update(timeSinceLastFrame); … … 320 351 if (mEntityStates[i]->GetState() == EntityState::MOVING) 321 352 { 322 Clamp2Terrain(sn, 0); 323 //sm->setNodeVisible(false); 353 Clamp2Terrain(sn, 0); //sn->setNodeVisible(false); 324 354 } 325 355 } -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
r161 r164 34 34 35 35 EntityState(Entity *ent, State entityState, Real speed); 36 36 ~EntityState(); 37 37 /** Update the entity state. 38 38 */ … … 46 46 */ 47 47 EntityState::State GetState(); 48 49 static bool OutOfBounds(SceneNode *node); 50 51 static Vector3 msMinPos; 52 static Vector3 msMaxPos; 48 53 49 54 protected: … … 136 141 RayQueryExecutor *mRayQueryExecutor; 137 142 143 Vector3 mTerrainMinPos; 144 Vector3 mTerrainMaxPos; 138 145 private: 139 146 void chooseSceneManager(void);
Note: See TracChangeset
for help on using the changeset viewer.