That's my first post, I'm just begginning whith 3D and object programming so please be kind ^^ (I'm a C and web 19 years old programmer)
My problem is that, I followed a french tutorial and understood the base of Ogre, the Scene, the notion of Node, Entities, Camera, textures, ressources etc...
I would like creating a minecraft-like 3D engine so I decided to create it
Shame on me, I programmed it the baddest way you could programmed it (I think), in fact, it's slow with only 100*100 cubes on the screen !
my code to create this evil program (please bless me ^^')
Everything is in this little part, world is defined before and contain here a 100*100*100 array, just a layer of 100*100 is filled by the 1 value (and puttend on the screen)
Code: Select all
void AppDemarrage::AfficherSol()
{
int x,y,z;
Ogre::Entity ** cubesTab = new Ogre::Entity * [world->getNbCube()];
Ogre::SceneNode ** cubesNodeTab = new Ogre::SceneNode * [world->getNbCube()];
Ogre::SceneNode * mainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
for(z=0;z!=world->p();z++)
{
for(y=0;y!=world->h();y++)
{
for(x=0;x!=world->w();x++)
{
int valCase=world->getCase(x,y,z);
int indexCase=world->ind(x,y,z);
if(valCase!=0)
{
// we create the cube
cubesTab[indexCase]=mSceneMgr->createEntity("cube"+intToStr(x)+"-"+intToStr(y)+"-"+intToStr(z), "cube.mesh");
cubesNodeTab[indexCase] = mainNode->createChildSceneNode();
cubesNodeTab[indexCase]->attachObject(cubesTab[indexCase]);
cubesNodeTab[indexCase]->setPosition(x*100,y*100,z*100);
// we apply the texture in function of the block's type...
switch(valCase)
{
case 1:
cubesTab[indexCase]->setMaterialName("cube");
break;
}
}
}
}
}
}
http://hpics.li/88aacec
I know this is really dirty, I would appreciate know which direction choose to improve it, I know a little about Chunk, ManualObject, Culling... I don't know what is REALLY important.