diff options
Diffstat (limited to 'libraries/irrlicht-1.8.1/doc/html/example002.html')
-rw-r--r-- | libraries/irrlicht-1.8.1/doc/html/example002.html | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/doc/html/example002.html b/libraries/irrlicht-1.8.1/doc/html/example002.html new file mode 100644 index 0000000..7cbcf5a --- /dev/null +++ b/libraries/irrlicht-1.8.1/doc/html/example002.html | |||
@@ -0,0 +1,218 @@ | |||
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 2: Quake3Map</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"> | ||
69 | var 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('example002.html',''); | ||
84 | </script> | ||
85 | <div id="doc-content"> | ||
86 | <div class="header"> | ||
87 | <div class="headertitle"> | ||
88 | <div class="title">Tutorial 2: Quake3Map </div> </div> | ||
89 | </div> | ||
90 | <div class="contents"> | ||
91 | <div class="textblock"><div class="image"> | ||
92 | <img src="002shot.jpg" alt="002shot.jpg"/> | ||
93 | </div> | ||
94 | <p>This Tutorial shows how to load a Quake 3 map into the engine, create a SceneNode for optimizing the speed of rendering, and how to create a user controlled camera.</p> | ||
95 | <p>Please note that you should know the basics of the engine before starting this tutorial. Just take a short look at the first tutorial, if you haven't done this yet: <a href="http://irrlicht.sourceforge.net/tut001.html">http://irrlicht.sourceforge.net/tut001.html</a></p> | ||
96 | <p>Lets start like the HelloWorld example: We include the irrlicht header files and an additional file to be able to ask the user for a driver type using the console. </p> | ||
97 | <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>></span> | ||
98 | <span class="preprocessor">#include <iostream></span> | ||
99 | </pre></div><p>As already written in the HelloWorld example, in the Irrlicht Engine everything can be found in the namespace 'irr'. To get rid of the irr:: in front of the name of every class, we tell the compiler that we use that namespace from now on, and we will not have to write that 'irr::'. There are 5 other sub namespaces 'core', 'scene', 'video', 'io' and 'gui'. Unlike in the HelloWorld example, we do not call 'using namespace' for these 5 other namespaces, because in this way you will see what can be found in which namespace. But if you like, you can also include the namespaces like in the previous example. </p> | ||
100 | <div class="fragment"><pre class="fragment"><span class="keyword">using namespace </span>irr; | ||
101 | </pre></div><p>Again, to be able to use the Irrlicht.DLL file, we need to link with the Irrlicht.lib. We could set this option in the project settings, but to make it easy, we use a pragma comment lib: </p> | ||
102 | <div class="fragment"><pre class="fragment"><span class="preprocessor">#ifdef _MSC_VER</span> | ||
103 | <span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span> | ||
104 | <span class="preprocessor">#endif</span> | ||
105 | </pre></div><p>Ok, lets start. Again, we use the main() method as start, not the WinMain(). </p> | ||
106 | <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main() | ||
107 | { | ||
108 | </pre></div><p>Like in the HelloWorld example, we create an IrrlichtDevice with <a class="el" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice()</a>. The difference now is that we ask the user to select which video driver to use. The Software device might be too slow to draw a huge Quake 3 map, but just for the fun of it, we make this decision possible, too. Instead of copying this whole code into your app, you can simply include <a class="el" href="driver_choice_8h.html">driverChoice.h</a> from Irrlicht's include directory. The function driverChoiceConsole does exactly the same. </p> | ||
109 | <div class="fragment"><pre class="fragment"> <span class="comment">// ask user for driver</span> | ||
110 | |||
111 | <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; | ||
112 | |||
113 | printf(<span class="stringliteral">"Please select the driver you want for this example:\n"</span>\ | ||
114 | <span class="stringliteral">" (a) OpenGL 1.5\n (b) Direct3D 9.0c\n (c) Direct3D 8.1\n"</span>\ | ||
115 | <span class="stringliteral">" (d) Burning's Software Renderer\n (e) Software Renderer\n"</span>\ | ||
116 | <span class="stringliteral">" (f) NullDevice\n (otherKey) exit\n\n"</span>); | ||
117 | |||
118 | <span class="keywordtype">char</span> i; | ||
119 | std::cin >> i; | ||
120 | |||
121 | <span class="keywordflow">switch</span>(i) | ||
122 | { | ||
123 | <span class="keywordflow">case</span> <span class="charliteral">'a'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0a2715182a79f1cb8e2826fd68a8150a53" title="OpenGL device, available on most platforms.">video::EDT_OPENGL</a>; <span class="keywordflow">break</span>; | ||
124 | <span class="keywordflow">case</span> <span class="charliteral">'b'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0a4691ca314f9018f508dcf2c57dcaacec" title="Direct3D 9 device, only available on Win32 platforms.">video::EDT_DIRECT3D9</a>;<span class="keywordflow">break</span>; | ||
125 | <span class="keywordflow">case</span> <span class="charliteral">'c'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0a8cc3807f6f28404f3424ad7e31b3142f" title="Direct3D8 device, only available on Win32 platforms.">video::EDT_DIRECT3D8</a>;<span class="keywordflow">break</span>; | ||
126 | <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae85481da26159b967191ccc6de1e4a05" title="The Burning's Software Renderer, an alternative software renderer.">video::EDT_BURNINGSVIDEO</a>;<span class="keywordflow">break</span>; | ||
127 | <span class="keywordflow">case</span> <span class="charliteral">'e'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0a1598cd235a1a6bd052e2011b559e8995" title="The Irrlicht Engine Software renderer.">video::EDT_SOFTWARE</a>; <span class="keywordflow">break</span>; | ||
128 | <span class="keywordflow">case</span> <span class="charliteral">'f'</span>: driverType = <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0acfdbd476cbfd4d05e72f9adffcc42210" title="Null driver, useful for applications to run the engine without visualisation.">video::EDT_NULL</a>; <span class="keywordflow">break</span>; | ||
129 | <span class="keywordflow">default</span>: <span class="keywordflow">return</span> 1; | ||
130 | } | ||
131 | |||
132 | <span class="comment">// create device and exit if creation failed</span> | ||
133 | |||
134 | IrrlichtDevice *device = | ||
135 | <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, core::dimension2d<u32>(640, 480)); | ||
136 | |||
137 | <span class="keywordflow">if</span> (device == 0) | ||
138 | <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span> | ||
139 | </pre></div><p>Get a pointer to the video driver and the SceneManager so that we do not always have to call <a class="el" href="classirr_1_1_irrlicht_device.html#ada90707ba5c645d47e000e4e0f87c4c4" title="Provides access to the video driver for drawing 3d and 2d geometry.">irr::IrrlichtDevice::getVideoDriver()</a> and <a class="el" href="classirr_1_1_irrlicht_device.html#a891b503ff4d5041296d88f23f97d7b3d" title="Provides access to the scene manager.">irr::IrrlichtDevice::getSceneManager()</a>. </p> | ||
140 | <div class="fragment"><pre class="fragment"> video::IVideoDriver* driver = device->getVideoDriver(); | ||
141 | scene::ISceneManager* smgr = device->getSceneManager(); | ||
142 | </pre></div><p>To display the Quake 3 map, we first need to load it. Quake 3 maps are packed into .pk3 files which are nothing else than .zip files. So we add the .pk3 file to our <a class="el" href="classirr_1_1io_1_1_i_file_system.html" title="The FileSystem manages files and archives and provides access to them.">irr::io::IFileSystem</a>. After it was added, we are able to read from the files in that archive as if they are directly stored on the disk. </p> | ||
143 | <div class="fragment"><pre class="fragment"> device->getFileSystem()->addFileArchive(<span class="stringliteral">"../../media/map-20kdm2.pk3"</span>); | ||
144 | </pre></div><p>Now we can load the mesh by calling <a class="el" 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.">irr::scene::ISceneManager::getMesh()</a>. We get a pointer returned to an <a class="el" href="classirr_1_1scene_1_1_i_animated_mesh.html" title="Interface for an animated mesh.">irr::scene::IAnimatedMesh</a>. As you might know, Quake 3 maps are not really animated, they are only a huge chunk of static geometry with some materials attached. Hence the IAnimatedMesh consists of only one frame, so we get the "first frame" of the "animation", which is our quake level and create an Octree scene node with it, using <a class="el" 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.">irr::scene::ISceneManager::addOctreeSceneNode()</a>. The Octree optimizes the scene a little bit, trying to draw only geometry which is currently visible. An alternative to the Octree would be a <a class="el" href="classirr_1_1scene_1_1_i_mesh_scene_node.html" title="A scene node displaying a static mesh.">irr::scene::IMeshSceneNode</a>, which would always draw the complete geometry of the mesh, without optimization. Try it: Use <a class="el" href="classirr_1_1scene_1_1_i_scene_manager.html#aa0a32f9f5b13d94e24eed80bdb999919" title="Adds a scene node for rendering a static mesh.">irr::scene::ISceneManager::addMeshSceneNode()</a> instead of addOctreeSceneNode() and compare the primitives drawn by the video driver. (There is a <a class="el" href="classirr_1_1video_1_1_i_video_driver.html#a2ce9be45cacb4aa034d3afdb489a57a3" title="Returns amount of primitives (mostly triangles) which were drawn in the last frame.">irr::video::IVideoDriver::getPrimitiveCountDrawn()</a> method in the <a class="el" href="classirr_1_1video_1_1_i_video_driver.html" title="Interface to driver which is able to perform 2d and 3d graphics functions.">irr::video::IVideoDriver</a> class). Note that this optimization with the Octree is only useful when drawing huge meshes consisting of lots of geometry. </p> | ||
145 | <div class="fragment"><pre class="fragment"> scene::IAnimatedMesh* mesh = smgr->getMesh(<span class="stringliteral">"20kdm2.bsp"</span>); | ||
146 | scene::ISceneNode* node = 0; | ||
147 | |||
148 | <span class="keywordflow">if</span> (mesh) | ||
149 | node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024); | ||
150 | <span class="comment">// node = smgr->addMeshSceneNode(mesh->getMesh(0));</span> | ||
151 | </pre></div><p>Because the level was not modelled around the origin (0,0,0), we translate the whole level a little bit. This is done on <a class="el" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">irr::scene::ISceneNode</a> level using the methods <a class="el" href="classirr_1_1scene_1_1_i_scene_node.html#a2166eb0a92cc0e46c49266f41a68ed50" title="Sets the position of the node relative to its parent.">irr::scene::ISceneNode::setPosition()</a> (in this case), <a class="el" href="classirr_1_1scene_1_1_i_scene_node.html#adb6ff54f52d3a9e1514cd487a550935c" title="Sets the rotation of the node relative to its parent.">irr::scene::ISceneNode::setRotation()</a>, and <a class="el" href="classirr_1_1scene_1_1_i_scene_node.html#a1d710e1e20546bd89affe09fa943b0e2" title="Sets the relative scale of the scene node.">irr::scene::ISceneNode::setScale()</a>. </p> | ||
152 | <div class="fragment"><pre class="fragment"> <span class="keywordflow">if</span> (node) | ||
153 | node->setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-1300,-144,-1249)); | ||
154 | </pre></div><p>Now we only need a camera to look at the Quake 3 map. We want to create a user controlled camera. There are some cameras available in the Irrlicht engine. For example the MayaCamera which can be controlled like the camera in Maya: Rotate with left mouse button pressed, Zoom with both buttons pressed, translate with right mouse button pressed. This could be created with <a class="el" href="classirr_1_1scene_1_1_i_scene_manager.html#a18e81a59e02231567ac938ea287fe523" title="Adds a maya style user controlled camera scene node to the scene graph.">irr::scene::ISceneManager::addCameraSceneNodeMaya()</a>. But for this example, we want to create a camera which behaves like the ones in first person shooter games (FPS) and hence use <a class="el" 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...">irr::scene::ISceneManager::addCameraSceneNodeFPS()</a>. </p> | ||
155 | <div class="fragment"><pre class="fragment"> smgr->addCameraSceneNodeFPS(); | ||
156 | </pre></div><p>The mouse cursor needs not be visible, so we hide it via the irr::IrrlichtDevice::ICursorControl. </p> | ||
157 | <div class="fragment"><pre class="fragment"> device->getCursorControl()->setVisible(<span class="keyword">false</span>); | ||
158 | </pre></div><p>We have done everything, so lets draw it. We also write the current frames per second and the primitives drawn into the caption of the window. The test for <a class="el" href="classirr_1_1_irrlicht_device.html#abd3c88336b739da2694883d5ffd25a70" title="Returns if the window is active.">irr::IrrlichtDevice::isWindowActive()</a> is optional, but prevents the engine to grab the mouse cursor after task switching when other programs are active. The call to <a class="el" href="classirr_1_1_irrlicht_device.html#a731727774fad9fc4c6c1c85277ca36dc" title="Cause the device to temporarily pause execution and let other processes run.">irr::IrrlichtDevice::yield()</a> will avoid the busy loop to eat up all CPU cycles when the window is not active. </p> | ||
159 | <div class="fragment"><pre class="fragment"> <span class="keywordtype">int</span> lastFPS = -1; | ||
160 | |||
161 | <span class="keywordflow">while</span>(device->run()) | ||
162 | { | ||
163 | <span class="keywordflow">if</span> (device->isWindowActive()) | ||
164 | { | ||
165 | driver->beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, video::SColor(255,200,200,200)); | ||
166 | smgr->drawAll(); | ||
167 | driver->endScene(); | ||
168 | |||
169 | <span class="keywordtype">int</span> fps = driver->getFPS(); | ||
170 | |||
171 | <span class="keywordflow">if</span> (lastFPS != fps) | ||
172 | { | ||
173 | <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">"Irrlicht Engine - Quake 3 Map example ["</span>; | ||
174 | str += driver->getName(); | ||
175 | str += <span class="stringliteral">"] FPS:"</span>; | ||
176 | str += fps; | ||
177 | |||
178 | device->setWindowCaption(str.c_str()); | ||
179 | lastFPS = fps; | ||
180 | } | ||
181 | } | ||
182 | <span class="keywordflow">else</span> | ||
183 | device->yield(); | ||
184 | } | ||
185 | </pre></div><p>In the end, delete the Irrlicht device. </p> | ||
186 | <div class="fragment"><pre class="fragment"> device->drop(); | ||
187 | <span class="keywordflow">return</span> 0; | ||
188 | } | ||
189 | </pre></div><p>That's it. Compile and play around with the program. </p> | ||
190 | </div></div> | ||
191 | </div> | ||
192 | <div id="nav-path" class="navpath"> | ||
193 | <ul> | ||
194 | <!-- window showing the filter options --> | ||
195 | <div id="MSearchSelectWindow" | ||
196 | onmouseover="return searchBox.OnSearchSelectShow()" | ||
197 | onmouseout="return searchBox.OnSearchSelectHide()" | ||
198 | onkeydown="return searchBox.OnSearchSelectKey(event)"> | ||
199 | <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Defines</a></div> | ||
200 | |||
201 | <!-- iframe showing the search results (closed by default) --> | ||
202 | <div id="MSearchResultsWindow"> | ||
203 | <iframe src="javascript:void(0)" frameborder="0" | ||
204 | name="MSearchResults" id="MSearchResults"> | ||
205 | </iframe> | ||
206 | </div> | ||
207 | |||
208 | |||
209 | <li class="footer"> | ||
210 | <a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht | ||
211 | Engine</a> Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:41 for Irrlicht 3D Engine by | ||
212 | <a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li> | ||
213 | </ul> | ||
214 | </div> | ||
215 | |||
216 | |||
217 | </body> | ||
218 | </html> | ||