Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > by-pkgid > 58828b263d8f56d90ac336dea07a4586 > files > 748

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Irrlicht Engine: Tutorial 17: Helloworld mobile</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<table class="irrlicht" >
  <tr valign="middle"> 
    <td><font size="2"><a class="qindex" href="index.html"><font color="#FFFFFF">Home</font></a> 
      | <a class="qindex" href="namespaces.html"><font color="#FFFFFF">Namespaces</font></a> 
      | <a class="qindex" href="hierarchy.html"><font color="#FFFFFF">Hierarchy</font></a> 
      | <a class="qindex" href="classes.html"><font color="#FFFFFF">Alphabetical 
      List</font></a> | <a class="qindex" href="annotated.html"><font color="#FFFFFF"> 
      Class list</font></a> | <a class="qindex" href="files.html"><font color="#FFFFFF">Files</font></a> 
      | <a class="qindex" href="namespacemembers.html"><font color="#FFFFFF"> 
      Namespace&nbsp;Members</font></a> | <a class="qindex" href="functions.html"><font color="#FFFFFF">Class 
      members</font></a> | <a class="qindex" href="globals.html"><font color="#FFFFFF">File 
      members</font></a> | <a class="qindex" href="pages.html"><font color="#FFFFFF">Tutorials</font></a></font> </td>
  </tr>
</table>
<!-- Generated by Doxygen 1.5.6 -->
<div class="contents">
<h1><a class="anchor" name="example017">Tutorial 17: Helloworld mobile </a></h1><div align="center">
<img src="017shot.jpg" alt="017shot.jpg">
</div>
  This example show Hello World for Windows mobile. It compiles on other platform too. The only differences between the original examples are. You need a GUI, because otherwise you can't quit the application. You need a Filesystem, which is relative based to your executable. <div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>

<span class="preprocessor">#if defined ( _IRR_WINDOWS_ )</span>
<span class="preprocessor"></span><span class="preprocessor">        #include &lt;windows.h&gt;</span>
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="keyword">using namespace </span>irr;
<span class="keyword">using namespace </span>core;
<span class="keyword">using namespace </span>scene;
<span class="keyword">using namespace </span>video;
<span class="keyword">using namespace </span>io;
<span class="keyword">using namespace </span>gui;

<span class="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span>
<span class="preprocessor"></span>
<span class="keyword">class </span>EventReceiver_basic : <span class="keyword">public</span> IEventReceiver
{
<span class="keyword">private</span>:
        IrrlichtDevice *Device;
<span class="keyword">public</span>:
        EventReceiver_basic ( IrrlichtDevice *device ): Device ( device ) {}

        <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
        {
                <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#c9eed96e06e85ce3c86fcbbbe9e48a0ce85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a>)
                {
                        <a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();

                        <span class="keywordflow">switch</span>(event.GUIEvent.EventType)
                        {
                                <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#eac71ad17341a4b6e9026ae11d576808308ee345c92444931f83e48354072d98" title="A button was clicked.">EGET_BUTTON_CLICKED</a>:
                                <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 2)
                                {
                                        Device-&gt;closeDevice();
                                        <span class="keywordflow">return</span> <span class="keyword">true</span>;
                                } <span class="keywordflow">break</span>;
                        }
                }

                <span class="keywordflow">return</span> <span class="keyword">false</span>;
        }
};

