Changeset 1775 for GTP/trunk/App/Demos/Geom/Demo_LodStrips
- Timestamp:
- 11/21/06 11:10:53 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Geom/Demo_LodStrips
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Geom/Demo_LodStrips/main.cpp
r1561 r1775 26 26 27 27 //Global variables 28 28 29 Entity* entity; 29 30 Geometry::LodStripsLibrary* myStrips; … … 42 43 OverlayElement* mInfo2; 43 44 OverlayElement* mHelp; 44 45 char HelpString[]="(F1) Help\n" 45 OverlayElement* mLOD; 46 OverlayElement* mShad; 47 SceneManager* SceneMgrAux; 48 49 char LODStringAuto[]="(F3) LOD Mode: AUTOMATIC"; 50 char LODStringManu[]="(F3) LOD Mode: MANUAL"; 51 char ShadON[] ="(F2) Shadows ON"; 52 char ShadOFF[] ="(F2) Shadows OFF"; 53 54 int degAA=0, degABAB=0; 55 56 char HelpString[]="(F1) Quit Help\n" 46 57 "This demo shows an example of the LODStrips model in action. The models in the scene\n" 47 58 "are associated to a LodStrips object that manage their level of detail.\n" … … 50 61 "closer to them the level of detail increases to restore the original geometry of the\n" 51 62 "model.\n" 52 "The current level of detail can be seen in real-time in the top-left corner of the screen.\n"63 "The current level of detail can be seen in real-time in the bottom-left corner of the screen.\n" 53 64 "The level of detail begins to decrease at a certain distance of the crowd, and stops\n" 54 65 "decreasing when the objects reach the their minimum LOD. This 'lodding' distance is\n" 55 "customizable from the source code of the demo."; 56 57 char NoHelpString[]="(F1) Help\n"; 66 "customizable from the source code of the demo.\n\n" 67 "(F3) LOD Mode ( AUTOMATIC vs MANUAL )\n" 68 " MANUAL MODE: Use (+) and (-) keys to change de LOD\n"; 69 70 char NoHelpString[]="\n\n\n\n\n\n\n\n\n\n\n\n\n(F1) Help\n"; 71 72 int num_ogres = 90; 58 73 59 74 … … 82 97 } 83 98 virtual void End(){ 99 int v0, v1, v2, v3; 100 unsigned int i; 101 102 v0 = pIdx[0]; 103 v1 = pIdx[1]; 104 for ( i=2; i < mRenderOp.indexData->indexCount; i++) 105 { 106 if ( v0 == v1 ) degAA++; 107 v0 = v1; 108 v1 = pIdx[i]; 109 } 110 111 v0 = pIdx[0]; 112 v1 = pIdx[1]; 113 v2 = pIdx[2]; 114 v3 = pIdx[3]; 115 for ( i=4; i < mRenderOp.indexData->indexCount; i++) 116 { 117 if ( ( v0 == v2 ) && ( v1 == v3 ) ) 118 { 119 v0 = v2; 120 v1 = v3; 121 v2 = pIdx[i]; 122 if ( i < mRenderOp.indexData->indexCount ) 123 { 124 i++; 125 v3 = pIdx[i]; 126 } 127 else v3 = -1; 128 129 degABAB++; 130 } 131 else 132 { 133 v0 = v1; 134 v1 = v2; 135 v2 = v3; 136 v3 = pIdx[i]; 137 } 138 } 139 84 140 ibuf->unlock(); 85 141 } … … 89 145 class FresnelFrameListener : public ExampleFrameListener 90 146 { 91 int manage;147 float miButtonTimer; 92 148 93 149 public: … … 96 152 : ExampleFrameListener(win, cam, false, false) 97 153 { 98 m anage=1;154 miButtonTimer=0; 99 155 } 100 156 … … 102 158 { 103 159 Vector3 dist; 104 int distance=0,inc2=0,d; 105 unsigned int nlod,diflods; 160 int distance=0,inc2=0; 161 static int modo=0; 162 static int shadows=1; 163 164 float tiempo = evt.timeSinceLastFrame; 165 miButtonTimer -= tiempo; 166 167 if (shadows == 0) 168 { 169 SceneMgrAux->setShadowTechnique(SHADOWTYPE_NONE); 170 } 171 else 172 { 173 SceneMgrAux->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE); 174 } 175 106 176 107 177 // Move upto 80 units/second … … 131 201 132 202 //LOD selection 133 int difdist = dist_max - dist_min; 134 135 int i=0; 136 203 static float lodfactor=0; 204 static float lodfactorBefore = -1.0f; 205 137 206 dist = node->getPosition() - mCamera->getPosition(); 138 207 distance =dist.length(); 139 208 140 float lodfactor = (float)(distance - dist_min) / (float)(dist_max - dist_min); 141 lodfactor = 1.0f - lodfactor; 209 if ( modo == 0 ) //Automatic LOD 210 { 211 int difdist = dist_max - dist_min; 212 213 int i=0; 214 215 lodfactor = (float)(distance - dist_min) / (float)(dist_max - dist_min); 216 lodfactor = 1.0f - lodfactor; 217 } 218 else 219 { 220 // lodfactor = lodfactorBefore; 221 } 222 223 224 if (( mInputDevice->isKeyDown(Ogre::KC_ADD) ) && (modo == 1)) 225 lodfactor += 0.001f; 226 if (( mInputDevice->isKeyDown(Ogre::KC_SUBTRACT) ) && (modo == 1)) 227 lodfactor -= 0.001f; 142 228 143 229 if (lodfactor<0.0f) … … 146 232 lodfactor=1.0f; 147 233 148 static float lodfactorBefore = -1.0f;149 234 if (fabsf(lodfactorBefore-lodfactor)>0.03f || 150 235 (lodfactorBefore>0.0f && lodfactor==0.0f) || 151 236 (lodfactorBefore<1.0f && lodfactor==1.0f)) 152 237 { 238 degAA=0; degABAB=0; 153 239 myStrips->GoToLod(lodfactor); 154 240 lodfactorBefore=lodfactor; 241 } 242 243 if ( mInputDevice->isKeyDown(Ogre::KC_F3) && ( miButtonTimer <= 0 ) ) 244 { 245 miButtonTimer = 0.5; 246 247 if (modo == 0) 248 { 249 modo=1; 250 mLOD->setCaption(LODStringManu); 251 } 252 else 253 { 254 modo=0; 255 mLOD->setCaption(LODStringAuto); 256 } 257 } 258 259 if ( mInputDevice->isKeyDown(Ogre::KC_F2) && ( miButtonTimer <= 0 ) ) 260 { 261 miButtonTimer = 0.5; 262 263 if (shadows == 0) 264 { 265 shadows = 1; 266 mShad->setCaption(ShadON); 267 } 268 else 269 { 270 shadows = 0; 271 mShad->setCaption(ShadOFF); 272 } 155 273 } 156 274 … … 215 333 } 216 334 335 SceneMgrAux->setShadowFarDistance(distance + 200); 217 336 218 337 char cadena[256]; 219 338 const RenderTarget::FrameStats& stats = mWindow->getStatistics(); 220 339 221 sprintf(cadena," Distance: %d",distance);222 340 sprintf(cadena,"\nDistance: %d\nLOD factor: %f\nTriangle Count: %d\nDegenerated AA: %d\nDegenerated ABAB: %d" 341 , distance, lodfactor,stats.triangleCount, degAA*num_ogres, degABAB*num_ogres); 223 342 mInfo->setCaption(cadena); 224 225 sprintf(cadena,"LOD factor: %f",lodfactor); 226 343 sprintf(cadena,"Current FPS: %f\n",stats.lastFPS); 227 344 mInfo2->setCaption(cadena); 345 346 //sprintf(cadena,"LOD factor: %f",lodfactor); 347 348 //mInfo2->setCaption(cadena); 228 349 229 350 mCamera->yaw(mRotX); … … 248 369 void createScene(void) 249 370 { 250 Entity* pEnt; 371 SceneMgrAux = mSceneMgr; 372 mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2)); 373 mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE); 374 mSceneMgr->setShadowTextureSettings(2048,1); 375 mSceneMgr->setShadowFarDistance(1024); 376 mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5)); 251 377 252 378 mat = new MaterialPtr[1]; 253 379 254 255 theCam->setPosition( 0,50,dist_min-600.0f);380 theCam = mCamera; 381 theCam->setPosition(-35,50,dist_min-600.0f); 256 382 // Set ambient light 257 mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));258 383 259 384 // Create a directional light 260 385 Light* l = mSceneMgr->createLight("MainLight"); 261 386 l->setType(Light::LT_DIRECTIONAL); 262 l->setDirection( 0.0,0.0,-1.0);263 264 387 l->setDirection(-0.5,-1.0,-1.0); 388 l->setCastShadows(true); 389 265 390 mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); 266 391 … … 273 398 MeshManager::getSingleton().createPlane("ground", 274 399 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 275 4000,4000,6,6,true,1,10,10,Vector3::UNIT_Z);400 20000,10000,6,6,true,1,250,250,Vector3::UNIT_Z); 276 401 277 402 Entity* groundEntity = mSceneMgr->createEntity( "GroundEntity", "ground" ); 278 403 mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity); 279 404 280 groundEntity->setMaterialName(" RockTerrain");281 groundEntity->setCastShadows(false); 405 groundEntity->setMaterialName("SnowTerrain"); 406 groundEntity->setCastShadows(false); 282 407 283 408 std::string model_file=model_name; … … 294 419 node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); 295 420 node->attachObject( entity ); 296 node->setVisible(false); 421 node->setVisible(false); 297 422 298 423 std::string lod_file="../../media/GT/"; … … 310 435 entity->setMaterialName("LODStripsDemo/Ogro"); 311 436 312 for (int i=-3; i<6; i++) // 7 313 for (int j=0; j<10; j++) // 4 437 438 num_ogres=0; 439 440 for (int i=-4; i<4; i++) // 7 441 for (int j=0; j<8; j++) // 4 314 442 { 315 443 char newObjName[16]=""; … … 322 450 float randomsepx = (float)((rand()%18)-9); 323 451 float randomsepy = (float)((rand()%12)-6); 324 auxnode->translate(i*70.0f+randomsepx, 0.0f,-j*70.0f-randomsepx);452 auxnode->translate(i*70.0f+randomsepx,-0.3f,-j*70.0f-randomsepx); 325 453 auxen->setNormaliseNormals(true); 454 auxen->setCastShadows(true); 455 456 num_ogres++; 326 457 } 327 458 … … 333 464 mInfo2 = OverlayManager::getSingleton().getOverlayElement("Demo_LodStrips/Info_2"); 334 465 mHelp = OverlayManager::getSingleton().getOverlayElement("Demo_LodStrips/Help"); 466 mLOD = OverlayManager::getSingleton().getOverlayElement("Demo_LodStrips/ModoLOD"); 467 mShad = OverlayManager::getSingleton().getOverlayElement("Demo_LodStrips/Shadows"); 335 468 mHelp->setCaption(NoHelpString); 336 pOver->show(); 469 mLOD->setCaption(LODStringAuto); 470 mShad->setCaption(ShadON); 471 pOver->show(); 472 //mWindow->getStatistics(); 337 473 338 474 } … … 341 477 { 342 478 mFrameListener= new FresnelFrameListener(mWindow, mCamera); 343 mFrameListener->showDebugOverlay( true);479 mFrameListener->showDebugOverlay(false); 344 480 mRoot->addFrameListener(mFrameListener); 345 481 }
Note: See TracChangeset
for help on using the changeset viewer.