You need to create a meta selector. That meta selector has to know about the triangle selectors for everything that you want a given node to collide with. If you want the camera to collide with all faeries and the terrain, and a house, you need to create selectors for each of those things, add them to a meta selector, and use that meta selector for a collision response animator that is applied to the camera.
So first off, you need a triangle selector for every faerie. If you want to collide with terrain, you need to create a selector for the terrain.
Code: Select all
// assuming you have an array of faeries...
core::array<scene::ISceneNode*> faeries;
// give each faerie a triangle selector
for (u32 f = 0; f < faeries.size(); ++f)
{
scene::ITriangleSelector* selector = smgr->createTriangleSelectorFromBoundingBox( faeries[f] );
faeries[f]->setTriangleSelector( selector );
selector->drop();
}
// give the terrain a selector
scene::ITriangleSelector* selector = smgr->createTerrainTriangleSelector(terrain);
terrain->setTriangleSelector(selector);
selector->drop();
For camera collision, you make a meta selector and add each of the faerie triangle selectors to that. Then you pass that meta selector to the collision response animator, and then add that animator to the camera.
Code: Select all
// now create a collision response animator to keep the camera from running through the faeries or the ground.
scene::IMetaTriangleSelector* meta =
smgr->createMetaTriangleSelector();
for (u32 f = 0; f < faeries.size(); ++f)
{
meta->addTriangleSelector( faeries[f]->getTriangleSelector() );
}
meta->addTriangleSelector( terrain->getTriangleSelector() );
scene::ISceneNodeAnimator* anim =
smgr->createCollisionResponseAnimator(meta, faeries[f],
core::vector3df(30,50,30),
core::vector3df(0,-3,0),
core::vector3df(0,20,0));
camera->addAnimator(anim);
anim->drop();
If you want the faeries to not collide with each other, you build up a meta selector for each faerie. That meta selector would need to have triangle selectors for each of the other faeries and possibly the ground. You would create a collision animator for the meta selector, and add it to the faerie.
Code: Select all
// now create a collision response animator to keep each faerie from running into the others
for (u32 f = 0; f < faeries.size(); ++f)
{
scene::IMetaTriangleSelector* meta =
smgr->createMetaTriangleSelector();
for (u32 g = 0; g < faeries.size(); ++g)
{
if (g == f)
continue;
meta->addTriangleSelector( faeries[g]->getTriangleSelector() );
}
// you may not want or need this
// meta->addTriangleSelector( terrain->getTriangleSelector() );
scene::ISceneNodeAnimator* anim =
smgr->createCollisionResponseAnimator(meta, faeries[f],
core::vector3df(30,50,30),
core::vector3df(0,-3,0),
core::vector3df(0,20,0));
faeries[f]->addAnimator(anim);
anim->drop();
}
If you are loading this stuff from an .irr file, I have posted some code that may help you
here. I have also posted some useful code
here.
Travis