OK, first things first. By default, all Irrlicht scene nodes are created with an ID of -1. This means that they have all bits set, and so they will match with any (non 0) bitmask that you provide. This is generally
not what you want, so you will have to set the ID of every scene node to something other than the default -1 in order to stop them being matched in collisions.
After that, you need to decide how many types of collision you need to deal with. If you only have one sort of collision, then you just need to use one bit of the ID, e.g. the low bit.
In the simplest case, you'd give all nodes that you don't want to collide with an ID of 0, and the nodes that you do want to collide with an ID of 1 (i.e. 1 << 0), then you'd pass 1 as the bitmask.
If you need to test different types of collisions, then set different bits. I'd use an enum to define them, e.g.:
Code: Select all
enum
{
BULLET_COLLISION_BIT = 1 << 0,
SPELL_COLLISION_BIT = 1 << 1,
GOBLIN_EJACULATE_COLLISION_BIT = 1 << 2
};
// This node can collide with bullets and spells
node1->setID(BULLET_COLLISION_BIT | SPELL_COLLISION_BIT);
// This node collides with bullets and goblin ejaculate, but not spells
node2->setID(BULLET_COLLISION_BIT | GOBLIN_EJACULATE_COLLISION_BIT);
node3->setID(0);
node4->setID(0);
// and all other nodes that shouldn't collide get an ID of 0
// .. later ..
// Check for nodes that have the SPELL_COLLISION_BIT set. This will hit node1,
// but not node2 (or node3, node4 ...)
ISceneNode* Victim = smgr->getSceneCollisionManager()->getSceneNodeFromRayBB(
line3d<f32>(firstPoint,secondPoint),(s32)SPELL_COLLISION_BIT, true)
Note that because you're only using some of the bits in the ID, you can still use the rest of the ID to uniquely identify nodes; just make sure you mask off the collision bits when you set the other bits.