<span class="keyword">class </span>CSampleSceneNode : <span class="keyword">public</span> ISceneNode
{
        aabbox3d&lt;f32&gt; Box;
        S3DVertex Vertices[4];
        SMaterial Material;
<span class="keyword">public</span>:

        CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, <a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span>)
                : ISceneNode(parent, mgr, id)
        {
                Material.Wireframe = <span class="keyword">false</span>;
                Material.Lighting = <span class="keyword">false</span>;

                Vertices[0] = S3DVertex(0,0,10, 1,1,0, SColor(255,0,255,255), 0, 1);
                Vertices[1] = S3DVertex(10,0,-10, 1,0,0, SColor(255,255,0,255), 1, 1);
                Vertices[2] = S3DVertex(0,20,0, 0,1,1, SColor(255,255,255,0), 1, 0);
                Vertices[3] = S3DVertex(-10,0,-10, 0,0,1, SColor(255,0,255,0), 0, 0);
                Box.reset(Vertices[0].Pos);
                <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=1; i&lt;4; ++i)
                        Box.addInternalPoint(Vertices[i].Pos);
        }
        <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRegisterSceneNode()
        {
                <span class="keywordflow">if</span> (IsVisible)
                        SceneManager-&gt;registerNodeForRendering(<span class="keyword">this</span>);

                ISceneNode::OnRegisterSceneNode();
        }

        <span class="keyword">virtual</span> <span class="keywordtype">void</span> render()
        {
                <a class="code" href="namespaceirr.html#e9f8ec82692ad3b83c21f555bfa70bcc" title="16 bit unsigned variable.">u16</a> indices[] = {       0,2,3, 2,1,3, 1,0,3, 2,0,1      };
                IVideoDriver* driver = SceneManager-&gt;getVideoDriver();

                driver-&gt;setMaterial(Material);
                driver-&gt;setTransform(<a class="code" href="namespaceirr_1_1video.html#15b57657a320243be03ae6f66fcff43d843cf42adb3fa9caf61c9e228cf14e85" title="World transformation.">ETS_WORLD</a>, AbsoluteTransformation);
                driver-&gt;drawIndexedTriangleList(&amp;Vertices[0], 4, &amp;indices[0], 4);
        }

        <span class="keyword">virtual</span> <span class="keyword">const</span> aabbox3d&lt;f32&gt;&amp; getBoundingBox()<span class="keyword"> const</span>
<span class="keyword">        </span>{
                <span class="keywordflow">return</span> Box;
        }

        <span class="keyword">virtual</span> <a class="code" href="namespaceirr.html#0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> getMaterialCount()
        {
                <span class="keywordflow">return</span> 1;
        }

        <span class="keyword">virtual</span> SMaterial&amp; getMaterial(<a class="code" href="namespaceirr.html#0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i)
        {
                <span class="keywordflow">return</span> Material;
        }       
};
</pre></div> ! Startup a Windows Mobile Device <div class="fragment"><pre class="fragment">IrrlichtDevice *startup()
{
        <span class="comment">// both software and burnings video can be used</span>
        <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">E_DRIVER_TYPE</a> driverType = <a class="code" href="namespaceirr_1_1video.html#e35a6de6d436c76107ad157fe42356d01598cd235a1a6bd052e2011b559e8995" title="The Irrlicht Engine Software renderer.">EDT_SOFTWARE</a>; <span class="comment">// EDT_BURNINGSVIDEO;</span>

        <span class="comment">// create device</span>
        IrrlichtDevice *device = 0;

<span class="preprocessor">#if defined (_IRR_USE_WINDOWS_CE_DEVICE_)</span>
<span class="preprocessor"></span>        <span class="comment">// set to standard mobile fullscreen 240x320</span>
        device = <a class="code" href="namespaceirr.html#baf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the...">createDevice</a>(driverType, dimension2d&lt;u32&gt;(240, 320), 16, <span class="keyword">true</span> );
<span class="preprocessor">#else</span>
<span class="preprocessor"></span>        <span class="comment">// on PC. use window mode</span>
        device = <a class="code" href="namespaceirr.html#baf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the...">createDevice</a>(driverType, dimension2d&lt;u32&gt;(240, 320), 16, <span class="keyword">false</span> );
<span class="preprocessor">#endif          </span>
<span class="preprocessor"></span>        <span class="keywordflow">if</span> ( 0 == device )
                <span class="keywordflow">return</span> 0;

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

        <span class="comment">// set the filesystem relative to the executable</span>
<span class="preprocessor">#if defined (_IRR_WINDOWS_)</span>
<span class="preprocessor"></span>        {
                <span class="keywordtype">wchar_t</span> buf[255];
                GetModuleFileNameW ( 0, buf, 255 );

                string&lt;c16&gt; base = buf;
                base = base.subString ( 0, base.findLast ( <span class="charliteral">'\\'</span> ) + 1 );
                device-&gt;getFileSystem()-&gt;registerFileArchive ( base );
        }
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
        IGUIStaticText *text = guienv-&gt;addStaticText(L<span class="stringliteral">"FPS: 25"</span>,
                rect&lt;s32&gt;(140,15,200,30), <span class="keyword">false</span>, <span class="keyword">false</span>, 0, 100 );

        guienv-&gt;addButton(core::rect&lt;int&gt;(200,10,238,30), 0, 2, L<span class="stringliteral">"Quit"</span>);

        <span class="comment">// add irrlicht logo</span>
        guienv-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">"../../media/irrlichtlogo3.png"</span>),
                                        core::position2d&lt;s32&gt;(0,-2));
        <span class="keywordflow">return</span> device;
}
</pre></div> ! <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> run ( IrrlichtDevice *device )
{
        <span class="keywordflow">while</span>(device-&gt;run())
        <span class="keywordflow">if</span> (device-&gt;isWindowActive())
        {
                device-&gt;getVideoDriver()-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, SColor(0,100,100,100));
                device-&gt;getSceneManager()-&gt;drawAll();
                device-&gt;getGUIEnvironment()-&gt;drawAll();
                device-&gt;getVideoDriver()-&gt;endScene ();

                IGUIElement *stat = device-&gt;getGUIEnvironment()-&gt;
                        getRootGUIElement()-&gt;getElementFromId ( 100 );
                <span class="keywordflow">if</span> ( stat )
                {
                        <a class="code" href="namespaceirr_1_1core.html#ef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a> str = L<span class="stringliteral">"FPS: "</span>;
                        str += (<a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)device-&gt;getVideoDriver()-&gt;getFPS();

                        stat-&gt;setText ( str.c_str() );
                }
        }

        device-&gt;drop();
        <span class="keywordflow">return</span> 0;
}
</pre></div> ! <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> example_customscenenode()
{
        <span class="comment">// create device</span>
        IrrlichtDevice *device = startup();
        <span class="keywordflow">if</span> (device == 0)
                <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>

        <span class="comment">// create engine and camera</span>
        EventReceiver_basic receiver(device);
        device-&gt;setEventReceiver(&amp;receiver);
        
        IVideoDriver* driver = device-&gt;getVideoDriver();
        ISceneManager* smgr = device-&gt;getSceneManager();
        IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();


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

        CSampleSceneNode *myNode = 
                <span class="keyword">new</span> CSampleSceneNode(smgr-&gt;getRootSceneNode(), smgr, 666);

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

        <span class="keywordflow">if</span>(anim)
        {
                myNode-&gt;addAnimator(anim);
                anim-&gt;drop();
                anim = 0; <span class="comment">// As I shouldn't refer to it again, ensure that I can't</span>
        }

        myNode-&gt;drop();
        myNode = 0; <span class="comment">// As I shouldn't refer to it again, ensure that I can't</span>

        <span class="keywordflow">return</span> run ( device );
}

