Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > contrib-release > by-pkgid > 58828b263d8f56d90ac336dea07a4586 > files > 751

irrlicht-doc-1.6.1-1mdv2010.1.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Irrlicht Engine: Tutorial 20: Managed Lights</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<table class="irrlicht" >
  <tr valign="middle"> 
    <td><font size="2"><a class="qindex" href="index.html"><font color="#FFFFFF">Home</font></a> 
      | <a class="qindex" href="namespaces.html"><font color="#FFFFFF">Namespaces</font></a> 
      | <a class="qindex" href="hierarchy.html"><font color="#FFFFFF">Hierarchy</font></a> 
      | <a class="qindex" href="classes.html"><font color="#FFFFFF">Alphabetical 
      List</font></a> | <a class="qindex" href="annotated.html"><font color="#FFFFFF"> 
      Class list</font></a> | <a class="qindex" href="files.html"><font color="#FFFFFF">Files</font></a> 
      | <a class="qindex" href="namespacemembers.html"><font color="#FFFFFF"> 
      Namespace&nbsp;Members</font></a> | <a class="qindex" href="functions.html"><font color="#FFFFFF">Class 
      members</font></a> | <a class="qindex" href="globals.html"><font color="#FFFFFF">File 
      members</font></a> | <a class="qindex" href="pages.html"><font color="#FFFFFF">Tutorials</font></a></font> </td>
  </tr>
</table>
<!-- Generated by Doxygen 1.5.6 -->
<div class="contents">
<h1><a class="anchor" name="example020">Tutorial 20: Managed Lights </a></h1><div align="center">
<img src="020shot.jpg" alt="020shot.jpg">
</div>
 <p>
Written by Colin MacDonald. This tutorial explains the use of the Light Manager of Irrlicht. It enables the use of more dynamic light sources than the actual hardware supports. Further applications of the Light Manager, such as per scene node callbacks, are left out for simplicity of the example. <div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>
<span class="preprocessor">#include &lt;iostream&gt;</span>

<span class="keyword">using namespace </span>irr;
<span class="keyword">using namespace </span>core;
<span class="keyword">using namespace </span>scene;
<span class="keyword">using namespace </span>video;
<span class="keyword">using namespace </span>io;
<span class="keyword">using namespace </span>gui;

