<!-- Wanted to avoid copying .css to each folder, so copied default .css from doxyen in here, kicked out most stuff we don't need for examples and modified some a little bit.
Target was having a single html in each example folder which is created from the main.cpp files and needs no files besides some images below media folder.
<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>
<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><divclass="fragment"><divclass="line"><spanclass="preprocessor">#include <irrlicht.h></span></div><divclass="line"><spanclass="preprocessor">#include "driverChoice.h"</span></div><divclass="line"><spanclass="preprocessor">#include "exampleHelper.h"</span></div><divclass="line"></div><divclass="line"><spanclass="keyword">using namespace </span>irr;</div><divclass="line"></div><divclass="line"><spanclass="preprocessor">#ifdef _MSC_VER</span></div><divclass="line"><spanclass="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span></div><divclass="line"><spanclass="preprocessor">#endif</span></div><divclass="line"></div><divclass="line"><spanclass="keyword">enum</span></div><divclass="line">{</div><divclass="line"><spanclass="comment">// I use this ISceneNode ID to indicate a scene node that is</span></div><divclass="line"><spanclass="comment">// not pickable by getSceneNodeAndCollisionPointFromRay()</span></div><divclass="line"> ID_IsNotPickable = 0,</div><divclass="line"></div><divclass="line"><spanclass="comment">// I use this flag in ISceneNode IDs to indicate that the</span></div><divclass="line"><spanclass="comment">// scene node can be picked by ray selection.</span></div><divclass="line"> IDFlag_IsPickable = 1 << 0,</div><divclass="line"></div><divclass="line"><spanclass="comment">// I use this flag in ISceneNode IDs to indicate that the</span></div><divclass="line"><spanclass="comment">// scene node can be highlighted. In this example, the</span></div><divclass="line"><spanclass="comment">// homonids can be highlighted, but the level mesh can't.</span></div><divclass="line"> IDFlag_IsHighlightable = 1 << 1</div><divclass="line">};</div><divclass="line"></div><divclass="line"><spanclass="keywordtype">int</span> main()</div><divclass="line">{</div><divclass="line"><spanclass="comment">// ask user for driver</span></div><divclass="line"> video::E_DRIVER_TYPE driverType=driverChoiceConsole();</div><divclass="line"><spanclass="keywordflow">if</span> (driverType==video::EDT_COUNT)</div><divclass="line"><spanclass="keywordflow">return</span> 1;</div><divclass="line"></div><divclass="line"><spanclass="comment">// create device</span></div><divclass="line"></div><divclass="line"> IrrlichtDevice *device =</div><divclass="line"> createDevice(driverType, core::dimension2d<u32>(640, 480), 16, <spanclass="keyword">false</span>);</div><divclass="line"></div><divclass="line"><spanclass="keywordflow">if</span> (device == 0)</div><divclass="line"><spanclass="keywordflow">return</span> 1; <spanclass="comment">// could not create selected driver.</span></div></div><!-- fragment --><p> If we want to receive information about the material of a hit triangle we have to get collisions per meshbuffer. The only disadvantage of this is that getting them per meshbuffer can be a little bit slower than per mesh, but usually that's not noticeable. If you set this to false you will no longer get material names in the title bar. </p><divclass="fragment"><divclass="line"><spanclass="keyword">const</span><spanclass="keywordtype">bool</span> separateMeshBuffers = <spanclass="keyword">true</span>;</div><divclass="line"></div><divclass="line">video::IVideoDriver* driver = device->getVideoDriver();</div><divclass="line">scene::ISceneManager* smgr = device->getSceneManager();</div><divclass="line"></div><divclass="line"><spanclass="keyword">const</span> io::path mediaPath = getExampleMediaPath();</div><divclass="line"></div><divclass="line">device->getFileSystem()->addFileArchive(mediaPath + <spanclass="stringliteral">
<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 which 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, -1000, 0), which approximates realistic gravity (depends on the units which are used in the scene model). You could set it to (0,0,0) to disable gravity. And the last value is just an offset: Without it 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, 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><divclass="fragment"><divclass="line"><spanclass="comment">// Set a jump speed of 300 units per second, which gives a fairly realistic jump</span></div><divclass="line"><spanclass="comment">// when used with the gravity of (0, -1000, 0) in the collision response animator.</span></div><divclass="line">scene::ICameraSceneNode* camera =</div><divclass="line"> smgr->addCameraSceneNodeFPS(0, 100.0f, .3f, ID_IsNotPickable, 0, 0, <spanclass="keyword">true</span>, 300.f);</div><divclass="line">camera->setPosition(core::vector3df(50,50,-60));</div><divclass="line">camera->setTarget(core::vector3df(-70,30,-60));</div><divclass="line"></div><divclass="line"><spanclass="keywordflow">if</span> (selector)</div><divclass="line">{</div><divclass="line"> scene::ISceneNodeAnimatorCollisionResponse * anim = smgr->createCollisionResponseAnimator(</div><divclass="line"> selector, camera, core::vector3df(30,50,30),</div><divclass="line"> core::vector3df(0,-1000,0), core::vector3df(0,30,0));</div><divclass="line"> selector->drop(); <spanclass="comment">// As soon as we're done with the selector, drop it.</span></div><divclass="line"> camera->addAnimator(anim);</div><divclass="line"> anim->drop(); <spanclass="comment">// And likewise, drop the animator when we're done referring to it.</span></div><divclass="line">}</div><divclass="line"></div><divclass="line"><spanclass="comment">// Now I create three animated characters which we can pick, a dynamic light for</span></div><divclass="line"><spanclass="comment">// lighting them, and a billboard for drawing where we found an intersection.</span></div><divclass="line"></div><divclass="line"><spanclass="comment">// First, let's get rid of the mouse cursor. We'll use a billboard to show</span></div><divclass="line"><spanclass="comment">// what we're looking at.</span></div><divclass="line">device->getCursorControl()->setVisible(<spanclass="keyword">false</span>);</div><divclass="line"></div><divclass="line"><spanclass="comment">// Add the billboard.</span></div><divclass="line">scene::IBillboardSceneNode * bill = smgr->addBillboardSceneNode();</div><divclass="line">bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );</div><divclass="line">bill->setMaterialTexture(0, driver->getTexture(mediaPath + <spanclass="stringliteral">"particle.bmp"</span>));</div><divclass="line">bill->setMaterialFlag(video::EMF_LIGHTING, <spanclass="keyword">false</span>);</div><divclass="line">bill->setMaterialFlag(video::EMF_ZBUFFER, <spanclass="keyword">false</span>);</div><divclass="line">bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));</div><divclass="line">bill->setID(ID_IsNotPickable); <spanclass="comment">// This ensures that we don't accidentally ray-pick it</span></div></d