Page 1 of 1

setFog Problem !!!

Posted: Fri Jul 04, 2008 3:02 pm
by CaPGeti
Hy....
How can I use fog for a .irr???
because, to get fog I enable EMF_FOG_ENABLE from a Mesh. But i have a scene!!!

Posted: Fri Jul 04, 2008 3:05 pm
by JP
Walk through the scene from smgr->getRootNode() through all the children, and the children of the children etc. and turn on the fog for each node that requires it to be on.

Posted: Fri Jul 04, 2008 3:12 pm
by CaPGeti
ah....sry for my english, but I come from germany. And i new in irrlicht.

How can I get the children?? Can you give me a example please? Sry but I don't know how I solve this.

Posted: Fri Jul 04, 2008 3:49 pm
by JP
If you need to know something the API is your first port of call :)

If you look up ISceneNode you will find a function called getChildren which returns you a list of all the children so you iterate through each child and set the fog (if necessary) and then iterate through each of those child's children and keep repeating until you've done all the nodes, a recursive function is obviously the best way to achieve this.

Posted: Fri Jul 04, 2008 4:20 pm
by rogerborg

Code: Select all

void turnOnFog(scene::ISceneNode * node)
{
	switch(node->getType())
	{
		// Turn on fog for appropriate node types, casting as necessary

	default:
		// Do nothing
		break;
	}
}


// Recurses through all the scene nodes, and passes each one to a function that
// does whatever you want with it. To do different things to every node, just
// call this function with a different "action" function parameter.
void recurseThroughAllNodes(scene::ISceneNode * node, void(*action)(scene::ISceneNode *))
{
	action(node);

	core::list<scene::ISceneNode*> children = node->getChildren();
	core::list<scene::ISceneNode*>::Iterator childIterator = children.begin();
	core::list<scene::ISceneNode*>::Iterator end = children.end();

	while(childIterator != end)
	{
		recurseThroughAllNodes(*childIterator, action);
		childIterator++;
	}
}

//...
// Then kick it off from the root of the scene tree by calling..

recurseThroughAllNodes(smgr->getRootSceneNode(), turnOnFog);

Posted: Thu Jul 10, 2008 1:00 am
by doqkhanh
I have a simple solution ;))

1. Open your irr file with notepad or vi

2. Replace

Code: Select all

<bool name="FogEnable" value="false" />
with

Code: Select all

<bool name="FogEnable" value="true" />

Posted: Thu Jul 10, 2008 10:08 am
by rogerborg
Oh, well, if you want to do it the easy way, then I suppose that's fine. :P

Actually, being serious, I doubt that you'd want to switch on fog for all materials, which is why there's a switch() in the sample code above.