Page 1 of 1

getSceneNodeFromRayBB how to use idBitMask?

Posted: Fri Apr 04, 2008 6:03 am
by kornwaretm
i just realize that using getSceneNodeFromRayBB is faster than using loop for testing collision. but it return the closest node only. that in my case the sword that the ray i cast from. i think if i can filter the result with this idBitMask parameter to advoid returning the sword it self or the node that holding it. but how to use this idBitMask?
this is my code

Code: Select all

if(actors[i]->input->action==TPS_SPEED){
									vector3df firstPoint = actors[i]->hand->getAbsolutePosition();
									vector3df secondPoint = actors[i]->senjataAct->eye->getAbsolutePosition();
									ISceneNode* Victim = smgr->getSceneCollisionManager()->getSceneNodeFromRayBB(line3d<f32>(firstPoint,secondPoint),(s32)111,true);
									if(Victim){
										castAnimatedBilboard(secondPoint,blood);
										if((Victim->getID()==10)){//&&(Victim!=actors[i]->node)){
											Victim->setVisible(false);
										}
									}
								}

Posted: Fri Apr 04, 2008 8:36 am
by rogerborg
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.

Posted: Fri Apr 04, 2008 8:49 am
by MasterGod
BitwiseMagic - I love it!

Posted: Fri Apr 04, 2008 9:05 am
by kornwaretm
woooooooooooooooooowwwwwwwwwwwwwwwwwww
WWWWWWWWWWOOOOOOOOOOWWWWWWWWWWWWW
you save me one more time rogerborg. thank you so much

by the way
i never see operator like << ??? is it operator??
1<<2 is this means (x>=1) && (x<2) ?

Posted: Fri Apr 04, 2008 9:27 am
by MasterGod
0x00000001 << 2
==
0x00000100

Shift left on bits

Posted: Fri Apr 04, 2008 9:44 am
by shogun
MasterGod wrote:0x00000001 << 2
==
0x00000100

Shift left on bits
0x is for hexadecimal.

Posted: Fri Apr 04, 2008 11:22 am
by rogerborg
kornwaretm wrote: by the way
i never see operator like << ??? is it operator??
1<<2 is this means (x>=1) && (x<2) ?
As MasterGod (mostly) said, it's the bit shifting operator, not to be confused with the C++ stream insertion/extraction operators.

Bit shifting is core to a lot of useful operations, so it's worth taking the time to understand it, along with bitwise logic.

You'll want to refresh yourself on that as well, so that you're clear on why a collision bitmask of (e.g.) 3 would match scene nodes with numerical IDs of 3, 7, 11, 15...

Posted: Fri Apr 04, 2008 5:51 pm
by Swarmer
rogerborg wrote:GOBLIN_EJACULATE_COLLISION_BIT
WHYYYY

Posted: Fri Apr 04, 2008 6:42 pm
by Acki
rogerborg wrote:GOBLIN_EJACULATE_COLLISION_BIT
are you doing a fantasy porn game !?!?! :lol:

Posted: Mon Apr 07, 2008 6:38 am
by kornwaretm
GOBLIN_EJACULATE_COLLISION_BIT
i wonder how it's look :lol:


thanks everyone for helping.
just need some times to read bitWise