<span class="keyword">class </span>EventReceiver_terrain : <span class="keyword">public</span> IEventReceiver
{
<span class="keyword">public</span>:

        EventReceiver_terrain(IrrlichtDevice *device, scene::ISceneNode* terrain, scene::ISceneNode* skybox, scene::ISceneNode* skydome) :
                Device ( device ), Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true)
        {
                Skybox-&gt;setVisible(<span class="keyword">true</span>);
                Skydome-&gt;setVisible(<span class="keyword">false</span>);
        }

        <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
        {
                <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#c9eed96e06e85ce3c86fcbbbe9e48a0ce85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a>)
                {
                        <a class="code" href="namespaceirr.html#c66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();

                        <span class="keywordflow">switch</span>(event.GUIEvent.EventType)
                        {
                                <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#eac71ad17341a4b6e9026ae11d576808308ee345c92444931f83e48354072d98" title="A button was clicked.">EGET_BUTTON_CLICKED</a>:
                                <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 2)
                                {
                                        Device-&gt;closeDevice();
                                        <span class="keywordflow">return</span> <span class="keyword">true</span>;
                                } <span class="keywordflow">break</span>;
                        }
                }

                <span class="comment">// check if user presses the key 'W' or 'D'</span>
                <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#c9eed96e06e85ce3c86fcbbbe9e48a0c6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> &amp;&amp; !event.KeyInput.PressedDown)
                {
                        <span class="keywordflow">switch</span> (event.KeyInput.Key)
                        {
                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb3e559e3169016a3180c45c2828f391af2">irr::KEY_KEY_W</a>: <span class="comment">// switch wire frame mode</span>
                                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3bc620823efed8d6bdbd46c8a0180893a" title="Draw as wireframe or filled triangles? Default: false.">video::EMF_WIREFRAME</a>,
                                                !Terrain-&gt;getMaterial(0).Wireframe);
                                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d33726bbddc57e6b37b05481b640eefb07" title="Draw as point cloud or filled triangles? Default: false.">video::EMF_POINTCLOUD</a>, <span class="keyword">false</span>);
                                <span class="keywordflow">return</span> <span class="keyword">true</span>;
                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb352e3c10f6d5c2bc0bd446273879f9519">irr::KEY_KEY_P</a>: <span class="comment">// switch wire frame mode</span>
                                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d33726bbddc57e6b37b05481b640eefb07" title="Draw as point cloud or filled triangles? Default: false.">video::EMF_POINTCLOUD</a>,
                                                !Terrain-&gt;getMaterial(0).PointCloud);
                                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3bc620823efed8d6bdbd46c8a0180893a" title="Draw as wireframe or filled triangles? Default: false.">video::EMF_WIREFRAME</a>, <span class="keyword">false</span>);
                                <span class="keywordflow">return</span> <span class="keyword">true</span>;
                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb3d20e7e220103e611752b90edeb6cbc9d">irr::KEY_KEY_D</a>: <span class="comment">// toggle detail map</span>
                                Terrain-&gt;setMaterialType(
                                        Terrain-&gt;getMaterial(0).MaterialType == <a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f19bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a> ?
                                        <a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f1065af4f8daeb15f81bfe0417a3f231b1" title="Detail mapped material.">video::EMT_DETAIL_MAP</a> : <a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f19bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>);
                                <span class="keywordflow">return</span> <span class="keyword">true</span>;
                        <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#54da2a0e231901735e3da1b0edf72eb3e52bafc112fc6c52f6b49cea42fa246e">irr::KEY_KEY_S</a>: <span class="comment">// toggle skies</span>
                                showBox=!showBox;
                                Skybox-&gt;setVisible(showBox);
                                Skydome-&gt;setVisible(!showBox);
                                <span class="keywordflow">return</span> <span class="keyword">true</span>;
                        <span class="keywordflow">default</span>:
                                <span class="keywordflow">break</span>;
                        }
                }

                <span class="keywordflow">return</span> <span class="keyword">false</span>;
        }

