I have a FOR loop that adds to all the boxes the metaselector.
That isn't what your code is showing. You need to create just one meta selector and one collision response animator.
Code: Select all
// just do this once
IMetaTriangleSelector* meta = smgr->createMetaTriangleSelector();
Then you need to add all of the selectors you create to that meta selector.
Code: Select all
for (u32 wh = 0; wh < N; ++wh)
{
// create selector for each cube
ITriangleSelector* selector = smgr->createTriangleSelectorFromBoundingBox(OJ[wh].Cube);
OJ[wh].Cube->setTriangleSelector(selector);
selector->drop();
// add each selector to the meta selector
meta->addTriangleSelector(selector);
}
Finally, create one collision animator
Code: Select all
ISceneNodeAnimator* RATRR = smgr->createCollisionResponseAnimator(meta, MainCamera, 5.f, vector3df(0,0,0), vector3df(0,0,0), .00005f);
MainCamera->addAnimator(RATRR);
RATRR->drop();
I posted code a while back that would generate triangle selectors for everything, and add them to a meta selector for you. The original post is in
this thread. I later posted some code to only consider collisions with objects near the camera. You can see that
here.
Here is a quick and dirty description of how this code works.
- ISceneManager_assignTriangleSelectors(ISceneManager* smgr, IFileSystem* ifs) generates collision information for every oct tree, mesh, animated mesh, terrain and cube scene node in the scene indicated by smgr. It does this by calling the next function. When this function returns, all of the collidable node types mentioned above will have their own triangle selector assigned.
- ISceneNode_assignTriangleSelectors(ISceneNode* node, ISceneManager* smgr, IFileSystem* ifs) assigns a triangle selector to the scene node node by calling the next function. It then calls itself recursively, so every node in the scene graph will have had this function called on itself.
- ISceneNode_assignTriangleSelector(ISceneNode* node, ISceneManager* smgr, IFileSystem* ifs) creates a triangle selector for the scene node node if possible. This code only works for oct tree, mesh, animated mesh, terrain and cube scene nodes. You could modify it to support other node types if you wanted, and you could modify it to create the selectors differently also [use a different lod for the terrain, or different parameters for the oct tree selector].
- ISceneManager_gatherTriangleSelectors(ISceneManager* smgr, IMetaTriangleSelector* meta) recursively gathers triangle selectors for all scene nodes that have them. All selectors are put into the meta selector. You could modify this function to filter which nodes are added or not. You could filter by name, id, address, or anything else if you felt the need.
- ISceneNode_gatherTriangleSelectors(ISceneNode* node, IMetaTriangleSelector* meta) adds the selector for node, if it has one, to meta, and then calls itself recursively on the children of node. This effectively gathers all selectors from node and all of its children/grandchildren/great-grand... into meta.
None of this code takes object position coherency into account, and the meta selector contains all of the selectors of all scene nodes. If your scene has many scene nodes, or your nodes have many triangles, then this primitive collision stuff probably won't work for you without some modification.
Travis