<span class="preprocessor">#if defined(_MSC_VER)</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span>
<span class="preprocessor">#endif // MSC_VER</span>
</pre></div><p>
Normally, you are limited to 8 dynamic lights per scene: this is a hardware limit. If you want to use more dynamic lights in your scene, then you can register an optional light manager that allows you to to turn lights on and off at specific point during rendering. You are still limited to 8 lights, but the limit is per scene node.<p>
This is completely optional: if you do not register a light manager, then a default distance-based scheme will be used to prioritise hardware lights based on their distance from the active camera.<p>
NO_MANAGEMENT disables the light manager and shows Irrlicht's default light behaviour. The 8 lights nearest to the camera will be turned on, and other lights will be turned off. In this example, this produces a funky looking but incoherent light display.<p>
LIGHTS_NEAREST_NODE shows an implementation that turns on a limited number of lights per mesh scene node. If finds the 3 lights that are nearest to the node being rendered, and turns them on, turning all other lights off. This works, but as it operates on every light for every node, it does not scale well with many lights. The flickering you can see in this demo is due to the lights swapping their relative positions from the cubes (a deliberate demonstration of the limitations of this technique).<p>
LIGHTS_IN_ZONE shows a technique for turning on lights based on a 'zone'. Each empty scene node is considered to be the parent of a zone. When nodes are rendered, they turn off all lights, then find their parent 'zone' and turn on all lights that are inside that zone, i.e. are descendents of it in the scene graph. This produces true 'local' lighting for each cube in this example. You could use a similar technique to locally light all meshes in (e.g.) a room, without the lights spilling out to other rooms.<p>
This light manager is also an event receiver; this is purely for simplicity in this example, it's neither necessary nor recommended for a real application. <div class="fragment"><pre class="fragment"><span class="keyword">class </span>CMyLightManager : <span class="keyword">public</span> ILightManager, <span class="keyword">public</span> IEventReceiver
{
        <span class="keyword">typedef</span> <span class="keyword">enum</span>
        {
                NO_MANAGEMENT,
                LIGHTS_NEAREST_NODE,
                LIGHTS_IN_ZONE
        }
        LightManagementMode;

        LightManagementMode Mode;
        LightManagementMode RequestedMode;

        <span class="comment">// These data represent the state information that this light manager</span>
        <span class="comment">// is interested in.</span>
        ISceneManager * SceneManager;
        core::array&lt;ILightSceneNode*&gt; * SceneLightList;
        <a class="code" href="namespaceirr_1_1scene.html#7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">E_SCENE_NODE_RENDER_PASS</a> CurrentRenderPass;
        ISceneNode * CurrentSceneNode;

<span class="keyword">public</span>:
        CMyLightManager(ISceneManager* sceneManager)
                : Mode(NO_MANAGEMENT), RequestedMode(NO_MANAGEMENT),
                SceneManager(sceneManager),  SceneLightList(0),
                CurrentRenderPass(<a class="code" href="namespaceirr_1_1scene.html#7862269bd1abc123929d4dbb8200d67f1f79a46e7a41716dcae5c8dfe8d310bb" title="No pass currently active.">ESNRP_NONE</a>), CurrentSceneNode(0)
        { }

        <span class="keyword">virtual</span> ~CMyLightManager(<span class="keywordtype">void</span>) { }

        <span class="comment">// The input receiver interface, which just switches light management strategy</span>
        <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent &amp; event)
        {
                <span class="keywordtype">bool</span> handled = <span class="keyword">false</span>;

                <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#c9eed96e06e85ce3c86fcbbbe9e48a0c6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> &amp;&amp; event.KeyInput.PressedDown)
                {
                        handled = <span class="keyword">true</span>;
                        <span class="keywordflow">switch</span>(event.KeyInput.Key)
                        {
                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb361ec605d669b598d2e7106981a326fde">irr::KEY_KEY_1</a>:
                                RequestedMode = NO_MANAGEMENT;
                                <span class="keywordflow">break</span>;
                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb3a7574bf313b5c29547f01c36f0a4a4f8">irr::KEY_KEY_2</a>:
                                RequestedMode = LIGHTS_NEAREST_NODE;
                                <span class="keywordflow">break</span>;
                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb3577dcff3b86e6dd45f70d8c691dd3c91">irr::KEY_KEY_3</a>:
                                RequestedMode = LIGHTS_IN_ZONE;
                                <span class="keywordflow">break</span>;
                        <span class="keywordflow">default</span>:
                                handled = <span class="keyword">false</span>;
                                <span class="keywordflow">break</span>;
                        }

                        <span class="keywordflow">if</span>(NO_MANAGEMENT == RequestedMode)
                                SceneManager-&gt;setLightManager(0); <span class="comment">// Show that it's safe to register the light manager</span>
                        <span class="keywordflow">else</span>
                                SceneManager-&gt;setLightManager(<span class="keyword">this</span>);
                }

                <span class="keywordflow">return</span> handled;
        }


        <span class="comment">// This is called before the first scene node is rendered.</span>
        <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnPreRender(core::array&lt;ILightSceneNode*&gt; &amp; lightList)
        {
                <span class="comment">// Update the mode; changing it here ensures that it's consistent throughout a render</span>
                Mode = RequestedMode;

                <span class="comment">// Store the light list. I am free to alter this list until the end of OnPostRender().</span>
                SceneLightList = &amp;lightList;
        }

        <span class="comment">// Called after the last scene node is rendered.</span>
        <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnPostRender()
        {
                <span class="comment">// Since light management might be switched off in the event handler, we'll turn all</span>
                <span class="comment">// lights on to ensure that they are in a consistent state. You wouldn't normally have</span>
                <span class="comment">// to do this when using a light manager, since you'd continue to do light management</span>
                <span class="comment">// yourself.</span>
                <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); i++)
                        (*SceneLightList)[i]-&gt;setVisible(<span class="keyword">true</span>);
        }

        <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRenderPassPreRender(<a class="code" href="namespaceirr_1_1scene.html#7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">E_SCENE_NODE_RENDER_PASS</a> renderPass)
        {
                <span class="comment">// I don't have to do anything here except remember which render pass I am in.</span>
                CurrentRenderPass = renderPass;
        }

        <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRenderPassPostRender(<a class="code" href="namespaceirr_1_1scene.html#7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">E_SCENE_NODE_RENDER_PASS</a> renderPass)
        {
                <span class="comment">// I only want solid nodes to be lit, so after the solid pass, turn all lights off.</span>
                <span class="keywordflow">if</span>(<a class="code" href="namespaceirr_1_1scene.html#7862269bd1abc123929d4dbb8200d67fd058b020ab42ad745cc03fe379148e1f" title="Solid scene nodes or special scene nodes without materials.">ESNRP_SOLID</a> == renderPass)
                {
                        <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); ++i)
                                (*SceneLightList)[i]-&gt;setVisible(<span class="keyword">false</span>);
                }
        }

        <span class="comment">// This is called before the specified scene node is rendered</span>
        <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnNodePreRender(ISceneNode* node)
        {
                CurrentSceneNode = node;

                <span class="comment">// This light manager only considers solid objects, but you are free to manipulate</span>
                <span class="comment">// lights during any phase, depending on your requirements.</span>
                <span class="keywordflow">if</span>(<a class="code" href="namespaceirr_1_1scene.html#7862269bd1abc123929d4dbb8200d67fd058b020ab42ad745cc03fe379148e1f" title="Solid scene nodes or special scene nodes without materials.">ESNRP_SOLID</a> != CurrentRenderPass)
                        <span class="keywordflow">return</span>;

                <span class="comment">// And in fact for this example, I only want to consider lighting for cube scene</span>
                <span class="comment">// nodes.  You will probably want to deal with lighting for (at least) mesh /</span>
                <span class="comment">// animated mesh scene nodes as well.</span>
                <span class="keywordflow">if</span>(node-&gt;getType() != <a class="code" href="namespaceirr_1_1scene.html#cad3d7ef92a9807d391ba29120f3b7bd44d66f5c284aed4d0698d6854b6a72e3" title="simple cube scene node">ESNT_CUBE</a>)
                        <span class="keywordflow">return</span>;

                <span class="keywordflow">if</span>(LIGHTS_NEAREST_NODE == Mode)
                {
                        <span class="comment">// This is a naive implementation that prioritises every light in the scene</span>
                        <span class="comment">// by its proximity to the node being rendered.  This produces some flickering</span>
                        <span class="comment">// when lights orbit closer to a cube than its 'zone' lights.</span>
                        <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a> nodePosition = node-&gt;getAbsolutePosition();

                        <span class="comment">// Sort the light list by prioritising them based on their distance from the node</span>
                        <span class="comment">// that's about to be rendered.</span>
                        array&lt;LightDistanceElement&gt; sortingArray;
                        sortingArray.reallocate(SceneLightList-&gt;size());

                        <a class="code" href="namespaceirr.html#0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i;
                        <span class="keywordflow">for</span>(i = 0; i &lt; SceneLightList-&gt;size(); ++i)
                        {
                                ILightSceneNode* lightNode = (*SceneLightList)[i];
                                <a class="code" href="namespaceirr.html#1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> distance = lightNode-&gt;getAbsolutePosition().getDistanceFromSQ(nodePosition);
                                sortingArray.push_back(LightDistanceElement(lightNode, distance));
                        }

                        sortingArray.sort();

                        <span class="comment">// The list is now sorted by proximity to the node.</span>
                        <span class="comment">// Turn on the three nearest lights, and turn the others off.</span>
                        <span class="keywordflow">for</span>(i = 0; i &lt; sortingArray.size(); ++i)
                                sortingArray[i].node-&gt;setVisible(i &lt; 3);

                }
                <span class="keywordflow">else</span> <span class="keywordflow">if</span>(LIGHTS_IN_ZONE == Mode)
                {
                        <span class="comment">// Empty scene nodes are used to represent 'zones'.  For each solid mesh that</span>
                        <span class="comment">// is being rendered, turn off all lights, then find its 'zone' parent, and turn</span>
                        <span class="comment">// on all lights that are found under that node in the scene graph.</span>
                        <span class="comment">// This is a general purpose algorithm that doesn't use any special</span>
                        <span class="comment">// knowledge of how this particular scene graph is organised.</span>
                        <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); ++i)
                        {
                                ILightSceneNode* lightNode = (*SceneLightList)[i];
                                SLight &amp; lightData = lightNode-&gt;getLightData();

                                <span class="keywordflow">if</span>(<a class="code" href="namespaceirr_1_1video.html#af0e02f6f83cc35cf9e764bf18400d3946a64f42740c097ee15d5c3a87961788" title="directional light, coming from a direction from an infinite distance">ELT_DIRECTIONAL</a> != lightData.Type)
                                        lightNode-&gt;setVisible(<span class="keyword">false</span>);
                        }

                        ISceneNode * parentZone = findZone(node);
                        <span class="keywordflow">if</span>(parentZone)
                                turnOnZoneLights(parentZone);
                }
        }

        <span class="comment">// Called after the specified scene node is rendered</span>
        <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnNodePostRender(ISceneNode* node)
        {
                <span class="comment">// I don't need to do any light management after individual node rendering.</span>
        }

