aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8.1/doc/html/example020.html
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-01-13 19:47:58 +1000
committerDavid Walter Seikel2014-01-13 19:47:58 +1000
commitf9158592e1478b2013afc7041d9ed041cf2d2f4a (patch)
treeb16e389d7988700e21b4c9741044cefa536dcbae /libraries/irrlicht-1.8.1/doc/html/example020.html
parentLibraries readme updated with change markers and more of the Irrlicht changes. (diff)
downloadSledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.zip
SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.gz
SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.bz2
SledjHamr-f9158592e1478b2013afc7041d9ed041cf2d2f4a.tar.xz
Update Irrlicht to 1.8.1. Include actual change markers this time. lol
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8.1/doc/html/example020.html464
1 files changed, 464 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/doc/html/example020.html b/libraries/irrlicht-1.8.1/doc/html/example020.html
new file mode 100644
index 0000000..0431cbb
--- /dev/null
+++ b/libraries/irrlicht-1.8.1/doc/html/example020.html
@@ -0,0 +1,464 @@
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<title>Irrlicht 3D Engine: Tutorial 20: Managed Lights</title>
6
7<link href="tabs.css" rel="stylesheet" type="text/css"/>
8<link href="doxygen.css" rel="stylesheet" type="text/css" />
9<link href="navtree.css" rel="stylesheet" type="text/css"/>
10<script type="text/javascript" src="jquery.js"></script>
11<script type="text/javascript" src="resize.js"></script>
12<script type="text/javascript" src="navtree.js"></script>
13<script type="text/javascript">
14 $(document).ready(initResizable);
15</script>
16<link href="search/search.css" rel="stylesheet" type="text/css"/>
17<script type="text/javascript" src="search/search.js"></script>
18<script type="text/javascript">
19 $(document).ready(function() { searchBox.OnSelectItem(0); });
20</script>
21
22</head>
23<body>
24<div id="top"><!-- do not remove this div! -->
25
26
27<div id="titlearea">
28<table cellspacing="0" cellpadding="0">
29 <tbody>
30 <tr style="height: 56px;">
31
32 <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
33
34
35 <td style="padding-left: 0.5em;">
36 <div id="projectname">Irrlicht 3D Engine
37
38 </div>
39
40 </td>
41
42
43
44
45 <td> <div id="MSearchBox" class="MSearchBoxInactive">
46 <span class="left">
47 <img id="MSearchSelect" src="search/mag_sel.png"
48 onmouseover="return searchBox.OnSearchSelectShow()"
49 onmouseout="return searchBox.OnSearchSelectHide()"
50 alt=""/>
51 <input type="text" id="MSearchField" value="Search" accesskey="S"
52 onfocus="searchBox.OnSearchFieldFocus(true)"
53 onblur="searchBox.OnSearchFieldFocus(false)"
54 onkeyup="searchBox.OnSearchFieldChange(event)"/>
55 </span><span class="right">
56 <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
57 </span>
58 </div>
59</td>
60
61
62 </tr>
63 </tbody>
64</table>
65</div>
66
67<!-- Generated by Doxygen 1.7.5.1 -->
68<script type="text/javascript">
69var searchBox = new SearchBox("searchBox", "search",false,'Search');
70</script>
71<script type="text/javascript" src="dynsections.js"></script>
72</div>
73<div id="side-nav" class="ui-resizable side-nav-resizable">
74 <div id="nav-tree">
75 <div id="nav-tree-contents">
76 </div>
77 </div>
78 <div id="splitbar" style="-moz-user-select:none;"
79 class="ui-resizable-handle">
80 </div>
81</div>
82<script type="text/javascript">
83 initNavTree('example020.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 20: Managed Lights </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="020shot.jpg" alt="020shot.jpg"/>
93</div>
94 <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. </p>
95<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>
96<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>
97
98<span class="keyword">using namespace </span>irr;
99<span class="keyword">using namespace </span>core;
100
101<span class="preprocessor">#if defined(_MSC_VER)</span>
102<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
103<span class="preprocessor">#endif // MSC_VER</span>
104</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>
105<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>
106<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>
107<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>
108<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>
109<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. </p>
110<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CMyLightManager : <span class="keyword">public</span> scene::ILightManager, <span class="keyword">public</span> IEventReceiver
111{
112 <span class="keyword">typedef</span> <span class="keyword">enum</span>
113 {
114 NO_MANAGEMENT,
115 LIGHTS_NEAREST_NODE,
116 LIGHTS_IN_ZONE
117 }
118 LightManagementMode;
119
120 LightManagementMode Mode;
121 LightManagementMode RequestedMode;
122
123 <span class="comment">// These data represent the state information that this light manager</span>
124 <span class="comment">// is interested in.</span>
125 scene::ISceneManager * SceneManager;
126 core::array&lt;scene::ISceneNode*&gt; * SceneLightList;
127 <a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">scene::E_SCENE_NODE_RENDER_PASS</a> CurrentRenderPass;
128 scene::ISceneNode * CurrentSceneNode;
129
130<span class="keyword">public</span>:
131 CMyLightManager(scene::ISceneManager* sceneManager)
132 : Mode(NO_MANAGEMENT), RequestedMode(NO_MANAGEMENT),
133 SceneManager(sceneManager), SceneLightList(0),
134 CurrentRenderPass(scene::<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67fa1f79a46e7a41716dcae5c8dfe8d310bb" title="No pass currently active.">ESNRP_NONE</a>), CurrentSceneNode(0)
135 { }
136
137 <span class="comment">// The input receiver interface, which just switches light management strategy</span>
138 <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent &amp; event)
139 {
140 <span class="keywordtype">bool</span> handled = <span class="keyword">false</span>;
141
142 <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> &amp;&amp; event.KeyInput.PressedDown)
143 {
144 handled = <span class="keyword">true</span>;
145 <span class="keywordflow">switch</span>(event.KeyInput.Key)
146 {
147 <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a61ec605d669b598d2e7106981a326fde">irr::KEY_KEY_1</a>:
148 RequestedMode = NO_MANAGEMENT;
149 <span class="keywordflow">break</span>;
150 <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3aa7574bf313b5c29547f01c36f0a4a4f8">irr::KEY_KEY_2</a>:
151 RequestedMode = LIGHTS_NEAREST_NODE;
152 <span class="keywordflow">break</span>;
153 <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a577dcff3b86e6dd45f70d8c691dd3c91">irr::KEY_KEY_3</a>:
154 RequestedMode = LIGHTS_IN_ZONE;
155 <span class="keywordflow">break</span>;
156 <span class="keywordflow">default</span>:
157 handled = <span class="keyword">false</span>;
158 <span class="keywordflow">break</span>;
159 }
160
161 <span class="keywordflow">if</span>(NO_MANAGEMENT == RequestedMode)
162 SceneManager-&gt;setLightManager(0); <span class="comment">// Show that it&#39;s safe to register the light manager</span>
163 <span class="keywordflow">else</span>
164 SceneManager-&gt;setLightManager(<span class="keyword">this</span>);
165 }
166
167 <span class="keywordflow">return</span> handled;
168 }
169
170
171 <span class="comment">// This is called before the first scene node is rendered.</span>
172 <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnPreRender(core::array&lt;scene::ISceneNode*&gt; &amp; lightList)
173 {
174 <span class="comment">// Update the mode; changing it here ensures that it&#39;s consistent throughout a render</span>
175 Mode = RequestedMode;
176
177 <span class="comment">// Store the light list. I am free to alter this list until the end of OnPostRender().</span>
178 SceneLightList = &amp;lightList;
179 }
180
181 <span class="comment">// Called after the last scene node is rendered.</span>
182 <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnPostRender()
183 {
184 <span class="comment">// Since light management might be switched off in the event handler, we&#39;ll turn all</span>
185 <span class="comment">// lights on to ensure that they are in a consistent state. You wouldn&#39;t normally have</span>
186 <span class="comment">// to do this when using a light manager, since you&#39;d continue to do light management</span>
187 <span class="comment">// yourself.</span>
188 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); i++)
189 (*SceneLightList)[i]-&gt;setVisible(<span class="keyword">true</span>);
190 }
191
192 <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRenderPassPreRender(<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">scene::E_SCENE_NODE_RENDER_PASS</a> renderPass)
193 {
194 <span class="comment">// I don&#39;t have to do anything here except remember which render pass I am in.</span>
195 CurrentRenderPass = renderPass;
196 }
197
198 <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRenderPassPostRender(<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67f" title="Enumeration for render passes.">scene::E_SCENE_NODE_RENDER_PASS</a> renderPass)
199 {
200 <span class="comment">// I only want solid nodes to be lit, so after the solid pass, turn all lights off.</span>
201 <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67fad058b020ab42ad745cc03fe379148e1f" title="Solid scene nodes or special scene nodes without materials.">scene::ESNRP_SOLID</a> == renderPass)
202 {
203 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); ++i)
204 (*SceneLightList)[i]-&gt;setVisible(<span class="keyword">false</span>);
205 }
206 }
207
208 <span class="comment">// This is called before the specified scene node is rendered</span>
209 <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnNodePreRender(scene::ISceneNode* node)
210 {
211 CurrentSceneNode = node;
212
213 <span class="comment">// This light manager only considers solid objects, but you are free to manipulate</span>
214 <span class="comment">// lights during any phase, depending on your requirements.</span>
215 <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1scene.html#a7862269bd1abc123929d4dbb8200d67fad058b020ab42ad745cc03fe379148e1f" title="Solid scene nodes or special scene nodes without materials.">scene::ESNRP_SOLID</a> != CurrentRenderPass)
216 <span class="keywordflow">return</span>;
217
218 <span class="comment">// And in fact for this example, I only want to consider lighting for cube scene</span>
219 <span class="comment">// nodes. You will probably want to deal with lighting for (at least) mesh /</span>
220 <span class="comment">// animated mesh scene nodes as well.</span>
221 <span class="keywordflow">if</span> (node-&gt;getType() != <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda44d66f5c284aed4d0698d6854b6a72e3" title="simple cube scene node">scene::ESNT_CUBE</a>)
222 <span class="keywordflow">return</span>;
223
224 <span class="keywordflow">if</span> (LIGHTS_NEAREST_NODE == Mode)
225 {
226 <span class="comment">// This is a naive implementation that prioritises every light in the scene</span>
227 <span class="comment">// by its proximity to the node being rendered. This produces some flickering</span>
228 <span class="comment">// when lights orbit closer to a cube than its &#39;zone&#39; lights.</span>
229 <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a> nodePosition = node-&gt;getAbsolutePosition();
230
231 <span class="comment">// Sort the light list by prioritising them based on their distance from the node</span>
232 <span class="comment">// that&#39;s about to be rendered.</span>
233 array&lt;LightDistanceElement&gt; sortingArray;
234 sortingArray.reallocate(SceneLightList-&gt;size());
235
236 <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i;
237 <span class="keywordflow">for</span>(i = 0; i &lt; SceneLightList-&gt;size(); ++i)
238 {
239 scene::ISceneNode* lightNode = (*SceneLightList)[i];
240 <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> distance = lightNode-&gt;getAbsolutePosition().getDistanceFromSQ(nodePosition);
241 sortingArray.push_back(LightDistanceElement(lightNode, distance));
242 }
243
244 sortingArray.sort();
245
246 <span class="comment">// The list is now sorted by proximity to the node.</span>
247 <span class="comment">// Turn on the three nearest lights, and turn the others off.</span>
248 <span class="keywordflow">for</span>(i = 0; i &lt; sortingArray.size(); ++i)
249 sortingArray[i].node-&gt;setVisible(i &lt; 3);
250 }
251 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(LIGHTS_IN_ZONE == Mode)
252 {
253 <span class="comment">// Empty scene nodes are used to represent &#39;zones&#39;. For each solid mesh that</span>
254 <span class="comment">// is being rendered, turn off all lights, then find its &#39;zone&#39; parent, and turn</span>
255 <span class="comment">// on all lights that are found under that node in the scene graph.</span>
256 <span class="comment">// This is a general purpose algorithm that doesn&#39;t use any special</span>
257 <span class="comment">// knowledge of how this particular scene graph is organised.</span>
258 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i = 0; i &lt; SceneLightList-&gt;size(); ++i)
259 {
260 <span class="keywordflow">if</span> ((*SceneLightList)[i]-&gt;getType() != <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda73c87b4a418b0b7dc9d441cdf45f51e3" title="Light Scene Node.">scene::ESNT_LIGHT</a>)
261 <span class="keywordflow">continue</span>;
262 scene::ILightSceneNode* lightNode = <span class="keyword">static_cast&lt;</span>scene::ILightSceneNode*<span class="keyword">&gt;</span>((*SceneLightList)[i]);
263 video::SLight &amp; lightData = lightNode-&gt;getLightData();
264
265 <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1video.html#aaf0e02f6f83cc35cf9e764bf18400d39a46a64f42740c097ee15d5c3a87961788" title="directional light, coming from a direction from an infinite distance">video::ELT_DIRECTIONAL</a> != lightData.Type)
266 lightNode-&gt;setVisible(<span class="keyword">false</span>);
267 }
268
269 scene::ISceneNode * parentZone = findZone(node);
270 <span class="keywordflow">if</span> (parentZone)
271 turnOnZoneLights(parentZone);
272 }
273 }
274
275 <span class="comment">// Called after the specified scene node is rendered</span>
276 <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnNodePostRender(scene::ISceneNode* node)
277 {
278 <span class="comment">// I don&#39;t need to do any light management after individual node rendering.</span>
279 }
280
281<span class="keyword">private</span>:
282
283 <span class="comment">// Find the empty scene node that is the parent of the specified node</span>
284 scene::ISceneNode * findZone(scene::ISceneNode * node)
285 {
286 <span class="keywordflow">if</span> (!node)
287 <span class="keywordflow">return</span> 0;
288
289 <span class="keywordflow">if</span> (node-&gt;getType() == <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda977d9500eeb4d4f23e5676a312367f57" title="Empty Scene Node.">scene::ESNT_EMPTY</a>)
290 <span class="keywordflow">return</span> node;
291
292 <span class="keywordflow">return</span> findZone(node-&gt;getParent());
293 }
294
295 <span class="comment">// Turn on all lights that are children (directly or indirectly) of the</span>
296 <span class="comment">// specified scene node.</span>
297 <span class="keywordtype">void</span> turnOnZoneLights(scene::ISceneNode * node)
298 {
299 core::list&lt;scene::ISceneNode*&gt; <span class="keyword">const</span> &amp; children = node-&gt;getChildren();
300 <span class="keywordflow">for</span> (core::list&lt;scene::ISceneNode*&gt;::ConstIterator child = children.begin();
301 child != children.end(); ++child)
302 {
303 <span class="keywordflow">if</span> ((*child)-&gt;getType() == <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda73c87b4a418b0b7dc9d441cdf45f51e3" title="Light Scene Node.">scene::ESNT_LIGHT</a>)
304 (*child)-&gt;setVisible(<span class="keyword">true</span>);
305 <span class="keywordflow">else</span> <span class="comment">// Assume that lights don&#39;t have any children that are also lights</span>
306 turnOnZoneLights(*child);
307 }
308 }
309
310
311 <span class="comment">// A utility class to aid in sorting scene nodes into a distance order</span>
312 <span class="keyword">class </span>LightDistanceElement
313 {
314 <span class="keyword">public</span>:
315 LightDistanceElement() {};
316
317 LightDistanceElement(scene::ISceneNode* n, <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> d)
318 : node(n), distance(d) { }
319
320 scene::ISceneNode* node;
321 <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> distance;
322
323 <span class="comment">// Lower distance elements are sorted to the start of the array</span>
324 <span class="keywordtype">bool</span> operator &lt; (<span class="keyword">const</span> LightDistanceElement&amp; other)<span class="keyword"> const</span>
325<span class="keyword"> </span>{
326 <span class="keywordflow">return</span> (distance &lt; other.distance);
327 }
328 };
329};
330</pre></div><div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argumentCount, <span class="keywordtype">char</span> * argumentValues[])
331{
332 <span class="comment">// ask user for driver</span>
333 <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType=driverChoiceConsole();
334 <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>)
335 <span class="keywordflow">return</span> 1;
336
337 IrrlichtDevice *device = <a class="code" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice</a>(driverType,
338 dimension2d&lt;u32&gt;(640, 480), 32);
339
340 <span class="keywordflow">if</span>(!device)
341 <span class="keywordflow">return</span> -1;
342
343 <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" 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 &#39;zone&#39;</span>
344
345 video::IVideoDriver* driver = device-&gt;getVideoDriver();
346 scene::ISceneManager* smgr = device-&gt;getSceneManager();
347 gui::IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();
348
349 gui::IGUISkin* skin = guienv-&gt;getSkin();
350 <span class="keywordflow">if</span> (skin)
351 {
352 skin-&gt;setColor(<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aa03e6e93fa9356e9d8d743e6928111185" title="Text on a button.">gui::EGDC_BUTTON_TEXT</a>, video::SColor(255, 255, 255, 255));
353 gui::IGUIFont* font = guienv-&gt;getFont(<span class="stringliteral">&quot;../../media/fontlucida.png&quot;</span>);
354 <span class="keywordflow">if</span>(font)
355 skin-&gt;setFont(font);
356 }
357
358 guienv-&gt;addStaticText(L<span class="stringliteral">&quot;1 - No light management&quot;</span>, core::rect&lt;s32&gt;(10,10,200,30));
359 guienv-&gt;addStaticText(L<span class="stringliteral">&quot;2 - Closest 3 lights&quot;</span>, core::rect&lt;s32&gt;(10,30,200,50));
360 guienv-&gt;addStaticText(L<span class="stringliteral">&quot;3 - Lights in zone&quot;</span>, core::rect&lt;s32&gt;(10,50,200,70));
361</pre></div><p>Add several "zones". You could use this technique to light individual rooms, for example. </p>
362<div class="fragment"><pre class="fragment"> <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> zoneX = -100.f; zoneX &lt;= 100.f; zoneX += 50.f)
363 <span class="keywordflow">for</span>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> zoneY = -60.f; zoneY &lt;= 60.f; zoneY += 60.f)
364 {
365 <span class="comment">// Start with an empty scene node, which we will use to represent a zone.</span>
366 scene::ISceneNode * zoneRoot = smgr-&gt;addEmptySceneNode();
367 zoneRoot-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(zoneX, zoneY, 0));
368
369 <span class="comment">// Each zone contains a rotating cube</span>
370 scene::IMeshSceneNode * node = smgr-&gt;addCubeSceneNode(15, zoneRoot);
371 scene::ISceneNodeAnimator * rotation = smgr-&gt;createRotationAnimator(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0.25f, 0.5f, 0.75f));
372 node-&gt;addAnimator(rotation);
373 rotation-&gt;drop();
374
375 <span class="comment">// And each cube has three lights attached to it. The lights are attached to billboards so</span>
376 <span class="comment">// that we can see where they are. The billboards are attached to the cube, so that the</span>
377 <span class="comment">// lights are indirect descendents of the same empty scene node as the cube.</span>
378 scene::IBillboardSceneNode * billboard = smgr-&gt;addBillboardSceneNode(node);
379 billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, -14, 30));
380 billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
381 billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
382 billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
383 smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), video::SColorf(1, 0, 0), lightRadius);
384
385 billboard = smgr-&gt;addBillboardSceneNode(node);
386 billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(-21, -14, -21));
387 billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
388 billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
389 billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
390 smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), video::SColorf(0, 1, 0), lightRadius);
391
392 billboard = smgr-&gt;addBillboardSceneNode(node);
393 billboard-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(21, -14, -21));
394 billboard-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
395 billboard-&gt;setMaterialTexture(0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
396 billboard-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);
397 smgr-&gt;addLightSceneNode(billboard, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 0, 0), video::SColorf(0, 0, 1), lightRadius);
398
399 <span class="comment">// Each cube also has a smaller cube rotating around it, to show that the cubes are being</span>
400 <span class="comment">// lit by the lights in their &#39;zone&#39;, not just lights that are their direct children.</span>
401 node = smgr-&gt;addCubeSceneNode(5, node);
402 node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0, 21, 0));
403 }
404
405 smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,-130), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,0));
406
407 CMyLightManager * myLightManager = <span class="keyword">new</span> CMyLightManager(smgr);
408 smgr-&gt;setLightManager(0); <span class="comment">// This is the default: we won&#39;t do light management until told to do it.</span>
409 device-&gt;setEventReceiver(myLightManager);
410
411 <span class="keywordtype">int</span> lastFps = -1;
412
413 <span class="keywordflow">while</span>(device-&gt;run())
414 {
415 driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, video::SColor(255,100,101,140));
416 smgr-&gt;drawAll();
417 guienv-&gt;drawAll();
418 driver-&gt;endScene();
419
420 <span class="keywordtype">int</span> fps = driver-&gt;getFPS();
421 <span class="keywordflow">if</span>(fps != lastFps)
422 {
423 lastFps = fps;
424 <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">&quot;Managed Lights [&quot;</span>;
425 str += driver-&gt;getName();
426 str += <span class="stringliteral">&quot;] FPS:&quot;</span>;
427 str += fps;
428 device-&gt;setWindowCaption(str.c_str());
429 }
430 }
431
432 myLightManager-&gt;drop(); <span class="comment">// Drop my implicit reference</span>
433 device-&gt;drop();
434 <span class="keywordflow">return</span> 0;
435}
436</pre></div> </div></div>
437</div>
438 <div id="nav-path" class="navpath">
439 <ul>
440<!-- window showing the filter options -->
441<div id="MSearchSelectWindow"
442 onmouseover="return searchBox.OnSearchSelectShow()"
443 onmouseout="return searchBox.OnSearchSelectHide()"
444 onkeydown="return searchBox.OnSearchSelectKey(event)">
445<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>
446
447<!-- iframe showing the search results (closed by default) -->
448<div id="MSearchResultsWindow">
449<iframe src="javascript:void(0)" frameborder="0"
450 name="MSearchResults" id="MSearchResults">
451</iframe>
452</div>
453
454
455 <li class="footer">
456<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
457Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:41 for Irrlicht 3D Engine by
458<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
459 </ul>
460 </div>
461
462
463</body>
464</html>