Changeset 1536
- Timestamp:
- 09/29/06 10:35:14 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Geom/Demo_LodStrips
- Files:
-
- 27 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Geom/Demo_LodStrips/main.cpp
r1529 r1536 18 18 19 19 // Distance values 20 #define dist_min 1 20020 #define dist_min 1100 21 21 #define dist_max 2000 22 22 … … 38 38 Camera* theCam; 39 39 Entity* pPlaneEnt; 40 std::vector<Entity*> belowWaterEnts;41 std::vector<Entity*> aboveWaterEnts;42 43 Plane reflectionPlane;44 40 45 41 OverlayElement* mInfo; 46 42 OverlayElement* mInfo2; 47 48 class RefractionTextureListener : public RenderTargetListener49 {50 public:51 void preRenderTargetUpdate(const RenderTargetEvent& evt)52 {53 // Hide plane and objects above the water54 pPlaneEnt->setVisible(false);55 std::vector<Entity*>::iterator i, iend;56 iend = aboveWaterEnts.end();57 for (i = aboveWaterEnts.begin(); i != iend; ++i)58 {59 (*i)->setVisible(false);60 }61 62 }63 void postRenderTargetUpdate(const RenderTargetEvent& evt)64 {65 // Show plane and objects above the water66 pPlaneEnt->setVisible(true);67 std::vector<Entity*>::iterator i, iend;68 iend = aboveWaterEnts.end();69 for (i = aboveWaterEnts.begin(); i != iend; ++i)70 {71 (*i)->setVisible(true);72 }73 }74 75 };76 class ReflectionTextureListener : public RenderTargetListener77 {78 public:79 void preRenderTargetUpdate(const RenderTargetEvent& evt)80 {81 // Hide plane and objects below the water82 pPlaneEnt->setVisible(false);83 std::vector<Entity*>::iterator i, iend;84 iend = belowWaterEnts.end();85 for (i = belowWaterEnts.begin(); i != iend; ++i)86 {87 (*i)->setVisible(false);88 }89 theCam->enableReflection(reflectionPlane);90 91 }92 void postRenderTargetUpdate(const RenderTargetEvent& evt)93 {94 // Show plane and objects below the water95 pPlaneEnt->setVisible(true);96 std::vector<Entity*>::iterator i, iend;97 iend = belowWaterEnts.end();98 for (i = belowWaterEnts.begin(); i != iend; ++i)99 {100 (*i)->setVisible(true);101 }102 theCam->disableReflection();103 }104 105 };106 43 107 44 class CustomIndexData : public Geometry::IndexData … … 197 134 198 135 static float lodfactorBefore = -1.0f; 199 if (fabsf(lodfactorBefore-lodfactor)>0.0 5f ||136 if (fabsf(lodfactorBefore-lodfactor)>0.03f || 200 137 (lodfactorBefore>0.0f && lodfactor==0.0f) || 201 138 (lodfactorBefore<1.0f && lodfactor==1.0f)) 202 139 { 203 140 myStrips->GoToLod(lodfactor); 204 // DumpDataToOgreBuffers(ogreMesh,myStrips);205 141 lodfactorBefore=lodfactor; 206 142 } … … 281 217 }; 282 218 283 class FresnelApplication : public ExampleApplication219 class LodStripsApplication : public ExampleApplication 284 220 { 285 221 protected: 286 RefractionTextureListener mRefractionListener;287 ReflectionTextureListener mReflectionListener;288 222 public: 289 FresnelApplication() { 290 291 292 } 293 294 ~FresnelApplication() 295 { 296 } 223 LodStripsApplication() {} 224 ~LodStripsApplication() {} 225 297 226 protected: 298 299 300 227 301 228 // Just override the mandatory create scene method … … 305 232 306 233 mat = new MaterialPtr[1]; 307 308 // Check prerequisites first309 const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities();310 if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !(caps->hasCapability(RSC_FRAGMENT_PROGRAM)))311 {312 OGRE_EXCEPT(1, "Your card does not support vertex and fragment programs, so cannot "313 "run this demo. Sorry!",314 "Fresnel::createScene");315 }316 else317 {318 if (!GpuProgramManager::getSingleton().isSyntaxSupported("arbfp1") &&319 !GpuProgramManager::getSingleton().isSyntaxSupported("ps_2_0") &&320 !GpuProgramManager::getSingleton().isSyntaxSupported("ps_1_4")321 )322 {323 OGRE_EXCEPT(1, "Your card does not support advanced fragment programs, "324 "so cannot run this demo. Sorry!",325 "Fresnel::createScene");326 }327 }328 234 329 235 theCam = mCamera; 330 theCam->setPosition(0, 20,dist_min-600.0f);236 theCam->setPosition(0,-100,dist_min-600.0f); 331 237 // Set ambient light 332 238 mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); 333 239 334 // Create a pointlight240 // Create a directional light 335 241 Light* l = mSceneMgr->createLight("MainLight"); 336 242 l->setType(Light::LT_DIRECTIONAL); 337 243 l->setDirection(0.0,0.0,-1.0); 338 339 244 340 RenderTexture* rttTex = mRoot->getRenderSystem()->createRenderTexture( "Refraction", 512, 512 ); 341 342 { 343 Viewport *v = rttTex->addViewport( mCamera ); 344 MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); 345 mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName("Refraction"); 346 v->setOverlaysEnabled(false); 347 rttTex->addListener(&mRefractionListener); 348 } 349 350 351 rttTex = mRoot->getRenderSystem()->createRenderTexture( "Reflection", 512, 512 ); 352 { 353 Viewport *v = rttTex->addViewport( mCamera ); 354 MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); 355 mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName("Reflection"); 356 v->setOverlaysEnabled(false); 357 rttTex->addListener(&mReflectionListener); 358 } 359 360 361 // Define a floor plane mesh 362 reflectionPlane.normal = Vector3::UNIT_Y; 363 reflectionPlane.d = 0; 364 MeshManager::getSingleton().createPlane("ReflectPlane", 365 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 366 reflectionPlane, 367 9000,9000,10,10,true,1,5,5,Vector3::UNIT_Z); 368 pPlaneEnt = mSceneMgr->createEntity( "plane", "ReflectPlane" ); 369 pPlaneEnt->setMaterialName("Examples/FresnelReflectionRefraction"); 370 mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); 371 372 245 373 246 mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); 374 247 … … 377 250 378 251 379 // Now the below water ents380 252 pEnt = mSceneMgr->createEntity( "PoolFloor", "PoolFloor.mesh" ); 381 253 myRootNode->attachObject(pEnt); 382 belowWaterEnts.push_back(pEnt);383 254 myRootNode->scale(6.0,6.0,6.0); 384 255 … … 410 281 411 282 entity->setNormaliseNormals(true); 412 aboveWaterEnts.push_back(entity);413 283 entity->setMaterialName("LODStripsDemo/Ogro"); 414 284 415 for (int i=-3; i< 7; i++) // 7416 for (int j=0; j< 4; j++) // 4285 for (int i=-3; i<6; i++) // 7 286 for (int j=0; j<10; j++) // 4 417 287 { 418 288 char newObjName[16]=""; … … 425 295 float randomsepx = (float)((rand()%18)-9); 426 296 float randomsepy = (float)((rand()%12)-6); 427 auxnode->translate(i*70.0f+randomsepx,-1 .0f,-j*70.0f-randomsepx);297 auxnode->translate(i*70.0f+randomsepx,-150.0f,-j*70.0f-randomsepx); 428 298 auxen->setNormaliseNormals(true); 429 299 } … … 466 336 { 467 337 // Create application object 468 FresnelApplication app;338 LodStripsApplication app; 469 339 470 340 try {
Note: See TracChangeset
for help on using the changeset viewer.