dynamic maps

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Asteroth
Posts: 11
Joined: Tue Feb 13, 2007 2:33 am

dynamic maps

Post by Asteroth »

I've had a look through the forums and can't seem to find an answer to this question so thought I'd create a new post.

Basically I have a basic level stored in a .pk3 file, but I want to be able to add meshscenenodes dynamically to it, for example so I can create a new random maze each time the game is loaded.

I have a basic meshscenenode for a wall segment stored in a file. The mesh displays fine, however when I try and add collision detection to my player, weird things start to happen! Am I going about this the right way? code outlined below.

Thanks in advance!

Code: Select all


//load basic map -----------------------------------

//unzip file
device->getFileSystem()->addZipFileArchive(mapfile);

//get mesh information
scene::IAnimatedMesh* worldMesh = smgr->getMesh(bspfile);
	
//create world node
scene::ISceneNode* worldNode = 0;

if (worldMesh)
    worldNode = smgr->addOctTreeSceneNode(worldMesh->getMesh(0));

 //triangle selector object used for collision detection
scene::ITriangleSelector* selector = 0;

if (worldNode)		
{
  mapSelector = smgr->createOctTreeTriangleSelector(worldMesh->getMesh(0), worldNode, 128);
		
  //add the triangle mesh to map node
  worldNode->setTriangleSelector(mapSelector);  
}

//load wall mesh -------------------------
device->getFileSystem()->addZipFileArchive(wallfile);

//get mesh information
wallMesh = smgr->getMesh(wallbspfile);
		
scene::ISceneNode* wallNode = 0;

if (wallMesh)
  wallNode = smgr->addOctTreeSceneNode(wallMesh->getMesh(0),smgr->getRootSceneNode());

//create triangle selector object used for collision detection
scene::ITriangleSelector* selector = 0;

if (wallNode) 
{		
  wallNode->setPosition(core::vector3df(100,0,100));

  scene::ITriangleSelector* wallSelector = smgr->createOctTreeTriangleSelector(wallMesh->getMesh(0), wallNode, 128);

  //add the triangle mesh to map node
  wallNode->setTriangleSelector(wallSelector);  
}	

//add collision detection animators to player	------------------	

//create animator for map
scene::ISceneNodeAnimator* mapAnim = smgr->createCollisionResponseAnimator(
  mapSelector, 
  player, 
  core::vector3df(10,10,10),
  core::vector3df(0,-1,0),
  core::vector3df(0,10,0)
);

player->addAnimator(mapAnim);
mapAnim->drop();
mapSelector->drop();

//create animator for wall
scene::ISceneNodeAnimator* wallAnim = smgr->createCollisionResponseAnimator(
  wallSelector, 
  player, 
  core::vector3df(10,10,10),
  core::vector3df(0,-1,0),
  core::vector3df(0,10,0)
);

player->addAnimator(wallAnim);
wallAnim->drop();
wallSelector->drop();



roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

if you want to generate random maze then take some scene space, lets say 10x10. take a wall mesh and randomly put it on this field. it wont look like a maze for the first time. you will have to think and add more random generation rules, then it would look like map ;) i even didnt look at your code, im not familar with irrlicht collisions. i use newton myself and my advice for you is to use newton too :P
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You should not add multiple collison animators to the same scene node. That can cause weird things to happen. You should instead use a IMetaTriangleSelector to hold all of the triangle selectors, and then use that to create a single collision animator...

I posted some code a while back on creating collision information from a scene that is already all built up. You could just build your scene like you want it, then call the functions I wrote to build up triangle selectors for each scene node and then build up a collision animator from the selectors. You can find that code here

Travis
Asteroth
Posts: 11
Joined: Tue Feb 13, 2007 2:33 am

Post by Asteroth »

IMetaTriangleSelector is just what I was looking for, thanks vitek! i'll have a go at it.

Right now all I need is collision detection, so Newtons a bit overkill for my purposes, but thanks for the advice roxaz.
Asteroth
Posts: 11
Joined: Tue Feb 13, 2007 2:33 am

Post by Asteroth »

just tried it out, works like a dream! thanks :)
Post Reply