Changeset 1536


Ignore:
Timestamp:
09/29/06 10:35:14 (18 years ago)
Author:
gumbau
Message:

Demo updated with the new version of the programming interface.

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  
    1818 
    1919// Distance values 
    20 #define dist_min 1200 
     20#define dist_min 1100 
    2121#define dist_max 2000 
    2222 
     
    3838Camera* theCam; 
    3939Entity* pPlaneEnt; 
    40 std::vector<Entity*> belowWaterEnts; 
    41 std::vector<Entity*> aboveWaterEnts; 
    42  
    43 Plane reflectionPlane; 
    4440 
    4541OverlayElement* mInfo; 
    4642OverlayElement* mInfo2; 
    47  
    48 class RefractionTextureListener : public RenderTargetListener 
    49 { 
    50 public: 
    51     void preRenderTargetUpdate(const RenderTargetEvent& evt) 
    52     { 
    53         // Hide plane and objects above the water 
    54         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 water 
    66         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 RenderTargetListener 
    77 { 
    78 public: 
    79     void preRenderTargetUpdate(const RenderTargetEvent& evt) 
    80     { 
    81         // Hide plane and objects below the water 
    82         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 water 
    95         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 }; 
    10643 
    10744class CustomIndexData : public Geometry::IndexData 
     
    197134 
    198135                static float lodfactorBefore = -1.0f; 
    199                 if (fabsf(lodfactorBefore-lodfactor)>0.05f ||  
     136                if (fabsf(lodfactorBefore-lodfactor)>0.03f ||  
    200137                        (lodfactorBefore>0.0f && lodfactor==0.0f) || 
    201138                        (lodfactorBefore<1.0f && lodfactor==1.0f)) 
    202139                { 
    203140                        myStrips->GoToLod(lodfactor); 
    204 //                      DumpDataToOgreBuffers(ogreMesh,myStrips); 
    205141                        lodfactorBefore=lodfactor; 
    206142                } 
     
    281217}; 
    282218 
    283 class FresnelApplication : public ExampleApplication 
     219class LodStripsApplication : public ExampleApplication 
    284220{ 
    285221protected: 
    286     RefractionTextureListener mRefractionListener; 
    287     ReflectionTextureListener mReflectionListener; 
    288222public: 
    289     FresnelApplication() { 
    290      
    291      
    292     } 
    293  
    294     ~FresnelApplication()  
    295     { 
    296     } 
     223    LodStripsApplication() {} 
     224    ~LodStripsApplication() {} 
     225 
    297226protected: 
    298      
    299  
    300227 
    301228    // Just override the mandatory create scene method 
     
    305232 
    306233                mat = new MaterialPtr[1]; 
    307                  
    308             // Check prerequisites first 
    309                 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         else 
    317         { 
    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         } 
    328234 
    329235        theCam = mCamera; 
    330         theCam->setPosition(0,20,dist_min-600.0f); 
     236        theCam->setPosition(0,-100,dist_min-600.0f); 
    331237        // Set ambient light 
    332238        mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); 
    333239 
    334         // Create a point light 
     240        // Create a directional light 
    335241        Light* l = mSceneMgr->createLight("MainLight"); 
    336242        l->setType(Light::LT_DIRECTIONAL); 
    337243        l->setDirection(0.0,0.0,-1.0); 
    338  
    339244        
    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        
    373246        mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox"); 
    374247 
     
    377250 
    378251 
    379         // Now the below water ents 
    380252        pEnt = mSceneMgr->createEntity( "PoolFloor", "PoolFloor.mesh" ); 
    381253        myRootNode->attachObject(pEnt); 
    382         belowWaterEnts.push_back(pEnt); 
    383254                myRootNode->scale(6.0,6.0,6.0); 
    384255 
     
    410281                 
    411282                entity->setNormaliseNormals(true); 
    412                 aboveWaterEnts.push_back(entity); 
    413283                entity->setMaterialName("LODStripsDemo/Ogro"); 
    414284 
    415                 for (int i=-3; i<7; i++) // 7 
    416                         for (int j=0; j<4; j++) // 4 
     285                for (int i=-3; i<6; i++) // 7 
     286                        for (int j=0; j<10; j++) // 4 
    417287                        { 
    418288                                char newObjName[16]=""; 
     
    425295                                float randomsepx = (float)((rand()%18)-9); 
    426296                                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); 
    428298                                auxen->setNormaliseNormals(true); 
    429299                        } 
     
    466336{ 
    467337    // Create application object 
    468     FresnelApplication app; 
     338    LodStripsApplication app; 
    469339 
    470340    try { 
Note: See TracChangeset for help on using the changeset viewer.