aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/doc/html/example007.html
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/doc/html/example007.html')
-rw-r--r--src/others/irrlicht-1.8.1/doc/html/example007.html384
1 files changed, 384 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/doc/html/example007.html b/src/others/irrlicht-1.8.1/doc/html/example007.html
new file mode 100644
index 0000000..e1a8577
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/doc/html/example007.html
@@ -0,0 +1,384 @@
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 7: Collision</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('example007.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 7: Collision </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="007shot.jpg" alt="007shot.jpg"/>
93</div>
94 <p>We will describe 2 methods: Automatic collision detection for moving through 3d worlds with stair climbing and sliding, and manual scene node and triangle picking using a ray. In this case, we will use a ray coming out from the camera, but you can use any ray.</p>
95<p>To start, we take the program from tutorial 2, which loads and displays a quake 3 level. We will use the level to walk in it and to pick triangles from. In addition we'll place 3 animated models into it for triangle picking. The following code starts up the engine and loads the level, as per tutorial 2. </p>
96<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>
97<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>
98
99<span class="keyword">using namespace </span>irr;
100
101<span class="preprocessor">#ifdef _MSC_VER</span>
102<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
103<span class="preprocessor"></span><span class="preprocessor">#endif</span>
104<span class="preprocessor"></span>
105<span class="keyword">enum</span>
106{
107 <span class="comment">// I use this ISceneNode ID to indicate a scene node that is</span>
108 <span class="comment">// not pickable by getSceneNodeAndCollisionPointFromRay()</span>
109 ID_IsNotPickable = 0,
110
111 <span class="comment">// I use this flag in ISceneNode IDs to indicate that the</span>
112 <span class="comment">// scene node can be picked by ray selection.</span>
113 IDFlag_IsPickable = 1 &lt;&lt; 0,
114
115 <span class="comment">// I use this flag in ISceneNode IDs to indicate that the</span>
116 <span class="comment">// scene node can be highlighted. In this example, the</span>
117 <span class="comment">// homonids can be highlighted, but the level mesh can&#39;t.</span>
118 IDFlag_IsHighlightable = 1 &lt;&lt; 1
119};
120
121<span class="keywordtype">int</span> main()
122{
123 <span class="comment">// ask user for driver</span>
124 <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();
125 <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>)
126 <span class="keywordflow">return</span> 1;
127
128 <span class="comment">// create device</span>
129
130 <a class="code" href="classirr_1_1_irrlicht_device.html" title="The Irrlicht device. You can create it with createDevice() or createDeviceEx().">IrrlichtDevice</a> *device =
131 <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, <a class="code" href="classirr_1_1core_1_1dimension2d.html">core::dimension2d&lt;u32&gt;</a>(640, 480), 16, <span class="keyword">false</span>);
132
133 <span class="keywordflow">if</span> (device == 0)
134 <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
135
136 <a class="code" href="classirr_1_1video_1_1_i_video_driver.html" title="Interface to driver which is able to perform 2d and 3d graphics functions.">video::IVideoDriver</a>* driver = device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#ada90707ba5c645d47e000e4e0f87c4c4" title="Provides access to the video driver for drawing 3d and 2d geometry.">getVideoDriver</a>();
137 <a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html" title="The Scene Manager manages scene nodes, mesh recources, cameras and all the other stuff.">scene::ISceneManager</a>* smgr = device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a891b503ff4d5041296d88f23f97d7b3d" title="Provides access to the scene manager.">getSceneManager</a>();
138
139 device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a3d8d2dee2f57aa7e6c0d14592de3e6ed" title="Provides access to the virtual file system.">getFileSystem</a>()-&gt;<a class="code" href="classirr_1_1io_1_1_i_file_system.html#afe6641c7f88a8fea0205c113b8379730" title="Adds an archive to the file system.">addFileArchive</a>(<span class="stringliteral">&quot;../../media/map-20kdm2.pk3&quot;</span>);
140
141 <a class="code" href="classirr_1_1scene_1_1_i_animated_mesh.html" title="Interface for an animated mesh.">scene::IAnimatedMesh</a>* q3levelmesh = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a63894c3f3d46cfc385116f1705935e03" title="Get pointer to an animateable mesh. Loads the file if not loaded already.">getMesh</a>(<span class="stringliteral">&quot;20kdm2.bsp&quot;</span>);
142 <a class="code" href="classirr_1_1scene_1_1_i_mesh_scene_node.html" title="A scene node displaying a static mesh.">scene::IMeshSceneNode</a>* q3node = 0;
143
144 <span class="comment">// The Quake mesh is pickable, but doesn&#39;t get highlighted.</span>
145 <span class="keywordflow">if</span> (q3levelmesh)
146 q3node = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a503339385ca2b33d7e8035a61c4eca84" title="Adds a scene node for rendering using a octree to the scene graph.">addOctreeSceneNode</a>(q3levelmesh-&gt;<a class="code" href="classirr_1_1scene_1_1_i_animated_mesh.html#adccb39fee83bed36a464cf7b96f3a0ca" title="Returns the IMesh interface for a frame.">getMesh</a>(0), 0, IDFlag_IsPickable);
147</pre></div><p>So far so good, we've loaded the quake 3 level like in tutorial 2. Now, here comes something different: We create a triangle selector. A triangle selector is a class which can fetch the triangles from scene nodes for doing different things with them, for example collision detection. There are different triangle selectors, and all can be created with the ISceneManager. In this example, we create an OctreeTriangleSelector, which optimizes the triangle output a little bit by reducing it like an octree. This is very useful for huge meshes like quake 3 levels. After we created the triangle selector, we attach it to the q3node. This is not necessary, but in this way, we do not need to care for the selector, for example dropping it after we do not need it anymore. </p>
148<div class="fragment"><pre class="fragment"> scene::ITriangleSelector* selector = 0;
149
150 <span class="keywordflow">if</span> (q3node)
151 {
152 q3node-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_node.html#a2166eb0a92cc0e46c49266f41a68ed50" title="Sets the position of the node relative to its parent.">setPosition</a>(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-1350,-130,-1400));
153
154 selector = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a4ed7d3b34f4d0c70395b6d464fe32b96" title="Creates a Triangle Selector, optimized by an octree.">createOctreeTriangleSelector</a>(
155 q3node-&gt;<a class="code" href="classirr_1_1scene_1_1_i_mesh_scene_node.html#afe540de69bc3a058919cd5ce465be634" title="Get the currently defined mesh for display.">getMesh</a>(), q3node, 128);
156 q3node-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_node.html#a87fb52ec54bf3ae117340d8defd1255f" title="Sets the triangle selector of the scene node.">setTriangleSelector</a>(selector);
157 <span class="comment">// We&#39;re not done with this selector yet, so don&#39;t drop it.</span>
158 }
159</pre></div><p>We add a first person shooter camera to the scene so that we can see and move in the quake 3 level like in tutorial 2. But this, time, we add a special animator to the camera: A Collision Response animator. This animator modifies the scene node to which it is attached to in order to prevent it moving through walls, and to add gravity to it. The only thing we have to tell the animator is how the world looks like, how big the scene node is, how much gravity to apply and so on. After the collision response animator is attached to the camera, we do not have to do anything more for collision detection, anything is done automatically. The rest of the collision detection code below is for picking. And please note another cool feature: The collision response animator can be attached also to all other scene nodes, not only to cameras. And it can be mixed with other scene node animators. In this way, collision detection and response in the Irrlicht engine is really easy.</p>
160<p>Now we'll take a closer look on the parameters of createCollisionResponseAnimator(). The first parameter is the TriangleSelector, which specifies how the world, against collision detection is done looks like. The second parameter is the scene node, which is the object, which is affected by collision detection, in our case it is the camera. The third defines how big the object is, it is the radius of an ellipsoid. Try it out and change the radius to smaller values, the camera will be able to move closer to walls after this. The next parameter is the direction and speed of gravity. We'll set it to (0, -10, 0), which approximates to realistic gravity, assuming that our units are metres. You could set it to (0,0,0) to disable gravity. And the last value is just a translation: Without this, the ellipsoid with which collision detection is done would be around the camera, and the camera would be in the middle of the ellipsoid. But as human beings, we are used to have our eyes on top of the body, with which we collide with our world, not in the middle of it. So we place the scene node 50 units over the center of the ellipsoid with this parameter. And that's it, collision detection works now. </p>
161<div class="fragment"><pre class="fragment"> <span class="comment">// Set a jump speed of 3 units per second, which gives a fairly realistic jump</span>
162 <span class="comment">// when used with the gravity of (0, -10, 0) in the collision response animator.</span>
163 scene::ICameraSceneNode* camera =
164 smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#ac312cbc85161678d00192880f2cdddbb" title="Adds a camera scene node with an animator which provides mouse and keyboard control appropriate for f...">addCameraSceneNodeFPS</a>(0, 100.0f, .3f, ID_IsNotPickable, 0, 0, <span class="keyword">true</span>, 3.f);
165 camera-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(50,50,-60));
166 camera-&gt;setTarget(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-70,30,-60));
167
168 <span class="keywordflow">if</span> (selector)
169 {
170 scene::ISceneNodeAnimator* anim = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a67b266cc40ebd66b5d21c26a78f002be" title="Creates a special scene node animator for doing automatic collision detection and response...">createCollisionResponseAnimator</a>(
171 selector, camera, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(30,50,30),
172 <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,-10,0), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,30,0));
173 selector-&gt;drop(); <span class="comment">// As soon as we&#39;re done with the selector, drop it.</span>
174 camera-&gt;addAnimator(anim);
175 anim-&gt;drop(); <span class="comment">// And likewise, drop the animator when we&#39;re done referring to it.</span>
176 }
177
178 <span class="comment">// Now I create three animated characters which we can pick, a dynamic light for</span>
179 <span class="comment">// lighting them, and a billboard for drawing where we found an intersection.</span>
180
181 <span class="comment">// First, let&#39;s get rid of the mouse cursor. We&#39;ll use a billboard to show</span>
182 <span class="comment">// what we&#39;re looking at.</span>
183 device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a500a3b7bf69487ff7e2075dd0b0db529" title="Provides access to the cursor control.">getCursorControl</a>()-&gt;setVisible(<span class="keyword">false</span>);
184
185 <span class="comment">// Add the billboard.</span>
186 scene::IBillboardSceneNode * bill = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a00266a58b97e827acd9e105806a99c3a" title="Adds a billboard scene node to the scene graph.">addBillboardSceneNode</a>();
187 bill-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a> );
188 bill-&gt;setMaterialTexture(0, driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#af4055165190e4adf221c6dc6f2434ea0" title="Get access to a named texture.">getTexture</a>(<span class="stringliteral">&quot;../../media/particle.bmp&quot;</span>));
189 bill-&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>);
190 bill-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a493bb44efafebb48adab96e31eb029e5" title="Is the ZBuffer enabled? Default: true.">video::EMF_ZBUFFER</a>, <span class="keyword">false</span>);
191 bill-&gt;setSize(core::dimension2d&lt;f32&gt;(20.0f, 20.0f));
192 bill-&gt;setID(ID_IsNotPickable); <span class="comment">// This ensures that we don&#39;t accidentally ray-pick it</span>
193</pre></div><p> Add 3 animated hominids, which we can pick using a ray-triangle intersection. They all animate quite slowly, to make it easier to see that accurate triangle selection is being performed. </p>
194<div class="fragment"><pre class="fragment"> scene::IAnimatedMeshSceneNode* node = 0;
195
196 video::SMaterial material;
197
198 <span class="comment">// Add an MD2 node, which uses vertex-based animation.</span>
199 node = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a8e2e0cd3a27e85b4116855dd2f3365b8" title="Adds a scene node for rendering an animated mesh model.">addAnimatedMeshSceneNode</a>(smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a63894c3f3d46cfc385116f1705935e03" title="Get pointer to an animateable mesh. Loads the file if not loaded already.">getMesh</a>(<span class="stringliteral">&quot;../../media/faerie.md2&quot;</span>),
200 0, IDFlag_IsPickable | IDFlag_IsHighlightable);
201 node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-90,-15,-140)); <span class="comment">// Put its feet on the floor.</span>
202 node-&gt;setScale(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(1.6f)); <span class="comment">// Make it appear realistically scaled</span>
203 node-&gt;setMD2Animation(<a class="code" href="namespaceirr_1_1scene.html#a08d4a84966e1d2886d0d57e4acbb4f19aac114a5c69f38d4f943145dd98929d95">scene::EMAT_POINT</a>);
204 node-&gt;setAnimationSpeed(20.f);
205 material.setTexture(0, driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#af4055165190e4adf221c6dc6f2434ea0" title="Get access to a named texture.">getTexture</a>(<span class="stringliteral">&quot;../../media/faerie2.bmp&quot;</span>));
206 material.Lighting = <span class="keyword">true</span>;
207 material.NormalizeNormals = <span class="keyword">true</span>;
208 node-&gt;getMaterial(0) = material;
209
210 <span class="comment">// Now create a triangle selector for it. The selector will know that it</span>
211 <span class="comment">// is associated with an animated node, and will update itself as necessary.</span>
212 selector = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a266625379b1558e9be1dc062ea4e71f7" title="Creates a simple ITriangleSelector, based on a mesh.">createTriangleSelector</a>(node);
213 node-&gt;setTriangleSelector(selector);
214 selector-&gt;drop(); <span class="comment">// We&#39;re done with this selector, so drop it now.</span>
215
216 <span class="comment">// And this B3D file uses skinned skeletal animation.</span>
217 node = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a8e2e0cd3a27e85b4116855dd2f3365b8" title="Adds a scene node for rendering an animated mesh model.">addAnimatedMeshSceneNode</a>(smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a63894c3f3d46cfc385116f1705935e03" title="Get pointer to an animateable mesh. Loads the file if not loaded already.">getMesh</a>(<span class="stringliteral">&quot;../../media/ninja.b3d&quot;</span>),
218 0, IDFlag_IsPickable | IDFlag_IsHighlightable);
219 node-&gt;setScale(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(10));
220 node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-75,-66,-80));
221 node-&gt;setRotation(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,90,0));
222 node-&gt;setAnimationSpeed(8.f);
223 node-&gt;getMaterial(0).NormalizeNormals = <span class="keyword">true</span>;
224 node-&gt;getMaterial(0).Lighting = <span class="keyword">true</span>;
225 <span class="comment">// Just do the same as we did above.</span>
226 selector = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a266625379b1558e9be1dc062ea4e71f7" title="Creates a simple ITriangleSelector, based on a mesh.">createTriangleSelector</a>(node);
227 node-&gt;setTriangleSelector(selector);
228 selector-&gt;drop();
229
230 <span class="comment">// This X files uses skeletal animation, but without skinning.</span>
231 node = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a8e2e0cd3a27e85b4116855dd2f3365b8" title="Adds a scene node for rendering an animated mesh model.">addAnimatedMeshSceneNode</a>(smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a63894c3f3d46cfc385116f1705935e03" title="Get pointer to an animateable mesh. Loads the file if not loaded already.">getMesh</a>(<span class="stringliteral">&quot;../../media/dwarf.x&quot;</span>),
232 0, IDFlag_IsPickable | IDFlag_IsHighlightable);
233 node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-70,-66,-30)); <span class="comment">// Put its feet on the floor.</span>
234 node-&gt;setRotation(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,-90,0)); <span class="comment">// And turn it towards the camera.</span>
235 node-&gt;setAnimationSpeed(20.f);
236 node-&gt;getMaterial(0).Lighting = <span class="keyword">true</span>;
237 selector = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a266625379b1558e9be1dc062ea4e71f7" title="Creates a simple ITriangleSelector, based on a mesh.">createTriangleSelector</a>(node);
238 node-&gt;setTriangleSelector(selector);
239 selector-&gt;drop();
240
241
242 <span class="comment">// And this mdl file uses skinned skeletal animation.</span>
243 node = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a8e2e0cd3a27e85b4116855dd2f3365b8" title="Adds a scene node for rendering an animated mesh model.">addAnimatedMeshSceneNode</a>(smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a63894c3f3d46cfc385116f1705935e03" title="Get pointer to an animateable mesh. Loads the file if not loaded already.">getMesh</a>(<span class="stringliteral">&quot;../../media/yodan.mdl&quot;</span>),
244 0, IDFlag_IsPickable | IDFlag_IsHighlightable);
245 node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-90,-25,20));
246 node-&gt;setScale(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.8f));
247 node-&gt;getMaterial(0).Lighting = <span class="keyword">true</span>;
248 node-&gt;setAnimationSpeed(20.f);
249
250 <span class="comment">// Just do the same as we did above.</span>
251 selector = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a266625379b1558e9be1dc062ea4e71f7" title="Creates a simple ITriangleSelector, based on a mesh.">createTriangleSelector</a>(node);
252 node-&gt;setTriangleSelector(selector);
253 selector-&gt;drop();
254
255 material.setTexture(0, 0);
256 material.Lighting = <span class="keyword">false</span>;
257
258 <span class="comment">// Add a light, so that the unselected nodes aren&#39;t completely dark.</span>
259 scene::ILightSceneNode * light = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a2e6442f8c95a544c355bd137ccdb7095" title="Adds a dynamic light scene node to the scene graph.">addLightSceneNode</a>(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-60,100,400),
260 video::SColorf(1.0f,1.0f,1.0f,1.0f), 600.0f);
261 light-&gt;setID(ID_IsNotPickable); <span class="comment">// Make it an invalid target for selection.</span>
262
263 <span class="comment">// Remember which scene node is highlighted</span>
264 scene::ISceneNode* highlightedSceneNode = 0;
265 scene::ISceneCollisionManager* collMan = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a433b65bfc974d069a1dc2fc296b23d9b" title="Get pointer to the scene collision manager.">getSceneCollisionManager</a>();
266 <span class="keywordtype">int</span> lastFPS = -1;
267
268 <span class="comment">// draw the selection triangle only as wireframe</span>
269 material.Wireframe=<span class="keyword">true</span>;
270
271 <span class="keywordflow">while</span>(device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a0489f8151dc43f6f41503ffb5a160b35" title="Runs the device.">run</a>())
272 <span class="keywordflow">if</span> (device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#abd3c88336b739da2694883d5ffd25a70" title="Returns if the window is active.">isWindowActive</a>())
273 {
274 driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a015b8f2f18c260a00a858181be1e9945" title="Applications must call this method before performing any rendering.">beginScene</a>(<span class="keyword">true</span>, <span class="keyword">true</span>, 0);
275 smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a04240262904667c821bd9de5e5fd9b02" title="Draws all the scene nodes.">drawAll</a>();
276
277 <span class="comment">// Unlight any currently highlighted scene node</span>
278 <span class="keywordflow">if</span> (highlightedSceneNode)
279 {
280 highlightedSceneNode-&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">true</span>);
281 highlightedSceneNode = 0;
282 }
283
284 <span class="comment">// All intersections in this example are done with a ray cast out from the camera to</span>
285 <span class="comment">// a distance of 1000. You can easily modify this to check (e.g.) a bullet</span>
286 <span class="comment">// trajectory or a sword&#39;s position, or create a ray from a mouse click position using</span>
287 <span class="comment">// ISceneCollisionManager::getRayFromScreenCoordinates()</span>
288 core::line3d&lt;f32&gt; ray;
289 ray.start = camera-&gt;getPosition();
290 ray.end = ray.start + (camera-&gt;getTarget() - ray.start).normalize() * 1000.0f;
291
292 <span class="comment">// Tracks the current intersection point with the level or a mesh</span>
293 <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a> intersection;
294 <span class="comment">// Used to show with triangle has been hit</span>
295 <a class="code" href="namespaceirr_1_1core.html#a1112835405bbec5dadf031dc7934e7d0" title="Typedef for a f32 3d triangle.">core::triangle3df</a> hitTriangle;
296
297 <span class="comment">// This call is all you need to perform ray/triangle collision on every scene node</span>
298 <span class="comment">// that has a triangle selector, including the Quake level mesh. It finds the nearest</span>
299 <span class="comment">// collision point/triangle, and returns the scene node containing that point.</span>
300 <span class="comment">// Irrlicht provides other types of selection, including ray/triangle selector,</span>
301 <span class="comment">// ray/box and ellipse/triangle selector, plus associated helpers.</span>
302 <span class="comment">// See the methods of ISceneCollisionManager</span>
303 scene::ISceneNode * selectedSceneNode =
304 collMan-&gt;getSceneNodeAndCollisionPointFromRay(
305 ray,
306 intersection, <span class="comment">// This will be the position of the collision</span>
307 hitTriangle, <span class="comment">// This will be the triangle hit in the collision</span>
308 IDFlag_IsPickable, <span class="comment">// This ensures that only nodes that we have</span>
309 <span class="comment">// set up to be pickable are considered</span>
310 0); <span class="comment">// Check the entire scene (this is actually the implicit default)</span>
311
312 <span class="comment">// If the ray hit anything, move the billboard to the collision position</span>
313 <span class="comment">// and draw the triangle that was hit.</span>
314 <span class="keywordflow">if</span>(selectedSceneNode)
315 {
316 bill-&gt;setPosition(intersection);
317
318 <span class="comment">// We need to reset the transform before doing our own rendering.</span>
319 driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#aaf6e88bedf7b91666a2bd34f46e092fc" title="Sets transformation matrices.">setTransform</a>(<a class="code" href="namespaceirr_1_1video.html#a15b57657a320243be03ae6f66fcff43da843cf42adb3fa9caf61c9e228cf14e85" title="World transformation.">video::ETS_WORLD</a>, <a class="code" href="namespaceirr_1_1core.html#a73fa92e638c5ca97efd72da307cc9b65" title="Typedef for f32 matrix.">core::matrix4</a>());
320 driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a8c9e31b41b7e6fd26cf65ce538ebab05" title="Sets a material.">setMaterial</a>(material);
321 driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#ac5eb03a333a43d17278dad31be19efca" title="Draws a 3d triangle.">draw3DTriangle</a>(hitTriangle, video::SColor(0,255,0,0));
322
323 <span class="comment">// We can check the flags for the scene node that was hit to see if it should be</span>
324 <span class="comment">// highlighted. The animated nodes can be highlighted, but not the Quake level mesh</span>
325 <span class="keywordflow">if</span>((selectedSceneNode-&gt;getID() &amp; IDFlag_IsHighlightable) == IDFlag_IsHighlightable)
326 {
327 highlightedSceneNode = selectedSceneNode;
328
329 <span class="comment">// Highlighting in this case means turning lighting OFF for this node,</span>
330 <span class="comment">// which means that it will be drawn with full brightness.</span>
331 highlightedSceneNode-&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>);
332 }
333 }
334
335 <span class="comment">// We&#39;re all done drawing, so end the scene.</span>
336 driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a75f61a93c5fc9fdf161c044d27bc994e" title="Presents the rendered image to the screen.">endScene</a>();
337
338 <span class="keywordtype">int</span> fps = driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a5b71428402c0b6a3b18b8f2fa408af13" title="Returns current frames per second value.">getFPS</a>();
339
340 <span class="keywordflow">if</span> (lastFPS != fps)
341 {
342 <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">&quot;Collision detection example - Irrlicht Engine [&quot;</span>;
343 str += driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a87ca51832295b2dceaa1e258daf863f1" title="Gets name of this video driver.">getName</a>();
344 str += <span class="stringliteral">&quot;] FPS:&quot;</span>;
345 str += fps;
346
347 device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a3d7c98d520bf18ce1973c6f1439a7c0f" title="Sets the caption of the window.">setWindowCaption</a>(str.c_str());
348 lastFPS = fps;
349 }
350 }
351
352 device-&gt;<a class="code" href="classirr_1_1_i_reference_counted.html#afb169a857e0d2cdb96b8821cb9bff17a" title="Drops the object. Decrements the reference counter by one.">drop</a>();
353
354 <span class="keywordflow">return</span> 0;
355}
356</pre></div> </div></div>
357</div>
358 <div id="nav-path" class="navpath">
359 <ul>
360<!-- window showing the filter options -->
361<div id="MSearchSelectWindow"
362 onmouseover="return searchBox.OnSearchSelectShow()"
363 onmouseout="return searchBox.OnSearchSelectHide()"
364 onkeydown="return searchBox.OnSearchSelectKey(event)">
365<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>
366
367<!-- iframe showing the search results (closed by default) -->
368<div id="MSearchResultsWindow">
369<iframe src="javascript:void(0)" frameborder="0"
370 name="MSearchResults" id="MSearchResults">
371</iframe>
372</div>
373
374
375 <li class="footer">
376<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
377Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:41 for Irrlicht 3D Engine by
378<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
379 </ul>
380 </div>
381
382
383</body>
384</html>