irrlicht/examples/09.Meshviewer/tutorial.html

214 lines
80 KiB
HTML
Raw Normal View History

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Tutorial 9: Mesh Viewer</title>
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- 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.
Feel free to improve :)
-->
<style>
body, table, div, p, dl {
font: 400 14px/22px;
}
body {
background-color: #F0F0F0;
color: black;
margin-left: 5%;
margin-right: 5%;
}
p.reference, p.definition {
font: 400 14px/22px;
}
.title {
font: 400 14px/28px;
font-size: 150%;
font-weight: bold;
margin: 10px 2px;
}
h1, h2, h3, h4, h5, h6 {
-webkit-transition: text-shadow 0.5s linear;
-moz-transition: text-shadow 0.5s linear;
-ms-transition: text-shadow 0.5s linear;
-o-transition: text-shadow 0.5s linear;
transition: text-shadow 0.5s linear;
margin-right: 15px;
}
caption {
font-weight: bold;
}
h3.version {
font-size: 90%;
text-align: center;
}
a {
color: #3D578C;
font-weight: normal;
text-decoration: none;
}
.contents a:visited {
color: #4665A2;
}
a:hover {
text-decoration: underline;
}
a.el {
font-weight: bold;
}
a.code, a.code:visited, a.line, a.line:visited {
color: #4665A2;
}
a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited {
color: #4665A2;
}
pre.fragment {
border: 1px solid #C4CFE5;
background-color: #FBFCFD;
padding: 4px 6px;
margin: 4px 8px 4px 2px;
overflow: auto;
word-wrap: break-word;
font-size: 9pt;
line-height: 125%;
font-family: monospace, fixed;
font-size: 105%;
}
div.fragment {
padding: 0px;
margin: 4px 8px 4px 2px;
background-color: #FBFCFD;
border: 1px solid #C4CFE5;
}
div.line {
font-family: monospace, fixed;
font-size: 13px;
min-height: 13px;
line-height: 1.0;
text-wrap: unrestricted;
white-space: -moz-pre-wrap; /* Moz */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: pre-wrap; /* CSS3 */
word-wrap: break-word; /* IE 5.5+ */
text-indent: -53px;
padding-left: 53px;
padding-bottom: 0px;
margin: 0px;
-webkit-transition-property: background-color, box-shadow;
-webkit-transition-duration: 0.5s;
-moz-transition-property: background-color, box-shadow;
-moz-transition-duration: 0.5s;
-ms-transition-property: background-color, box-shadow;
-ms-transition-duration: 0.5s;
-o-transition-property: background-color, box-shadow;
-o-transition-duration: 0.5s;
transition-property: background-color, box-shadow;
transition-duration: 0.5s;
}
div.contents {
margin-top: 10px;
margin-left: 12px;
margin-right: 8px;
}
div.center {
text-align: center;
margin-top: 0px;
margin-bottom: 0px;
padding: 0px;
}
div.center img {
border: 0px;
}
span.keyword {
color: #008000
}
span.keywordtype {
color: #604020
}
span.keywordflow {
color: #e08000
}
span.comment {
color: #800000
}
span.preprocessor {
color: #806020
}
span.stringliteral {
color: #002080
}
span.charliteral {
color: #008080
}
blockquote {
background-color: #F7F8FB;
border-left: 2px solid #9CAFD4;
margin: 0 24px 0 4px;
padding: 0 12px 0 16px;
}
hr {
height: 0px;
border: none;
border-top: 1px solid #4A6AAA;
}
address {
font-style: normal;
color: #2A3D61;
}
div.header {
background-image:url('nav_h.png');
background-repeat:repeat-x;
background-color: #F9FAFC;
margin: 0px;
border-bottom: 1px solid #C4CFE5;
}
div.headertitle {
padding: 5px 5px 5px 10px;
}
.image {
text-align: center;
}
.caption {
font-weight: bold;
}
div.zoom {
border: 1px solid #90A5CE;
}
tr.heading h2 {
margin-top: 12px;
margin-bottom: 4px;
}
</style>
</head>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<!--END TITLEAREA-->
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Tutorial 9: Mesh Viewer </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><div class="image">
<img src="../../media/009shot.jpg" alt="009shot.jpg"/>
</div>
<p>This tutorial show how to create a more complex application with the engine. We construct a simple mesh viewer using the user interface API and the scene management of Irrlicht. The tutorial show how to create and use Buttons, Windows, Toolbars, Menus, ComboBoxes, Tabcontrols, Editboxes, Images, MessageBoxes, SkyBoxes, and how to parse XML files with the integrated XML reader of the engine.</p>
<p>We start like in most other tutorials: Include all necessary header files, add a comment to let the engine be linked with the right .lib file in Visual Studio, and declare some global variables. We also add two 'using namespace' statements, so we do not need to write the whole names of all classes. In this tutorial, we use a lot stuff from the gui namespace. </p><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;irrlicht.h&gt;</span></div><div class="line"><span class="preprocessor">#include &quot;driverChoice.h&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span>irr;</div><div class="line"><span class="keyword">using namespace </span>gui;</div><div class="line"></div><div class="line"><span class="preprocessor">#ifdef _MSC_VER</span></div><div class="line"><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span></div><div class="line"><span class="preprocessor">#endif</span></div></div><!-- fragment --><p> Some global variables used later on </p><div class="fragment"><div class="line">IrrlichtDevice *Device = 0;</div><div class="line">core::stringc StartUpModelFile;</div><div class="line">core::stringw MessageText;</div><div class="line">core::stringw Caption;</div><div class="line">scene::ISceneNode* Model = 0;</div><div class="line">scene::ISceneNode* SkyBox = 0;</div><div class="line"><span class="keywordtype">bool</span> Octree=<span class="keyword">false</span>;</div><div class="line"><span class="keywordtype">bool</span> UseLight=<span class="keyword">false</span>;</div><div class="line"></div><div class="line">scene::ICameraSceneNode* Camera[2] = {0, 0};</div><div class="line"></div><div class="line"><span class="comment">// Values used to identify individual GUI elements</span></div><div class="line"><span class="keyword">enum</span></div><div class="line">{</div><div class="line"> GUI_ID_DIALOG_ROOT_WINDOW = 0x10000,</div><div class="line"></div><div class="line"> GUI_ID_X_SCALE,</div><div class="line"> GUI_ID_Y_SCALE,</div><div class="line"> GUI_ID_Z_SCALE,</div><div class="line"></div><div class="line"> GUI_ID_OPEN_MODEL,</div><div class="line"> GUI_ID_SET_MODEL_ARCHIVE,</div><div class="line"> GUI_ID_LOAD_AS_OCTREE,</div><div class="line"></div><div class="line"> GUI_ID_SKY_BOX_VISIBLE,</div><div class="line"> GUI_ID_TOGGLE_DEBUG_INFO,</div><div class="line"></div><div class="line"> GUI_ID_DEBUG_OFF,</div><div class="line"> GUI_ID_DEBUG_BOUNDING_BOX,</div><div class="line"> GUI_ID_DEBUG_NORMALS,</div><div class="line"> GUI_ID_DEBUG_SKELETON,</div><div class="line"> GUI_ID_DEBUG_WIRE_OVERLAY,</div><div class="line"> GUI_ID_DEBUG_HALF_TRANSPARENT,</div><div class="line"> GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES,</div><div class="line"> GUI_ID_DEBUG_ALL,</div><div class="line"></div><div class="line"> GUI_ID_MODEL_MATERIAL_SOLID,</div><div class="line"> GUI_ID_MODEL_MATERIAL_TRANSPARENT,</div><div class="line"> GUI_ID_MODEL_MATERIAL_REFLECTION,</div><div class="line"></div><div class="line"> GUI_ID_CAMERA_MAYA,</div><div class="line"> GUI_ID_CAMERA_FIRST_PERSON,</div><div class="line"></div><div class="line"> GUI_ID_POSITION_TEXT,</div><div class="line"></div><div class="line"> GUI_ID_ABOUT,</div><div class="line"> GUI_ID_QUIT,</div><div class="line"></div><div class="line"> GUI_ID_TEXTUREFILTER,</div><div class="line"> GUI_ID_SKIN_TRANSPARENCY,</div><div class="line"> GUI_ID_SKIN_ANIMATION_FPS,</div><div class="line"></div><div class="line"> GUI_ID_BUTTON_SET_SCALE,</div><div class="line"> GUI_ID_BUTTON_SCALE_MUL10,</div><div class="line"> GUI_ID_BUTTON_SCALE_DIV10,</div><div class="line"> GUI_ID_BUTTON_OPEN_MODEL,</div><div class="line"> GUI_ID_BUTTON_SHOW_ABOUT,</div><div class="line"> GUI_ID_BUTTON_SHOW_TOOLBOX,</div><div class="line"> GUI_ID_BUTTON_SELECT_ARCHIVE,</div><div class="line"></div><div class="line"> GUI_ID_ANIMATION_INFO,</div><div class="line"></div><div class="line"> <span class=
<pre class="fragment"> &lt;?xml version="1.0"?&gt;
&lt;config&gt;
&lt;startUpModel file="some filename" /&gt;
&lt;messageText caption="Irrlicht Engine Mesh Viewer"&gt;
Hello!
&lt;/messageText&gt;
&lt;/config&gt;</pre><p>We need the data stored in there to be written into the global variables StartUpModelFile, MessageText and Caption. This is now done using the Irrlicht Engine integrated XML parser: </p><div class="fragment"><div class="line"><span class="comment">// read configuration from xml file</span></div><div class="line"></div><div class="line">io::IXMLReader* xml = Device-&gt;getFileSystem()-&gt;createXMLReader( L<span class="stringliteral">&quot;config.xml&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordflow">while</span>(xml &amp;&amp; xml-&gt;read())</div><div class="line">{</div><div class="line"> <span class="keywordflow">switch</span>(xml-&gt;getNodeType())</div><div class="line"> {</div><div class="line"> <span class="keywordflow">case</span> io::EXN_TEXT:</div><div class="line"> <span class="comment">// in this xml file, the only text which occurs is the</span></div><div class="line"> <span class="comment">// messageText</span></div><div class="line"> MessageText = xml-&gt;getNodeData();</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> io::EXN_ELEMENT:</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (core::stringw(<span class="stringliteral">&quot;startUpModel&quot;</span>) == xml-&gt;getNodeName())</div><div class="line"> StartUpModelFile = xml-&gt;getAttributeValue(L<span class="stringliteral">&quot;file&quot;</span>);</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> <span class="keywordflow">if</span> (core::stringw(<span class="stringliteral">&quot;messageText&quot;</span>) == xml-&gt;getNodeName())</div><div class="line"> Caption = xml-&gt;getAttributeValue(L<span class="stringliteral">&quot;caption&quot;</span>);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">default</span>:</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> (xml)</div><div class="line"> xml-&gt;drop(); <span class="comment">// don&#39;t forget to delete the xml reader</span></div><div class="line"></div><div class="line"><span class="keywordflow">if</span> (argc &gt; 1)</div><div class="line"> StartUpModelFile = argv[1];</div></div><!-- fragment --><p> That wasn't difficult. Now we'll set a nicer font and create the Menu. It is possible to create submenus for every menu item. The call menu-&gt;addItem(L"File", -1, true, true); for example adds a new menu Item with the name "File" and the id -1. The following parameter says that the menu item should be enabled, and the last one says, that there should be a submenu. The submenu can now be accessed with menu-&gt;getSubMenu(0), because the "File" entry is the menu item with index 0. </p><div class="fragment"><div class="line"><span class="comment">// set a nicer font</span></div><div class="line"></div><div class="line">IGUISkin* skin = env-&gt;getSkin();</div><div class="line">IGUIFont* font = env-&gt;getFont(<span class="stringliteral">&quot;fonthaettenschweiler.bmp&quot;</span>);</div><div class="line"><span class="keywordflow">if</span> (font)</div><div class="line"> skin-&gt;setFont(font);</div><div class="line"></div><div class="line"><span class="comment">// create menu</span></div><div class="line">gui::IGUIContextMenu* menu = env-&gt;addMenu();</div><div class="line">menu-&gt;addItem(L<span class="stringliteral">&quot;File&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);</div><div class="line">menu-&gt;addItem(L<span class="stringliteral">&quot;View&quot;</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>);</div><div class="line">menu
<!-- HTML footer for doxygen 1.8.13-->
<!-- start footer part -->
<p>&nbsp;</p>
</body>
</html>