Collecting of selectors

A forum to store posts deemed exceptionally wise and useful
Post Reply
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Collecting of selectors

Post by etcaptor »

Hi all,
Because in Beginners Help forum still appears questions about it, I deside me to write a function for easy using of selectors when Irrlicht collision is needed. This function can be base for easy creating of collision type "each to each". Also avoid autocollision. Each node must have one MetaTriangleSelector. This meta selector consist selectors for all nodes except this node.

Code: Select all

IMetaTriangleSelector* CreateMetaSelectorForWorldNodes(ISceneNode* Node)
{
   IMetaTriangleSelector * WorldNodesMetaTriangleSelector = SceneManager->createMetaTriangleSelector(); //will consist selectors of all nodes without this Node

    SceneManager->getRootSceneNode()->getChildren();
    const core::list<ISceneNode*>& children = SceneManager->getRootSceneNode()->getChildren();
    core::list<ISceneNode*>::Iterator it = children.begin();

	for (; it != children.end(); ++it)
	{
       ISceneNode* current = *(it);

        if(current)
        {
          if(current->getTriangleSelector() && current != Node)
            WorldNodesMetaTriangleSelector->addTriangleSelector(current->getTriangleSelector());

        }
    }
   return WorldNodesMetaTriangleSelector;
}
Using:

1. loading of some node

Code: Select all

scene::IAnimatedMesh* faerie = smgr->getMesh("../../media/faerie.md2");
scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(faerie);
2. Creating of selector for this node

Code: Select all

smgr->createTriangleSelectorFromBoundingBox (node);
3. Collect selectors for all nodes except this node

Code: Select all

 IMetaTriangleSelector* metaselector = CreateMetaSelectorForWorldNodes(node) ;
4. Set this metaselector

Code: Select all

node->setTriangleSelector(metaselector);
5. Creating of collisionResponeAnimator

Code: Select all

scene::ISceneNodeAnimator* anim =    smgr->createCollisionResponseAnimator(
		metaselector, node, core::vector3df(30,50,30),
		core::vector3df(0,-3,0),
		core::vector3df(0,50,0));
	node->addAnimator(anim);
So, this node must be collided with all world nodes.
You can expand this example by adding of some idBitMask parameter if you want creating of some type of selective collision by groups.
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
Seifsta
Posts: 2
Joined: Sat May 05, 2007 11:11 pm

Post by Seifsta »

Sorry to revive an old thread, but I have implemented a similar technique to this, and have found I am getting a serious performance drop after i add about 5 nodes. Anyone else experience this problem?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Maybe you are creating a new triangle selecter each time instead of using the one linked to the node like this method? I recommend you reuse the same triangle selector for each node. You are probably re-making it every time you add a node (For the other nodes that already have one.).

Are you use "getTriangleSelector()" from the scene node like this guy?

ALSO, I dont see a method here to check if the "current" node is not the node you are adding collision to? Hmmm... And why are you setting the triangle selector for the node to world triangle selector? This only needs to be passed as a parameter to its collision animator to work, which you are already doing.

There is also a random "getChildren()" (Before the for loop) from the root scene node that is repeated, the first one is redundant and should be remo

Anyway this code has alot of randomnesses in it but I think its a good idea, especially when combined with some sort of bitmasking as suggested.
Seifsta
Posts: 2
Joined: Sat May 05, 2007 11:11 pm

Post by Seifsta »

Hi, what I decided to do was to make two seperate collision response animators, one for nodes and world, and one fof between nodes.
Each node has its own meta selector,

It's pretty much working now, Although I can't really post it in its current state. Its looks a hell of a lot different from this solution now.

2 Questions though.

1) does the collision response animator allow selectors to be added to the meta selector in runtime ( i need this for when i add a new nodes bounding box to current nodes meta selector )

2) although it works, nodes on top of nodes are jerky as. I believe this to be due to the fact of the 2 collision response animators fighting each other. any suggestion on how to combat this?
Post Reply