I have managed to load a .irr file and apply collision to it. After that i added a collisionanimator to an object(the player). When i start the game the player falls down on the landscape and stands on it. No problem.
The .irr files consists of one terrain generated from a bitmap.
Now the problem is. As soon as i add a cube/mesh/sphere or any form into the irr file. The collision disappears when i start the game :/
Here is the code for creating the triangle selector thing.
Code: Select all
ITriangleSelector * selector = 0;
// load the scene
smgr->loadScene("data/scenes/testlv2.irr");
IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();
array<ISceneNode *> nodes;
smgr->getSceneNodesFromType(ESNT_ANY, nodes); // Find all nodes
for (u32 i=0; i < nodes.size(); ++i)
{
ISceneNode * node = nodes[i];
switch(node->getType())
{
case scene::ESNT_CUBE:
case scene::ESNT_ANIMATED_MESH:
// Because the selector won't animate with the mesh,
// and is only being used for camera collision, we'll just use an approximate
// bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
selector = smgr->createTriangleSelectorFromBoundingBox(node);
break;
case scene::ESNT_MESH:
case scene::ESNT_SPHERE: // Derived from IMeshSceneNode
selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
case scene::ESNT_TERRAIN:
selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);
break;
case scene::ESNT_OCT_TREE:
selector = smgr->createOctTreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node);
break;
default:
// Don't create a selector for this node type
break;
}
if(selector)
{
// Add it to the meta selector, which will take a reference to it
meta->addTriangleSelector(selector);
// And drop my reference to it, so that the meta selector owns it.
selector->drop();
}
}
if (selector){ //Set col animator to draPlayer
ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, draPlayer, vector3df(10,20,10),vector3df(0,0,0),vector3df(0,50,0));
selector->drop();
draPlayer->addAnimator(anim);
anim->drop();
}
Thanks.
-Ali
EDIT:
I tried removing the terrain and adding a simple cube. It worked. As soon as i add a second cube the collision is turned off.
All textures are loaded succesfully btw.
One more thing. I have my own gravity inmplemented (i tried changing to the default grav, didnt work either. Fell right through the floor).
EDIT2:
I turned off all gravity and tried to move to collide with a wall. And it worked! Apperantly only the floor's collision is gone... Why??
EDIT3:
I noticed one more thing. Only the latest cube i added into irredit has collision applied to it. All other are ignored.