getSceneNodeFromRayBB how to use idBitMask?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
kornwaretm
Competition winner
Posts: 189
Joined: Tue Oct 16, 2007 3:53 am
Location: Indonesia
Contact:

getSceneNodeFromRayBB how to use idBitMask?

Post 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);
										}
									}
								}
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post 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.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

BitwiseMagic - I love it!
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
kornwaretm
Competition winner
Posts: 189
Joined: Tue Oct 16, 2007 3:53 am
Location: Indonesia
Contact:

Post 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) ?
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

0x00000001 << 2
==
0x00000100

Shift left on bits
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

MasterGod wrote:0x00000001 << 2
==
0x00000100

Shift left on bits
0x is for hexadecimal.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post 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...
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Swarmer
Posts: 100
Joined: Mon Apr 16, 2007 7:23 am

Post by Swarmer »

rogerborg wrote:GOBLIN_EJACULATE_COLLISION_BIT
WHYYYY
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

rogerborg wrote:GOBLIN_EJACULATE_COLLISION_BIT
are you doing a fantasy porn game !?!?! :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
kornwaretm
Competition winner
Posts: 189
Joined: Tue Oct 16, 2007 3:53 am
Location: Indonesia
Contact:

Post by kornwaretm »

GOBLIN_EJACULATE_COLLISION_BIT
i wonder how it's look :lol:


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