(ENG) Sudi's Octree: Advanced use.
Stai invece cercando la versione italiana di questo tutorial? ( )
Licenzed under Creative Commons ShareAlike noncommercial 2.5 by Dario "Demone Rosso". (Red Demon).
First of all download Sudi's code. I linked his code in this article about his Octree.
This tutorial show how to use multiple Sudi's Octree SceneManager. This can be usefull for someone (for example who is using different Octrees at the same time: applications with multiple windows). I show here how to create lots of OctreeManager, how to add child to them and how to remove them from memory without causing a memory leach.
#include <irrlicht.h> //download Irrlicht package to get the header
#include <iostream> //I get here the rand() function
#include "COcttreeManager.h" //I have linked it from
here
#include "ImprovedCOttreeManager.h" //this will be
released within my game
#include "driverChoice.h" //download Irrlicht package to get this header
using namespace
irr; //then use proper namespaces
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
int
main() // main method
{
//a variable for use the improved octree.
//actually there is no release for it.
bool useImprovedOctree = false;
// Ask for player to select a render driver
E_DRIVER_TYPE driverType = driverChoiceConsole();
if ( driverType ==
EDT_COUNT )
return 1;
// create the IrrlichtDevice in wich we run our game
IrrlichtDevice *device = createDevice( driverType,
dimension2d<u32>(640, 480), 32, false);
if (!device)
return
2;
//get the scene manager
ISceneManager* smgr = device->getSceneManager();
// I declare here some variables I'm going to use
array<ISceneNode *> managerList; //an array of Sudi's
OctreeManagers.
array<ISceneNode *> childList;
ISceneNode* node=0;
//Allocate arrays.
u16 aSize =
256;
managerList.reallocate( aSize );
childList.reallocate( aSize
);
for (u16 i=0; i<aSize; i++)
{
if( useImprovedOctree ) //for now I continue to use original code
managerList[i] = new COcttreeManager(smgr->getRootSceneNode(), smgr,
irr::core::aabbox3d<irr::f32>
(-1000,-1000,-1000,1000,1000,1000) );
else
managerList[i] = new COcttreeManager(smgr->getRootSceneNode(), smgr,
irr::core::aabbox3d<irr::f32>
(-1000,-1000,-1000,1000,1000,1000) );
//now that we have created the OctreeManager we fill it with
childs
for(u16 j=0; j<aSize; j++)
{
node = smgr->addCubeSceneNode(5.0f, managerList[i],i*aSize+j+1001,
vector3df( (f32)(rand()%1800-900),
(f32)(rand()%1800-900),
(f32)(rand()%1800-900) )
); //create a cube
node->setParent(managerList[i]); //add it to the octree manager
}
device->run(); //draw the scene once.
driver->beginScene(true, true, SColor(0,130,130,130));
smgr->drawAll();
driver->endScene();
managerList[i]->setParent(0); //remove the octree manager from smgr
managerList[i]->drop(); //drop it. Now it will be deleted.
}
device->closeDevice();
device->run();
device->drop();
return 0; //end of program
}