Ignore:
Timestamp:
08/24/06 14:17:44 (18 years ago)
Author:
szydlowski
Message:

Added the KdTerrainSceneManager?, a subclass of the KdTreeSceneManager? capable of rendering terrain like the TerrainSceneManager? from Ogre.
All the *Kd*Terrain* classes are identical to their octree counterparts, save prefixing all classes and structures with Kd to avoid namespace clashes.
This was necessary, since the TerrainSceneManager? was hard coded in these classes, and all references had to be replaced with the KdTerrainSceneManager?.
Also added a comprehensive README for the demo application.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp

    r1258 r1273  
    181181        cfDeath.load("testKdTree.cfg"); 
    182182 
    183         mSceneFiles = cfDeath.getSetting("scene"); 
     183        mOptions.mSceneFiles = cfDeath.getSetting("scene"); 
    184184 
    185185        tmp = cfDeath.getSetting("shadows"); 
     
    236236        createMaterials(); 
    237237 
     238        // load simple scene (planes & robots) 
     239        if (mOptions.mSceneFiles == "") 
     240        { 
     241                createSimpleScene(); 
     242        } 
     243        // load terrain, but only if terrainscenemanager selected 
     244        else if (mOptions.mSceneFiles == TERRAIN_SCENE) 
     245        { 
     246                Plane waterPlane; 
     247 
     248                // Set ambient light 
     249                mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); 
     250 
     251                // Create a light 
     252                Light* l = mSceneMgr->createLight("MainLight"); 
     253                // Accept default settings: point light, white diffuse, just set position 
     254                // NB I could attach the light to a SceneNode if I wanted it to move automatically with 
     255                //  other objects, but I don't 
     256                l->setPosition(20,80,50); 
     257 
     258                // Fog 
     259                // NB it's VERY important to set this before calling setWorldGeometry  
     260                // because the vertex program picked will be different 
     261                //ColourValue fadeColour(0.93, 0.86, 0.76); 
     262                //mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000); 
     263                //mWindow->getViewport(0)->setBackgroundColour(fadeColour); 
     264                mWindow->getViewport(0)->setBackgroundColour(ColourValue::Blue); 
     265 
     266                std::string terrain_cfg("terrain.cfg"); 
     267 
     268                mSceneMgr -> setWorldGeometry( terrain_cfg ); 
     269 
     270                // Define the required skyplane 
     271                Plane plane; 
     272                // 5000 world units from the camera 
     273                plane.d = 5000; 
     274                // Above the camera, facing down 
     275                plane.normal = -Vector3::UNIT_Y; 
     276 
     277                // add one robot 
     278                //Entity *robot = mSceneMgr->createEntity("TheRobot","robot.mesh"); 
     279                //SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("TheRobotNode"); 
     280                //node->attachObject(robot); 
     281                // add stuff minus gound plane 
     282                mSelectEntities &= ~ENT_PLN; 
     283                createSimpleScene(); 
     284 
     285                // Set a nice viewpoint 
     286                mCamNode->setPosition(707,2500,528); 
     287                mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329)); 
     288        } 
     289        // load scene from file 
     290        else 
     291        { 
     292                // don't load the other stuff 
     293                loadScene(mOptions.mSceneFiles); 
     294                // top view 
     295                mTopCam->setPosition(Vector3(1232, 3990, -1477)); 
     296                // walkthrough view 
     297                mCamNode->setPosition(Vector3(827.885, 184.435, -524.984)); 
     298                mCamNode->setOrientation(Quaternion(0.98935, 0.0348082, -0.141246, 0.00496945)); 
     299 
     300                mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true); 
     301        } 
     302} 
     303 
     304void KdTreeApp::createSimpleScene() 
     305{ 
    238306        Entity *deaths; 
    239307        SceneNode *nodes; 
     
    245313        Real planeSixth = mPlaneDim / 6; 
    246314 
    247         // load scene from file 
    248         if (mSceneFiles != "") 
    249         { 
    250                 // don't load the other stuff 
    251                 loadScene(mSceneFiles); 
    252                 // top view 
    253                 mTopCam->setPosition(Vector3(1232, 3990, -1477)); 
    254                 // walkthrough view 
    255                 mCamNode->setPosition(Vector3(827.885, 184.435, -524.984)); 
    256                 mCamNode->setOrientation(Quaternion(0.98935, 0.0348082, -0.141246, 0.00496945)); 
    257  
    258                 mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 5000, true); 
    259         } 
    260         else 
    261         { 
    262                 mCamNode->setPosition(Vector3(1280,600,1666)); 
    263                 mCamNode->setOrientation(Quaternion(0.936893, -0.124586, 0.323813, 0.04306)); 
    264                 //mCamera->lookAt(Vector3(-20,30,10)); 
    265  
    266                 SceneNode *anchor = mSceneMgr->getRootSceneNode()->createChildSceneNode("AnchorNode"); 
    267                 //SceneNode *grndan = anchor->createChildSceneNode("GroundAnchor"); 
    268                 SceneNode *grndan = mSceneMgr->getRootSceneNode(); 
    269  
    270                 if (mSelectEntities & ENT_GRID) 
     315        mCamNode->setPosition(Vector3(1280,600,1666)); 
     316        mCamNode->setOrientation(Quaternion(0.936893, -0.124586, 0.323813, 0.04306)); 
     317 
     318        SceneNode *anchor = mSceneMgr->getRootSceneNode()->createChildSceneNode("AnchorNode"); 
     319        //SceneNode *grndan = anchor->createChildSceneNode("GroundAnchor"); 
     320        SceneNode *grndan = mSceneMgr->getRootSceneNode(); 
     321 
     322        if (mSelectEntities & ENT_GRID) 
     323        { 
     324                for (j = 0, z =  -(mModelCount / 2 * mModelSpacing); j < mModelCount; j++, z += mModelSpacing) 
    271325                { 
    272                         for (j = 0, z =  -(mModelCount / 2 * mModelSpacing); j < mModelCount; j++, z += mModelSpacing) 
     326                        for (i = 0, x = -(mModelCount / 2 * mModelSpacing); i < mModelCount; i++, x += mModelSpacing)  
    273327                        { 
    274                                 for (i = 0, x = -(mModelCount / 2 * mModelSpacing); i < mModelCount; i++, x += mModelSpacing)  
    275                                 { 
    276                                         deaths = mSceneMgr->createEntity(cat(entName, i, j).c_str(),"robot.mesh"); 
    277                                         if (mShadowsEnabled) 
    278                                                 deaths->setCastShadows(true); 
    279                                         nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName, i, j).c_str(), Vector3(x, 0 , z)); 
    280                                         nodes->attachObject(deaths); 
    281                                 } 
    282                         } 
    283                 } 
    284  
    285                 if (mSelectEntities & ENT_RND) 
    286                 { 
    287                         entName = "randomdeath"; 
    288                         nodeName = "RandomDeathNode"; 
    289                         for (i = 0; i < mRandomCount; i++) 
    290                         { 
    291                                 Vector3 pos( 
    292                                         Math::RangeRandom(-planeHalf,-planeSixth),  
    293                                         0,  
    294                                         Math::RangeRandom(-planeThreeEights, planeThreeEights)); 
    295                                 deaths = mSceneMgr->createEntity(cat(entName,666,i),"robot.mesh"); 
     328                                deaths = mSceneMgr->createEntity(cat(entName, i, j).c_str(),"robot.mesh"); 
    296329                                if (mShadowsEnabled) 
    297330                                        deaths->setCastShadows(true); 
    298                                 nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName,666,i), pos, 
    299                                         Quaternion(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y)); 
     331                                nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName, i, j).c_str(), Vector3(x, 0 , z)); 
    300332                                nodes->attachObject(deaths); 
    301333                        } 
    302334                } 
    303  
    304                 if (mSelectEntities & ENT_SPC) 
     335        } 
     336 
     337        if (mSelectEntities & ENT_RND) 
     338        { 
     339                entName = "randomdeath"; 
     340                nodeName = "RandomDeathNode"; 
     341                for (i = 0; i < mRandomCount; i++) 
    305342                { 
    306                         entName = "randomspaceship"; 
    307                         nodeName = "RandomSpaceshipNode"; 
    308                         for (i = 0; i < mRandomCount; i++) 
    309                         { 
    310                                 Vector3 pos( 
    311                                         //Math::RangeRandom(-planeHalf,-planeSixth),  
    312                                         Math::RangeRandom(planeSixth,planeHalf),  
    313                                         Math::RangeRandom(planeHalf * 0.1, planeHalf),  
    314                                         Math::RangeRandom(-planeThreeEights, planeThreeEights)); 
    315                                 deaths = mSceneMgr->createEntity(cat(entName,666,i),"razor.mesh"); 
    316                                 if (mShadowsEnabled) 
    317                                         deaths->setCastShadows(true); 
    318                                 nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName,666,i), pos, 
    319                                         Quaternion(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y)); 
    320                                 nodes->attachObject(deaths); 
    321                         } 
     343                        Vector3 pos( 
     344                                Math::RangeRandom(-planeHalf,-planeSixth),  
     345                                0,  
     346                                Math::RangeRandom(-planeThreeEights, planeThreeEights)); 
     347                        deaths = mSceneMgr->createEntity(cat(entName,666,i),"robot.mesh"); 
     348                        if (mShadowsEnabled) 
     349                                deaths->setCastShadows(true); 
     350                        nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName,666,i), pos, 
     351                                Quaternion(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y)); 
     352                        nodes->attachObject(deaths); 
    322353                } 
    323  
    324                 if (mSelectEntities & ENT_MOV) 
     354        } 
     355 
     356        if (mSelectEntities & ENT_SPC) 
     357        { 
     358                entName = "randomspaceship"; 
     359                nodeName = "RandomSpaceshipNode"; 
     360                for (i = 0; i < mRandomCount; i++) 
    325361                { 
    326                         Entity *movingDeath = mSceneMgr->createEntity("movingDeath","robot.mesh"); 
     362                        Vector3 pos( 
     363                                //Math::RangeRandom(-planeHalf,-planeSixth),  
     364                                Math::RangeRandom(planeSixth,planeHalf),  
     365                                Math::RangeRandom(planeHalf * 0.1, planeHalf),  
     366                                Math::RangeRandom(-planeThreeEights, planeThreeEights)); 
     367                        deaths = mSceneMgr->createEntity(cat(entName,666,i),"razor.mesh"); 
    327368                        if (mShadowsEnabled) 
    328                                 movingDeath->setCastShadows( true ); 
    329  
    330                         SceneNode *deathPivotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("deathPivotNode"); 
    331                         mMoveNode = deathPivotNode->createChildSceneNode("movingNode", Vector3(0, 0, mRotationRadius)/*, 
    332                                 Quaternion(Radian(Math::HALF_PI), Vector3::UNIT_Y)*/); 
    333                         mMoveNode->attachObject(movingDeath); 
    334  
    335                         Entity *ent_ball = mSceneMgr->createEntity("ball","sphere.mesh"); 
    336                         SceneNode *node_pivot = mMoveNode->createChildSceneNode("pivotNode"); 
    337                         SceneNode *node_ball = node_pivot->createChildSceneNode("orbitNode", Vector3(120, 40, 0)); 
    338                         node_ball->attachObject(ent_ball); 
    339                         node_ball->scale(0.1, 0.1, 0.1); 
    340                          
    341  
    342                         //mFollowCam->setAutoTracking(true, mMoveNode); 
     369                                deaths->setCastShadows(true); 
     370                        nodes = /*mSceneMgr->getRootSceneNode()*/anchor->createChildSceneNode(cat(nodeName,666,i), pos, 
     371                                Quaternion(Radian(Math::RangeRandom(-Math::PI, Math::PI)), Vector3::UNIT_Y)); 
     372                        nodes->attachObject(deaths); 
    343373                } 
    344                  
    345                 if (mSelectEntities & ENT_PLN) 
    346                 { 
    347                         Plane ground(Vector3::UNIT_Y, 0); 
    348                         MeshManager::getSingleton().createPlane("ground", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,  
    349                                 ground, mPlaneDim * 4 / 3, mPlaneDim, 20, 20, true, 1, 20, 20, Vector3::UNIT_Z); 
    350                         Entity *ent_ground = mSceneMgr->createEntity("GroundEntity", "ground"); 
    351                         ent_ground->setCastShadows(false); 
    352                         ent_ground->setMaterialName("Examples/RustySteel");//("Examples/Rockwall"); 
    353                         SceneNode *node_ground = /*mSceneMgr->getRootSceneNode()*/grndan->createChildSceneNode("GroundNode", Vector3(0, 0, 0)); 
    354                         node_ground->attachObject(ent_ground); 
    355  
    356                         //MeshManager::getSingleton().createPlane("ground2", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,  
    357                         //      ground, mPlaneDim/2, mPlaneDim, 10, 20, true, 1, 10, 20, Vector3::UNIT_Z); 
    358                         //ent_ground = mSceneMgr->createEntity("GroundEntity2", "ground2"); 
    359                         //ent_ground->setCastShadows(false); 
    360                         //ent_ground->setMaterialName("Examples/RustySteel"); 
    361                         //node_ground = /*mSceneMgr->getRootSceneNode()*/grndan->createChildSceneNode("GroundNode2", Vector3(-mPlaneDim/4, 0, 0)); 
    362                         //node_ground->attachObject(ent_ground); 
    363                 } 
    364  
    365                 // Lights 
    366                 mSceneMgr->setAmbientLight(ColourValue(0.1,0.1,0.1)); 
    367                 Light *light = mSceneMgr->createLight("light"); 
     374        } 
     375 
     376        if (mSelectEntities & ENT_MOV) 
     377        { 
     378                Entity *movingDeath = mSceneMgr->createEntity("movingDeath","robot.mesh"); 
    368379                if (mShadowsEnabled) 
    369                 { 
    370                         mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); 
    371                         light->setType(Light::LT_POINT); 
    372                         light->setPosition(Vector3(x, 300, z + 200)); 
    373                 } 
    374                 else 
    375                 { 
    376                         light->setType(Light::LT_DIRECTIONAL); 
    377                         light->setDirection(-1,-1,-1); 
    378                 } 
    379                 light->setDiffuseColour(ColourValue::White); 
    380                 light->setSpecularColour(ColourValue(1, 1, 0.2)); 
    381  
    382                 // Skybox 
    383                 mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", mPlaneDim * 2); 
    384         } 
    385  
    386         /* Some math tests 
    387         Plane planeX(Vector3::UNIT_X, Vector3(10,10,10)); 
    388         Plane planeY(Vector3::UNIT_Y, Vector3(10,10,10)); 
    389         Plane planeZ(Vector3::UNIT_Z, Vector3(10,10,10)); 
    390         Vector3 vect(20,20,20); 
    391         Vector3 interX = planeX.projectVector(vect); 
    392         Vector3 interY = planeY.projectVector(vect); 
    393         Vector3 interZ = planeZ.projectVector(vect); 
    394         std::stringstream ssX, ssY, ssZ; 
    395         ssX << "The intersection of " << planeX << " and " << vect << " is at: " << interX; 
    396         ssY << "The intersection of " << planeY << " and " << vect << " is at: " << interY; 
    397         ssZ << "The intersection of " << planeZ << " and " << vect << " is at: " << interZ; 
    398         LogManager::getSingleton().logMessage(ssX.str()); 
    399         LogManager::getSingleton().logMessage(ssY.str()); 
    400         LogManager::getSingleton().logMessage(ssZ.str()); 
    401         */ 
     380                        movingDeath->setCastShadows( true ); 
     381 
     382                SceneNode *deathPivotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("deathPivotNode"); 
     383                mMoveNode = deathPivotNode->createChildSceneNode("movingNode", Vector3(0, 0, mRotationRadius)/*, 
     384                                                                                                                                                                                                         Quaternion(Radian(Math::HALF_PI), Vector3::UNIT_Y)*/); 
     385                                                                                                                                                                                                         mMoveNode->attachObject(movingDeath); 
     386 
     387                Entity *ent_ball = mSceneMgr->createEntity("ball","sphere.mesh"); 
     388                SceneNode *node_pivot = mMoveNode->createChildSceneNode("pivotNode"); 
     389                SceneNode *node_ball = node_pivot->createChildSceneNode("orbitNode", Vector3(120, 40, 0)); 
     390                node_ball->attachObject(ent_ball); 
     391                node_ball->scale(0.1, 0.1, 0.1); 
     392 
     393 
     394                //mFollowCam->setAutoTracking(true, mMoveNode); 
     395        } 
     396 
     397        if (mSelectEntities & ENT_PLN) 
     398        { 
     399                Plane ground(Vector3::UNIT_Y, 0); 
     400                MeshManager::getSingleton().createPlane("ground", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,  
     401                        ground, mPlaneDim * 4 / 3, mPlaneDim, 20, 20, true, 1, 20, 20, Vector3::UNIT_Z); 
     402                Entity *ent_ground = mSceneMgr->createEntity("GroundEntity", "ground"); 
     403                ent_ground->setCastShadows(false); 
     404                ent_ground->setMaterialName("Examples/RustySteel");//("Examples/Rockwall"); 
     405                SceneNode *node_ground = /*mSceneMgr->getRootSceneNode()*/grndan->createChildSceneNode("GroundNode", Vector3(0, 0, 0)); 
     406                node_ground->attachObject(ent_ground); 
     407 
     408                //MeshManager::getSingleton().createPlane("ground2", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,  
     409                //      ground, mPlaneDim/2, mPlaneDim, 10, 20, true, 1, 10, 20, Vector3::UNIT_Z); 
     410                //ent_ground = mSceneMgr->createEntity("GroundEntity2", "ground2"); 
     411                //ent_ground->setCastShadows(false); 
     412                //ent_ground->setMaterialName("Examples/RustySteel"); 
     413                //node_ground = /*mSceneMgr->getRootSceneNode()*/grndan->createChildSceneNode("GroundNode2", Vector3(-mPlaneDim/4, 0, 0)); 
     414                //node_ground->attachObject(ent_ground); 
     415        } 
     416 
     417        // Lights 
     418        mSceneMgr->setAmbientLight(ColourValue(0.1,0.1,0.1)); 
     419        Light *light = mSceneMgr->createLight("light"); 
     420        if (mShadowsEnabled) 
     421        { 
     422                mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); 
     423                light->setType(Light::LT_POINT); 
     424                light->setPosition(Vector3(x, 300, z + 200)); 
     425        } 
     426        else 
     427        { 
     428                light->setType(Light::LT_DIRECTIONAL); 
     429                light->setDirection(-1,-1,-1); 
     430        } 
     431        light->setDiffuseColour(ColourValue::White); 
     432        light->setSpecularColour(ColourValue(1, 1, 0.2)); 
     433 
     434        // Skybox 
     435        mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", mPlaneDim * 2); 
    402436} 
    403437 
     
    418452                "MySceneManager"); 
    419453        // set params for kdtree scene manager 
    420         if (mOptions.mSceneManager == KdTreeAppListener::SM_KDT) 
     454        if (mOptions.mSceneManager == KdTreeAppListener::SM_KDT ||  
     455                mOptions.mSceneManager == KdTreeAppListener::SM_KTE) 
    421456        { 
    422457                mSceneMgr->setOption("BuildMethod", &mOptions.mBuildMethod); 
     
    530565 
    531566        // create play button 
    532         mat = MaterialManager::getSingleton().create("KdTree/DemoPlayButton", "General"); 
     567        mat = MaterialManager::getSingleton().getByName("KdTree/DemoPlayButton"); 
     568        if (mat.isNull()) 
     569                mat = MaterialManager::getSingleton().create("KdTree/DemoPlayButton", "General"); 
    533570        mat->setLightingEnabled(false); 
    534571        tech = mat->getTechnique(0); 
     
    540577 
    541578        // create record button 
    542         mat = MaterialManager::getSingleton().create("KdTree/DemoRecordButton", "General"); 
     579        mat = MaterialManager::getSingleton().getByName("KdTree/DemoRecordButton"); 
     580        if (mat.isNull()) 
     581                mat = MaterialManager::getSingleton().create("KdTree/DemoRecordButton", "General"); 
    543582        mat->setLightingEnabled(false); 
    544583        tech = mat->getTechnique(0); 
Note: See TracChangeset for help on using the changeset viewer.