<span class="keyword">private</span>:
        IrrlichtDevice *Device;
        scene::ISceneNode* Terrain;
        scene::ISceneNode* Skybox;
        scene::ISceneNode* Skydome;
        <span class="keywordtype">bool</span> showBox;
};
</pre></div><p>
The start of the main function starts like in most other example. We ask the user for the desired renderer and start it up. This time with the advanced parameter handling. <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> example_terrain()
{
        <span class="comment">// create device</span>
        IrrlichtDevice *device = startup();
        <span class="keywordflow">if</span> (device == 0)
                <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
</pre></div><p>
First, we add standard stuff to the scene: A nice irrlicht engine logo, a small help text, a user controlled camera, and we disable the mouse cursor. <div class="fragment"><pre class="fragment">        video::IVideoDriver* driver = device-&gt;getVideoDriver();
        scene::ISceneManager* smgr = device-&gt;getSceneManager();
        gui::IGUIEnvironment* env = device-&gt;getGUIEnvironment();


        <span class="comment">//set other font</span>
        <span class="comment">//env-&gt;getSkin()-&gt;setFont(env-&gt;getFont("../../media/fontlucida.png"));</span>

        <span class="comment">// add some help text</span>
        env-&gt;addStaticText(
                L<span class="stringliteral">"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome"</span>,
                core::rect&lt;s32&gt;(5,250,235,320), <span class="keyword">true</span>, <span class="keyword">true</span>, 0, -1, <span class="keyword">true</span>);

        <span class="comment">// add camera</span>
        scene::ICameraSceneNode* camera =
                smgr-&gt;addCameraSceneNodeFPS(0,100.0f,1.2f);

        camera-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(2700*2,255*2,2600*2));
        camera-&gt;setTarget(<a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(2397*2,343*2,2700*2));
        camera-&gt;setFarValue(42000.0f);

        <span class="comment">// disable mouse cursor</span>
        device-&gt;getCursorControl()-&gt;setVisible(<span class="keyword">false</span>);