<span class="keyword">private</span>:

        <span class="comment">// Find the empty scene node that is the parent of the specified node</span>
        ISceneNode * findZone(ISceneNode * node)
        {
                <span class="keywordflow">if</span>(!node)
                        <span class="keywordflow">return</span> 0;

                <span class="keywordflow">if</span>(node-&gt;getType() == <a class="code" href="namespaceirr_1_1scene.html#cad3d7ef92a9807d391ba29120f3b7bd977d9500eeb4d4f23e5676a312367f57" title="Empty Scene Node.">ESNT_EMPTY</a>)
                        <span class="keywordflow">return</span> node;

                <span class="keywordflow">return</span> findZone(node-&gt;getParent());
        }

        <span class="comment">// Turn on all lights that are children (directly or indirectly) of the</span>
        <span class="comment">// specified scene node.</span>
        <span class="keywordtype">void</span> turnOnZoneLights(ISceneNode * node)
        {
                core::list&lt;ISceneNode*&gt; <span class="keyword">const</span> &amp; children = node-&gt;getChildren();
                <span class="keywordflow">for</span> (core::list&lt;ISceneNode*&gt;::ConstIterator child = children.begin();
                        child != children.end();
                        ++child)
                {
                        <span class="keywordflow">if</span>((*child)-&gt;getType() == <a class="code" href="namespaceirr_1_1scene.html#cad3d7ef92a9807d391ba29120f3b7bd73c87b4a418b0b7dc9d441cdf45f51e3" title="Light Scene Node.">ESNT_LIGHT</a>)
                                static_cast&lt;ILightSceneNode*&gt;(*child)-&gt;setVisible(<span class="keyword">true</span>);
                        <span class="keywordflow">else</span> <span class="comment">// Assume that lights don't have any children that are also lights</span>
                                turnOnZoneLights(*child);
                }
        }


        <span class="comment">// A utility class to aid in sorting scene nodes into a distance order</span>
        <span class="keyword">class </span>LightDistanceElement
        {
        <span class="keyword">public</span>:
                LightDistanceElement() {};

                LightDistanceElement(ILightSceneNode* n, <a class="code" href="namespaceirr.html#1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> d)
                        : node(n), distance(d) { }

                ILightSceneNode* node;
                <a class="code" href="namespaceirr.html#1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> distance;

                <span class="comment">// Lower distance elements are sorted to the start of the array</span>
                <span class="keywordtype">bool</span> operator &lt; (<span class="keyword">const</span> LightDistanceElement&amp; other)<span class="keyword"> const</span>
<span class="keyword">                </span>{
                        <span class="keywordflow">return</span> (distance &lt; other.distance);
                }
        };
};
</pre></div><p>
<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argumentCount, <span class="keywordtype">char</span> * argumentValues[])
{
        <span class="keywordtype">char</span> driverChoice;

        <span class="keywordflow">if</span>(argumentCount &gt; 1)
                driverChoice = argumentValues[1][0];
        <span class="keywordflow">else</span>
        {
                printf(<span class="stringliteral">"Please select the driver you want for this example:\n"</span>\
                        <span class="stringliteral">" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"</span>\
                        <span class="stringliteral">" (d) Software Renderer\n (e) Burning's Software Renderer\n"</span>\
                        <span class="stringliteral">" (f) NullDevice\n (otherKey) exit\n\n"</span>);

                std::cin &gt;&gt; driverChoice;
        }

        <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType;
        <span class="keywordflow">switch</span>(driverChoice)
        {
                <span class="keywordflow">case</span> <span class="charliteral">'a'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d04691ca314f9018f508dcf2c57dcaacec" title="Direct3D 9 device, only available on Win32 platforms.">video::EDT_DIRECT3D9</a>;<span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'b'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d08cc3807f6f28404f3424ad7e31b3142f" title="Direct3D8 device, only available on Win32 platforms.">video::EDT_DIRECT3D8</a>;<span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'c'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d02715182a79f1cb8e2826fd68a8150a53" title="OpenGL device, available on most platforms.">video::EDT_OPENGL</a>;   <span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d01598cd235a1a6bd052e2011b559e8995" title="The Irrlicht Engine Software renderer.">video::EDT_SOFTWARE</a>; <span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'e'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0e85481da26159b967191ccc6de1e4a05" title="The Burning&amp;#39;s Software Renderer, an alternative software renderer.">video::EDT_BURNINGSVIDEO</a>;<span class="keywordflow">break</span>;
                <span class="keywordflow">case</span> <span class="charliteral">'f'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0cfdbd476cbfd4d05e72f9adffcc42210" title="Null driver, useful for applications to run the engine without visualisation.">video::EDT_NULL</a>;     <span class="keywordflow">break</span>;
                <span class="keywordflow">default</span>: <span class="keywordflow">return</span> 0;
        }


        IrrlichtDevice *device = <a class="code" href="namespaceirr.html#baf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the...">createDevice</a>(driverType, dimension2d&lt;u32&gt;(640, 480), 32,
                                                                                <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, 0);
        <span class="keywordflow">if</span>(!device)
                <span class="keywordflow">return</span> -1;

        <a class="code" href="namespaceirr.html#0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <span class="keyword">const</span> lightRadius = 60.f; <span class="comment">// Enough to reach the far side of each 'zone'</span>

        IVideoDriver* driver = device-&gt;getVideoDriver();
        ISceneManager* smgr = device-&gt;getSceneManager();
        IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();

        gui::IGUISkin* skin = guienv-&gt;getSkin();
        <span class="keywordflow">if</span> (skin)
        {
                skin-&gt;setColor(<a class="code" href="namespaceirr_1_1gui.html#bd15860fde29833c48daff5f95d5467a03e6e93fa9356e9d8d743e6928111185" title="Text on a button.">EGDC_BUTTON_TEXT</a>, SColor(255, 255, 255, 255));
                gui::IGUIFont* font = guienv-&gt;getFont(<span class="stringliteral">"../../media/fontlucida.png"</span>);
                <span class="keywordflow">if</span>(font)
                        skin-&gt;setFont(font);
        }

        guienv-&gt;addStaticText(L<span class="stringliteral">"1 - No light management"</span>, core::rect&lt;s32&gt;(10,10,200,30));
        guienv-&gt;addStaticText(L<span class="stringliteral">"2 - Closest 3 lights"</span>, core::rect&lt;s32&gt;(10,30,200,50));
        guienv-&gt;addStaticText(L<span class="stringliteral">"3 - Lights in zone"</span>, core::rect&lt;s32&gt;(10,50,200,70));
</pre></div><p>
Add several "zones". You could use this technique to light individual rooms, for example. <div class="fragment"><pre class="fragment">        <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> zoneX = -100.f; zoneX &lt;= 100.f; zoneX += 50.f)
                <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> zoneY = -60.f; zoneY &lt;= 60.f; zoneY += 60.f)
                {
                        <span class="comment">// Start with an empty scene node, which we will use to represent a zone.</span>
                        ISceneNode * zoneRoot = smgr-&gt;addEmptySceneNode();
                        zoneRoot-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(zoneX, zoneY, 0));

                        <span class="comment">// Each zone contains a rotating cube</span>
                        IMeshSceneNode * node = smgr-&gt;addCubeSceneNode(15, zoneRoot);
                        ISceneNodeAnimator * rotation = smgr-&gt;createRotationAnimator(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0.25f, 0.5f, 0.75f));
                        node-&gt;addAnimator(rotation);
                        rotation-&gt;drop();

                        <span class="comment">// And each cube has three lights attached to it.  The lights are attached to billboards so</span>
                        <span class="comment">// that we can see where they are.  The billboards are attached to the cube, so that the</span>
                        <span class="comment">// lights are indirect descendents of the same empty scene node as the cube.</span>
                        IBillboardSceneNode * billboard = smgr-&gt;addBillboardSceneNode(node);
                        billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, -14, 30));
                        billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f11b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
                        billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">"../../media/particle.bmp"</span>));
                        billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
                        ILightSceneNode * light = smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), SColorf(1, 0, 0), lightRadius);

                        billboard = smgr-&gt;addBillboardSceneNode(node);
                        billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(-21, -14, -21));
                        billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f11b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
                        billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">"../../media/particle.bmp"</span>));
                        billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
                        light = smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), SColorf(0, 1, 0), lightRadius);

                        billboard = smgr-&gt;addBillboardSceneNode(node);
                        billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(21, -14, -21));
                        billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f11b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
                        billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">"../../media/particle.bmp"</span>));
                        billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
                        light = smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), SColorf(0, 0, 1), lightRadius);

                        <span class="comment">// Each cube also has a smaller cube rotating around it, to show that the cubes are being</span>
                        <span class="comment">// lit by the lights in their 'zone', not just lights that are their direct children.</span>
                        node = smgr-&gt;addCubeSceneNode(5, node);
                        node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 21, 0));
                }

        smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,-130), <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,0));

        CMyLightManager * myLightManager = <span class="keyword">new</span> CMyLightManager(smgr);
        smgr-&gt;setLightManager(0); <span class="comment">// This is the default: we won't do light management until told to do it.</span>
        device-&gt;setEventReceiver(myLightManager);

        <span class="keywordtype">int</span> lastFps = -1;

        <span class="keywordflow">while</span>(device-&gt;run())
        {
                driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, SColor(255,100,101,140));
                smgr-&gt;drawAll();
                guienv-&gt;drawAll();
                driver-&gt;endScene();

                <span class="keywordtype">int</span> fps = driver-&gt;getFPS();
                <span class="keywordflow">if</span>(fps != lastFps)
                {
                        lastFps = fps;
                        <a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">"Managed Lights ["</span>;
                        str += driver-&gt;getName();
                        str += <span class="stringliteral">"] FPS:"</span>;
                        str += fps;
                        device-&gt;setWindowCaption(str.c_str());
                }
        }

        myLightManager-&gt;drop(); <span class="comment">// Drop my implicit reference</span>
        device-&gt;drop();
        <span class="keywordflow">return</span> 0;
}
</pre></div> </div>
<hr size="1">
<address style="align: right;">
<small> </small>
</address>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr> 
    <td width="0"> <div align="left"><small><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="irrlicht.png" alt="The Irrlicht Engine" align="middle" border=0 width=88 height=31></a></small></div></td>
    <td> <div align="left"><small><em><font size="2">The <a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
        Engine</a> Documentation &copy; 2003-2009 by Nikolaus Gebhardt. Generated 
        on Sun Jan 10 09:24:07 2010 by <a href="http://www.doxygen.org" target="_blank">Doxygen</a> 
        (1.5.6)</font></em></small></div></td>
  </tr>
</table>
<address style="align: right;">
</address>
</body>
</html>