Diference between 0 and (1 << 0)?

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.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Returning to the 07.Collision example.

It is possible to get rid of bitwise implementation and use a struct to hold all necessary data that describes the node. In this case we can extend the struct to hold any type of data. Also we add an array to hold each node' data.
That may look like:

Code: Select all

// Holds all necessary info to describe the node.
// Note: unlike to bitwise implementation (the original) this struct can be extended to hold any type of data (not only flags).
struct NodeInfo
{
	bool IsPickable;
	bool IsHighlightable;

	NodeInfo(bool pickable, bool highlightable)
	{
		IsPickable = pickable;
		IsHighlightable = highlightable;
	}
};

// Array of all node' descriptions.
// Note: node' ID is an index in this array.
core::array<NodeInfo> NodeInfoArray;
When we need to describe a node, we use next:

Code: Select all

		NodeInfoArray.push_back(NodeInfo(true, false));
		q3node = smgr->addOctreeSceneNode(q3levelmesh->getMesh(0), 0, NodeInfoArray.size() - 1);
When we need to call getSceneNodeAndCollisionPointFromRay() we do not use idBitMask argument at all (because its useless in our case); instead we just add additional condition to returned node, like:

Code: Select all

		if (selectedSceneNode &&
			NodeInfoArray[selectedSceneNode->getID()].IsPickable)
		{
			...
:arrow: Full working updated source can be found at - http://irrlichtirc.g0dsoft.com/pastebin/view/7206407
Post Reply