</pre></div><p>
Here comes the terrain renderer scene node: We add it just like any other scene node to the scene using ISceneManager::addTerrainSceneNode(). The only parameter we use is a file name to the heightmap we use. A heightmap is simply a gray scale texture. The terrain renderer loads it and creates the 3D terrain from it.<p>
To make the terrain look more big, we change the scale factor of it to (40, 4.4, 40). Because we don't have any dynamic lights in the scene, we switch off the lighting, and we set the file terrain-texture.jpg as texture for the terrain and detailmap3.jpg as second texture, called detail map. At last, we set the scale values for the texture: The first texture will be repeated only one time over the whole terrain, and the second one (detail map) 20 times. <div class="fragment"><pre class="fragment">        <span class="comment">// add terrain scene node</span>
        scene::ITerrainSceneNode* terrain = smgr-&gt;addTerrainSceneNode(
                <span class="stringliteral">"../../media/terrain-heightmap.bmp"</span>,
                0,                                      <span class="comment">// parent node</span>
                -1,                                     <span class="comment">// node id</span>
                <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.f, 0.f, 0.f),         <span class="comment">// position</span>
                <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.f, 0.f, 0.f),         <span class="comment">// rotation</span>
                <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(40.f, 4.4f, 40.f),      <span class="comment">// scale</span>
                video::SColor ( 255, 255, 255, 255 ),   <span class="comment">// vertexColor</span>
                5,                                      <span class="comment">// maxLOD</span>
                <a class="code" href="namespaceirr_1_1scene.html#6de1eb2d024f82b5b1af499d61523044be94d6195f435b8e08a38269e63af72e" title="patch size of 17, at most, use 5 levels of detail with this patch size.">scene::ETPS_17</a>,                         <span class="comment">// patchSize</span>
                4                                       <span class="comment">// smoothFactor</span>
                );

        <span class="keywordflow">if</span> ( terrain )
        {
                terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);

                terrain-&gt;setMaterialTexture(0,
                                driver-&gt;getTexture(<span class="stringliteral">"../../media/terrain-texture.jpg"</span>));
                terrain-&gt;setMaterialTexture(1,
                                driver-&gt;getTexture(<span class="stringliteral">"../../media/detailmap3.jpg"</span>));
                
                terrain-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#c8e9b6c66f7cebabd1a6d30cbc5430f1065af4f8daeb15f81bfe0417a3f231b1" title="Detail mapped material.">video::EMT_DETAIL_MAP</a>);

                terrain-&gt;scaleTexture(1.0f, 20.0f);
                <span class="comment">//terrain-&gt;setDebugDataVisible ( true );</span>
</pre></div><p>
To be able to do collision with the terrain, we create a triangle selector. If you want to know what triangle selectors do, just take a look into the collision tutorial. The terrain triangle selector works together with the terrain. To demonstrate this, we create a collision response animator and attach it to the camera, so that the camera will not be able to fly through the terrain. <div class="fragment"><pre class="fragment">                <span class="comment">// create triangle selector for the terrain     </span>
                scene::ITriangleSelector* selector
                        = smgr-&gt;createTerrainTriangleSelector(terrain, 0);
                terrain-&gt;setTriangleSelector(selector);

                <span class="comment">// create collision response animator and attach it to the camera</span>
                scene::ISceneNodeAnimator* anim = smgr-&gt;createCollisionResponseAnimator(
                        selector, camera, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(60,100,60),
                        <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0),
                        <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,50,0));
                selector-&gt;drop();
                camera-&gt;addAnimator(anim);
                anim-&gt;drop();
</pre></div> If you need access to the terrain data you can also do this directly via the following code fragment. <div class="fragment"><pre class="fragment">                scene::CDynamicMeshBuffer* buffer = <span class="keyword">new</span> scene::CDynamicMeshBuffer(<a class="code" href="namespaceirr_1_1video.html#0e3b59e025e0d0db0ed2ee0ce904deac7b5127a706ee33eb4385d702da007016" title="Vertex with two texture coordinates, video::S3DVertex2TCoords.">video::EVT_2TCOORDS</a>, <a class="code" href="namespaceirr_1_1video.html#f152a1edea2579f0517e0049525acb551c79610ea1191e124887efa16626f299">video::EIT_16BIT</a>);
                terrain-&gt;getMeshBufferForLOD(*buffer, 0);
                video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer-&gt;getVertexBuffer().getData();
                <span class="comment">// Work on data or get the IndexBuffer with a similar call.</span>
                buffer-&gt;drop(); <span class="comment">// When done drop the buffer again.</span>
        }
