Object ID and Mask!

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
Isoprog
Posts: 80
Joined: Wed Dec 10, 2008 7:53 am

Object ID and Mask!

Post by Isoprog »

Hi,
I am having a little problem with object id and mask. I just wanted to know how do I use id with mask for a scene node?
I am using like this:

Code: Select all

Mask::Node | objectID
While it works, there is a problem with this. Say if mask Node is -> 1 << 2, you can imagine what will happen. First 8 node will have same id, 0-4.
I need this for picking and getting a node.

Thanks in advance.
Regards.
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Object ID and Mask!

Post by hybrid »

Yeah, you have to create the ids accordingly. Say, take the lower 16bits for numbering the nodes (from 1..65535) and the upper 16 bits for defining properties and classes. All nodes belonging to NPC types have 1<<24 set, etc. Then you can mask based on the type with upper bit masks, and still have a unique numbering in the lower bits.
Isoprog
Posts: 80
Joined: Wed Dec 10, 2008 7:53 am

Re: Object ID and Mask!

Post by Isoprog »

I am a little confused about numbering the node with lower bitmask. Could you kindly explain a little please.
Thanks for the reply.

Regards
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Object ID and Mask!

Post by hybrid »

Just number the nodes with numbers below a certain threshold, in my example 65535, i.e. representable within 16bit. Then, inorder to group or characterize your nodes, you set cetain bits in the upper 2 bytes of the ID via bitwise OR

Code: Select all

 
// initial numbering
node->setID(192);
// several types of nodes in your app
enum E_MY_NODE_TYPES
{
    E_BUILDING=1<<17,
    E_NPC=1<<18,
    E_VEGETATION=1<<19
};
// make node vegetation
node->setID(node->getID()|E_VEGETATION);
// or to be sure to have just one class, also when changing types later on
node->setID((node->getID()&0xffff)|E_BUILDING);
 
You can also mix several types and characterizations, e.g. add an 'unimportant' flag for things which you can avoid to render if on low-end platforms. Such values can then also be added to the ID via some more OR operators.
For bitmasks you can then choose, e.g. E_VEGETATION, as bitmask to search for all nodes belonging to that class.
Isoprog
Posts: 80
Joined: Wed Dec 10, 2008 7:53 am

Re: Object ID and Mask!

Post by Isoprog »

Ok, got it. Thanks for the reply.

Regards.
Post Reply