diff options
Diffstat (limited to 'src/others/irrlicht-1.8.1/examples/08.SpecialFX/tutorial.html')
-rw-r--r-- | src/others/irrlicht-1.8.1/examples/08.SpecialFX/tutorial.html | 278 |
1 files changed, 278 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/examples/08.SpecialFX/tutorial.html b/src/others/irrlicht-1.8.1/examples/08.SpecialFX/tutorial.html new file mode 100644 index 0000000..8c1fc51 --- /dev/null +++ b/src/others/irrlicht-1.8.1/examples/08.SpecialFX/tutorial.html | |||
@@ -0,0 +1,278 @@ | |||
1 | <html> | ||
2 | <head> | ||
3 | <title>Irrlicht Engine Tutorial</title> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | ||
5 | </head> | ||
6 | |||
7 | <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> | ||
8 | <br> | ||
9 | <table width="95%" border="0" cellspacing="0" cellpadding="2" align="center"> | ||
10 | <tr> | ||
11 | <td bgcolor="#666699" width="10"><b><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="../../media/irrlichtlogo.jpg" width="88" height="31" border="0"></a></b></td> | ||
12 | <td bgcolor="#666699" width="100%"> | ||
13 | <div align="center"> | ||
14 | <div align="left"><b><font color="#FFFFFF">Tutorial 8. Special Effects</font></b></div> | ||
15 | </div> | ||
16 | </td> | ||
17 | </tr> | ||
18 | <tr bgcolor="#eeeeff"> | ||
19 | <td height="90" colspan="2"> | ||
20 | <div align="left"> | ||
21 | <p>This tutorials describes how to do special effects. It shows how to | ||
22 | use stencil buffer shadows, the particle system, billboards, dynamic | ||
23 | light and the water surface scene node. </p> | ||
24 | <p>The program which is described here will look like this:</p> | ||
25 | <p align="center"><img src="../../media/008shot.jpg" width="259" height="204"><br> | ||
26 | </p> | ||
27 | </div> | ||
28 | </td> | ||
29 | </tr> | ||
30 | </table> | ||
31 | <br> | ||
32 | <table width="95%" border="0" cellspacing="0" cellpadding="2" align="center"> | ||
33 | <tr> | ||
34 | <td bgcolor="#666699"> <b><font color="#FFFFFF">Lets start!</font></b></td> | ||
35 | </tr> | ||
36 | <tr> | ||
37 | <td height="90" bgcolor="#eeeeff" valign="top"> <div align="left"> | ||
38 | <div align="left"> | ||
39 | <p>We start like in some tutorials before. Please note that this time, | ||
40 | the 'shadows' flag in createDevice() is set to true, for we want to | ||
41 | have a dynamic shadow casted from an animated character. If your this | ||
42 | example runs to slow, set it to false. The Irrlicht Engine checks | ||
43 | if your hardware doesn't support the stencil buffer, and disables | ||
44 | shadows by itself, but just in case the demo runs slow on your hardware.</p> | ||
45 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
46 | <tr> | ||
47 | <td> <pre><font color="#008000" size="2">#include <irrlicht.h> | ||
48 | #include <iostream><br> | ||
49 | </font><font size="2"><b>using namespace </b>irr; | ||
50 | |||
51 | <font color="#008000">#pragma comment(lib, "Irrlicht.lib") | ||
52 | |||
53 | </font><b>int </b>main() | ||
54 | { | ||
55 | // ask user for driver<br> video::E_DRIVER_TYPE driverType;<br> | ||
56 | printf("Please select the driver you want for this example:\n"\<br> " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\<br> " (d) Software Renderer\n (e) Apfelbaum Software Renderer\n"\<br> " (f) NullDevice\n (otherKey) exit\n\n");<br><br> char i;<br> std::cin >> i;<br><br> switch(i)<br> {<br> case 'a': driverType = video::EDT_DIRECT3D9;break;<br> case 'b': driverType = video::EDT_DIRECT3D8;break;<br> case 'c': driverType = video::EDT_OPENGL; break;<br> case 'd': driverType = video::EDT_SOFTWARE; break;<br> case 'e': driverType = video::EDT_BURNINGSVIDEO;break;<br> case 'f': driverType = video::EDT_NULL; break;<br> default: return 1;<br> } | ||
57 | |||
58 | // create device and exit if creation failed<br> IrrlichtDevice *device = createDevice(driverType, | ||
59 | core::dimension2d<s32>(640, 480), 16, false, true); | ||
60 | |||
61 | if (device == 0) | ||
62 | return 1; | ||
63 | |||
64 | video::IVideoDriver* driver = device->getVideoDriver(); | ||
65 | scene::ISceneManager* smgr = device->getSceneManager();<font face="Courier New"> | ||
66 | </font></font></pre> | ||
67 | </td> | ||
68 | </tr> | ||
69 | </table> | ||
70 | <p> For our environment, we load a .3ds file. It is a small room I modelled | ||
71 | with Anim8or and exported it into the 3ds format because the Irrlicht | ||
72 | Engine did not support the .an8 format when I wrote this tutorial. | ||
73 | I am a very bad 3d graphic artist, and so the texture mapping is not | ||
74 | very nice in this model. Luckily I am a better programmer than artist, | ||
75 | and so the Irrlicht Engine is able to create a cool texture mapping | ||
76 | for me: Just use the mesh manipulator and create a planar texture | ||
77 | mapping for the mesh. If you want to see the mapping I made with Anim8or, | ||
78 | uncomment this line. I also did not figure out how to<br> | ||
79 | set the material right in Anim8or, it has a specular light color | ||
80 | which I don't really<br> | ||
81 | like. I'll switch it off too with this code.</p> | ||
82 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
83 | <tr> | ||
84 | <td> <pre><font size=2> scene::IAnimatedMesh* mesh = smgr->getMesh( | ||
85 | <font color="#FF0000">"../../media/room.3ds"</font>); | ||
86 | |||
87 | smgr->getMeshManipulator()->makePlanarTextureMapping( | ||
88 | mesh->getMesh(<font color="#800080">0</font>), <font color="#800080">0.008f</font>); | ||
89 | |||
90 | scene::ISceneNode* node = <font color="#800080">0</font>; | ||
91 | |||
92 | node = smgr->addAnimatedMeshSceneNode(mesh); | ||
93 | node->setMaterialTexture(<font color="#800080">0</font>, driver->getTexture(<font color="#FF0000">"../../media/wall.jpg"</font>)); | ||
94 | node->getMaterial(0).SpecularColor.set(0,0,0,0);</font></pre></td> | ||
95 | </tr> | ||
96 | </table> | ||
97 | <p> Now, for the first special effect: Animated water. It works like | ||
98 | this: The WaterSurfaceSceneNode takes a mesh as input and makes it | ||
99 | wave like a water surface. And if we let this scene node use a nice | ||
100 | material like the MT_REFLECTION_2_LAYER, it looks really cool. We | ||
101 | are doing this with the next few lines of code. As input mesh, we | ||
102 | create a hill plane mesh, without hills. But any other mesh could | ||
103 | be used for this, you could even use the room.3ds (which would look | ||
104 | really strange) if you wanted to. </p> | ||
105 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
106 | <tr> | ||
107 | <td> <pre> mesh = smgr->addHillPlaneMesh(<font color="#FF0000">"myHill"</font>, | ||
108 | core::dimension2d<f32>(<font color="#800080">20</font>,<font color="#800080">20</font>), | ||
109 | core::dimension2d<s32>(<font color="#800080">40</font>,<font color="#800080">40</font>), <font color="#800080">0</font>, <font color="#800080">0</font>, | ||
110 | core::dimension2d<f32>(<font color="#800080">0</font>,<font color="#800080">0</font>), | ||
111 | core::dimension2d<f32>(<font color="#800080">10</font>,<font color="#800080">10</font>)); | ||
112 | |||
113 | node = smgr->addWaterSurfaceSceneNode(mesh->getMesh(<font color="#800080">0</font>), <font color="#800080">3.0f</font>, <font color="#800080">300.0f</font>, <font color="#800080">30.0f</font>); | ||
114 | node->setPosition(core::vector3df(<font color="#800080">0</font>,<font color="#800080">7</font>,<font color="#800080">0</font>)); | ||
115 | |||
116 | node->setMaterialTexture(<font color="#800080">0</font>, driver->getTexture(<font color="#FF0000">"../../media/stones.jpg"</font>)); | ||
117 | node->setMaterialTexture(<font color="#800080">1</font>, driver->getTexture(<font color="#FF0000">"../../media/water.jpg"</font>)); | ||
118 | |||
119 | node->setMaterialType(video::EMT_REFLECTION_2_LAYER<font size=3 face="Courier New">); | ||
120 | </font></pre></td> | ||
121 | </tr> | ||
122 | </table> | ||
123 | <p> The second special effect is very basic, I bet you saw it already | ||
124 | in some Irrlicht Engine demos: A transparent billboard combined with | ||
125 | a dynamic light. We simply create a light scene node, let it fly around, | ||
126 | an to make it look more cool, we attach a billboard scene node to | ||
127 | it.</p> | ||
128 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
129 | <tr> | ||
130 | <td> <pre><font size=2> <font color="#0A246A"><i>// create light | ||
131 | |||
132 | </i></font> node = smgr->addLightSceneNode(<font color="#800080">0</font>, core::vector3df(<font color="#800080">0</font>,<font color="#800080">0</font>,<font color="#800080">0</font>), | ||
133 | video::SColorf(<font color="#800080">1.0f</font>, <font color="#800080">0.6f</font>, <font color="#800080">0.7f</font>, <font color="#800080">1.0f</font>), <font color="#800080">600.0f</font>); | ||
134 | scene::ISceneNodeAnimator* anim = <font color="#800080">0</font>; | ||
135 | anim = smgr->createFlyCircleAnimator (core::vector3df(<font color="#800080">0</font>,<font color="#800080">150</font>,<font color="#800080">0</font>),<font color="#800080">250.0f</font>); | ||
136 | node->addAnimator(anim); | ||
137 | anim->drop(); | ||
138 | |||
139 | <font color="#0A246A"><i>// attach billboard to light | ||
140 | |||
141 | </i></font> node = smgr->addBillboardSceneNode(node, core::dimension2d<f32>(<font color="#800080">50</font>, <font color="#800080">50</font>)); | ||
142 | node->setMaterialFlag(video::EMF_LIGHTING, <b>false</b>); | ||
143 | node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR); | ||
144 | node->setMaterialTexture(<font color="#800080">0</font>, driver->getTexture(<font color="#FF0000">"../../media/particlewhite.bmp"</font>)); | ||
145 | |||
146 | </font></pre></td> | ||
147 | </tr> | ||
148 | </table> | ||
149 | <p> The next special effect is a lot more interesting: A particle system. | ||
150 | The particle system in the Irrlicht Engine is quit modular and extensible | ||
151 | and yet easy to use. There is a particle system scene node into which | ||
152 | you can put particle emitters, which make particles come out of nothing. | ||
153 | These emitters are quite flexible and usually have lots of parameters | ||
154 | like direction, amount and color of the particles they should create.<br> | ||
155 | There are different emitters, for example a point emitter which lets | ||
156 | particles pop out at a fixed point. If the particle emitters available | ||
157 | in the engine are not enough for you, you can easily create your own | ||
158 | ones, you'll simply have to create a class derived from the IParticleEmitter | ||
159 | interface and attach it to the particle system using setEmitter().<br> | ||
160 | In this example we create a box particle emitter, which creates particles | ||
161 | randomly inside a box. The parameters define the box, direction of | ||
162 | the particles, minimal and maximal new particles per second, color | ||
163 | and minimal and maximal livetime of the particles.</p> | ||
164 | <p> Because only with emitters particle system would be a little bit | ||
165 | boring, there are particle affectors, which modify particles during | ||
166 | they fly around. They can be added to the particle system, simulating | ||
167 | additional effects like gravity or wind. The particle affector we | ||
168 | use in this example is an affector, which modifies the color of the | ||
169 | particles: It lets them fade out. Like the particle emitters, additional | ||
170 | particle affectors can also be implemented by you, simply derive a | ||
171 | class from IParticleAffector and add it with addAffector(). After | ||
172 | we set a nice material to the particle system, we have a cool looking | ||
173 | camp fire. By adjusting material, texture, particle emitter and affector | ||
174 | parameters, it is also easily possible to create smoke, rain, explosions, | ||
175 | snow, and so on.<br> | ||
176 | </p> | ||
177 | </div> | ||
178 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
179 | <tr> | ||
180 | <td> <pre><font size="2"> scene::IParticleSystemSceneNode* ps = <font color="#800080">0</font>; | ||
181 | ps = smgr->addParticleSystemSceneNode(<b>false</b>); | ||
182 | ps->setPosition(core::vector3df(-<font color="#800080">70</font>,<font color="#800080">60</font>,<font color="#800080">40</font>)); | ||
183 | ps->setScale(core::vector3df(<font color="#800080">2</font>,<font color="#800080">2</font>,<font color="#800080">2</font>)); | ||
184 | |||
185 | ps->setParticleSize(core::dimension2d<f32>(<font color="#800080">20.0f</font>, <font color="#800080">10.0f</font>)); | ||
186 | |||
187 | scene::IParticleEmitter* em = ps->createBoxEmitter( | ||
188 | core::aabbox3d<f32>(-<font color="#800080">7</font>,<font color="#800080">0</font>,-<font color="#800080">7</font>,<font color="#800080">7</font>,<font color="#800080">1</font>,<font color="#800080">7</font>), | ||
189 | core::vector3df(<font color="#800080">0.0f</font>,<font color="#800080">0.03f</font>,<font color="#800080">0.0f</font>), | ||
190 | <font color="#800080">80</font>,<font color="#800080">100</font>, | ||
191 | video::SColor(<font color="#800080">0</font>,<font color="#800080">255</font>,<font color="#800080">255</font>,<font color="#800080">255</font>), video::SColor(<font color="#800080">0</font>,<font color="#800080">255</font>,<font color="#800080">255</font>,<font color="#800080">255</font>), | ||
192 | <font color="#800080">800</font>,<font color="#800080">2000</font>); | ||
193 | |||
194 | ps->setEmitter(em); | ||
195 | em->drop(); | ||
196 | |||
197 | scene::IParticleAffector* paf = | ||
198 | ps->createFadeOutParticleAffector(); | ||
199 | |||
200 | ps->addAffector(paf); | ||
201 | paf->drop(); | ||
202 | |||
203 | ps->setMaterialFlag(video::EMF_LIGHTING, <b>false</b>); | ||
204 | ps->setMaterialTexture(<font color="#800080">0</font>, driver->getTexture(<font color="#FF0000">"../../media/particle.bmp"</font>)); | ||
205 | ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA)<font size="2">;</font></font></pre></td> | ||
206 | </tr> | ||
207 | </table> | ||
208 | <p> As our last special effect, we want a dynamic shadow be casted from | ||
209 | an animated character. For this we load a DirectX .x model and place | ||
210 | it into our world. For creating the shadow, we simply need to call addShadowVolumeSceneNode(). | ||
211 | The color of shadows is only adjustable globally for all shadows, by | ||
212 | calling ISceneManager::setShadowColor(). Voila, here is our dynamic | ||
213 | shadow.<br> | ||
214 | Because the character is a little bit too small for this scene, we make | ||
215 | it bigger using setScale(). And because the character is lighted by | ||
216 | a dynamic light, we need to normalize the normals to make the lighting | ||
217 | on it correct. This is always necessary if the scale of a dynamic lighted | ||
218 | model is not (1,1,1). Otherwise it would get too dark or too bright | ||
219 | because the normals will be scaled too.</p> | ||
220 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
221 | <tr> | ||
222 | <td><pre><font size=2> mesh = smgr->getMesh(<font color="#FF0000">"../../media/dwarf.x"</font>); | ||
223 | scene::IAnimatedMeshSceneNode* anode = <font color="#800080">0</font>; | ||
224 | |||
225 | anode = smgr->addAnimatedMeshSceneNode(mesh); | ||
226 | anode->setPosition(core::vector3df(-<font color="#800080">50</font>,<font color="#800080">20</font>,-<font color="#800080">60</font>)); | ||
227 | anode->setAnimationSpeed(15); | ||
228 | <font color="#0A246A"> | ||
229 | // add shadow</font> | ||
230 | anode->addShadowVolumeSceneNode(); | ||
231 | smgr->setShadowColor(video::SColor(<font color="#800080">220</font>,<font color="#800080">0</font>,<font color="#800080">0</font>,<font color="#800080">0</font>)); | ||
232 | </font><font size=2><font color="#0A246A"> | ||
233 | // make the model a little bit bigger and normalize its normals <br> // because of this for correct lighting</font><br> anode->setScale(core::vector3df(2,2,2));<br> anode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);</font><font size=3 face="Courier New"><br></font></pre></td> | ||
234 | </tr> | ||
235 | </table> | ||
236 | <p> Finally we simply have to draw everything, that's all.</p> | ||
237 | <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center"> | ||
238 | <tr> | ||
239 | <td><pre><font size=2> scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(); | ||
240 | camera->setPosition(core::vector3df(-<font color="#800080">50</font>,<font color="#800080">50</font>,-<font color="#800080">150</font>)); | ||
241 | |||
242 | |||
243 | <b>int </b>lastFPS = -<font color="#800080">1</font>; | ||
244 | |||
245 | <b>while</b>(device->run()) | ||
246 | { | ||
247 | driver->beginScene(<b>true</b>, <b>true</b>, <font color="#800080">0</font>); | ||
248 | |||
249 | smgr->drawAll(); | ||
250 | |||
251 | driver->endScene(); | ||
252 | |||
253 | <b>int </b>fps = driver->getFPS(); | ||
254 | |||
255 | <b>if </b>(lastFPS != fps) | ||
256 | { | ||
257 | core::stringw str = L"Irrlicht Engine - SpecialFX example [";<br> str += driver->getName();<br> str += "] FPS:";<br> str += fps;<br><br> device->setWindowCaption(str.c_str());<br> lastFPS = fps;<br> } | ||
258 | } | ||
259 | |||
260 | device->drop(); | ||
261 | |||
262 | <b>return </b><font color="#800080">0</font>; | ||
263 | } | ||
264 | |||
265 | </font> | ||
266 | </pre></td> | ||
267 | </tr> | ||
268 | </table> | ||
269 | <p> </p> | ||
270 | <p> </p> | ||
271 | <p> </p> | ||
272 | </div> | ||
273 | </td> | ||
274 | </tr> | ||
275 | </table> | ||
276 | <p> </p> | ||
277 | </body> | ||
278 | </html> | ||