</pre></div><p>
To make the user be able to switch between normal and wireframe mode, we create an instance of the event reciever from above and let Irrlicht know about it. In addition, we add the skybox which we already used in lots of Irrlicht examples and a skydome, which is shown mutually exclusive with the skybox by pressing 'S'. <div class="fragment"><pre class="fragment">        <span class="comment">// create skybox and skydome</span>
        driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#caf6f7414534f7d62bff18c5bf11876f288b302e9d4faaba80c7796c7bc1682c">video::ETCF_CREATE_MIP_MAPS</a>, <span class="keyword">false</span>);

        scene::ISceneNode* skybox=smgr-&gt;addSkyBoxSceneNode(
                driver-&gt;getTexture(<span class="stringliteral">"../../media/irrlicht2_up.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"../../media/irrlicht2_dn.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"../../media/irrlicht2_lf.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"../../media/irrlicht2_rt.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"../../media/irrlicht2_ft.jpg"</span>),
                driver-&gt;getTexture(<span class="stringliteral">"../../media/irrlicht2_bk.jpg"</span>));
        scene::ISceneNode* skydome=smgr-&gt;addSkyDomeSceneNode(driver-&gt;getTexture(<span class="stringliteral">"../../media/skydome.jpg"</span>),16,8,0.95f,2.0f);

        driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#caf6f7414534f7d62bff18c5bf11876f288b302e9d4faaba80c7796c7bc1682c">video::ETCF_CREATE_MIP_MAPS</a>, <span class="keyword">true</span>);

        <span class="comment">// create event receiver</span>
        EventReceiver_terrain receiver( device, terrain, skybox, skydome);
        device-&gt;setEventReceiver(&amp;receiver);

        <span class="keywordflow">return</span> run ( device );
}
</pre></div><p>
<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> example_helloworld()
{
        <span class="comment">// create device</span>
        IrrlichtDevice *device = startup();
        <span class="keywordflow">if</span> (device == 0)
                <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>

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

        IAnimatedMesh* mesh = smgr-&gt;getMesh(<span class="stringliteral">"../../media/sydney.md2"</span>);
        <span class="keywordflow">if</span> (!mesh)
        {
                device-&gt;drop();
                <span class="keywordflow">return</span> 1;
        }
        IAnimatedMeshSceneNode* node = smgr-&gt;addAnimatedMeshSceneNode( mesh );
</pre></div><p>
To let the mesh look a little bit nicer, we change its material. We disable lighting because we do not have a dynamic light in here, and the mesh would be totally black otherwise. Then we set the frame loop, such that the predefined STAND animation is used. And last, we apply a texture to the mesh. Without it the mesh would be drawn using only a color. <div class="fragment"><pre class="fragment">        <span class="keywordflow">if</span> (node)
        {
                node-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#8a3bc00ae8137535b9fbc5f40add70d3cea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">EMF_LIGHTING</a>, <span class="keyword">false</span>);
                node-&gt;setMD2Animation(<a class="code" href="namespaceirr_1_1scene.html#08d4a84966e1d2886d0d57e4acbb4f1935893ae58423c41dace23ad13e262e2c">scene::EMAT_STAND</a>);
                node-&gt;setMaterialTexture( 0, driver-&gt;getTexture(<span class="stringliteral">"../../media/sydney.bmp"</span>) );
        }
</pre></div><p>
To look at the mesh, we place a camera into 3d space at the position (0, 30, -40). The camera looks from there to (0,5,0), which is approximately the place where our md2 model is. <div class="fragment"><pre class="fragment">        smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,30,-40), <a class="code" href="namespaceirr_1_1core.html#06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,5,0));

        EventReceiver_basic receiver(device);
        device-&gt;setEventReceiver(&amp;receiver);

        <span class="keywordflow">return</span> run ( device );

}

<span class="preprocessor">#if defined (_IRR_USE_WINDOWS_CE_DEVICE_)</span>
<span class="preprocessor"></span><span class="preprocessor">        #pragma comment(linker, "/subsystem:WINDOWSCE /ENTRY:main") </span>
<span class="preprocessor"></span><span class="preprocessor">#elif defined (_IRR_WINDOWS_)</span>
<span class="preprocessor"></span><span class="preprocessor">        #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")</span>
<span class="preprocessor">#endif</span>
</pre></div><p>
<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
{
        example_helloworld ();
        example_customscenenode();
        <span class="comment">//example_terrain();</span>
}
</pre></div> </div>
<hr size="1">
<address style="align: right;">
<small> </small>
</address>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr> 
    <td width="0"> <div align="left"><small><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="irrlicht.png" alt="The Irrlicht Engine" align="middle" border=0 width=88 height=31></a></small></div></td>
    <td> <div align="left"><small><em><font size="2">The <a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
        Engine</a> Documentation &copy; 2003-2009 by Nikolaus Gebhardt. Generated 
        on Sun Jan 10 09:24:07 2010 by <a href="http://www.doxygen.org" target="_blank">Doxygen</a> 
        (1.5.6)</font></em></small></div></td>
  </tr>
</table>
<address style="align: right;">
</address>
</body>
</html>