mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-10 17:53:53 +01:00
210 lines
30 KiB
HTML
210 lines
30 KiB
HTML
|
<!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 23: SMeshBufferHandling</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 23: SMeshBufferHandling </div> </div>
|
||
|
</div><!--header-->
|
||
|
<div class="contents">
|
||
|
<div class="textblock"><div class="image">
|
||
|
<img src="../../media/023shot.jpg" alt="023shot.jpg"/>
|
||
|
</div>
|
||
|
<p>A tutorial by geoff.</p>
|
||
|
<p>In this tutorial we'll learn how to create custom meshes and deal with them with Irrlicht. We'll create an interesting heightmap with some lighting effects. With keys 1,2,3 you can choose a different mesh layout, which is put into the mesh buffers as desired. All positions, normals, etc. are updated accordingly.</p>
|
||
|
<p>Ok, let's start with the headers (I think there's nothing to say about it) </p><div class="fragment"><div class="line"><span class="preprocessor">#include <irrlicht.h></span></div><div class="line"><span class="preprocessor">#include "driverChoice.h"</span></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, "Irrlicht.lib")</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="comment">//Namespaces for the engine</span></div><div class="line"><span class="keyword">using namespace </span>irr;</div><div class="line"><span class="keyword">using namespace </span>video;</div><div class="line"><span class="keyword">using namespace </span>core;</div><div class="line"><span class="keyword">using namespace </span>scene;</div><div class="line"><span class="keyword">using namespace </span>io;</div><div class="line"><span class="keyword">using namespace </span>gui;</div></div><!-- fragment --><p> This is the type of the functions which work out the colour.</p><div class="fragment"><div class="line"><span class="keyword">typedef</span> SColor colour_func(f32 x, f32 y, f32 z);</div></div><!-- fragment --><p> Here comes a set of functions which can be used for coloring the nodes while creating the mesh.</p><div class="fragment"><div class="line"><span class="comment">// Greyscale, based on the height.</span></div><div class="line">SColor grey(f32, f32, f32 z)</div><div class="line">{</div><div class="line"> u32 n = (u32)(255.f * z);</div><div class="line"> <span class="keywordflow">return</span> SColor(255, n, n, n);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// Interpolation between blue and white, with red added in one</span></div><div class="line"><span class="comment">// direction and green in the other.</span></div><div class="line">SColor yellow(f32 x, f32 y, f32)</div><div class="line">{</div><div class="line"> <span class="keywordflow">return</span> SColor(255, 128 + (u32)(127.f * x), 128 + (u32)(127.f * y), 255);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// Pure white.</span></div><div class="line">SColor white(f32, f32, f32) { <span class="keywordflow">return</span> SColor(255, 255, 255, 255); }</div></div><!-- fragment --><p> The type of the functions which generate the heightmap. x and y range between -0.5 and 0.5, and s is the scale of the heightmap.</p><div class="fragment"><div class="line"><span class="keyword">typedef</span> f32 generate_func(s16 x, s16 y, f32 s);</div><div class="line"></div><div class="line"><span class="comment">// An interesting sample function :-)</span></div><div class="line">f32 eggbox(s16 x, s16 y, f32 s)</div><div class="line">{</div><div class="line"> <span class="keyword">const</span> f32 r = 4.f*sqrtf((f32)(x*x + y*y))/s;</div><div class="line"> <span class="keyword">const</span> f32 z = expf(-r * 2) * (cosf(0.2f * x) + cosf(0.2f * y));</div><div class="line"> <span class="keywordflow">return</span> 0.25f+0.25f*z;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// A rather dumb sine function :-/</span></div><div class="line">f32 moresine(s16 x, s16 y, f32 s)</div><div class="line">{</div><div class="line"> <span class="keyword">const</span> f32 xx=0.3f*(f32)x/s;</div><div class="line"> <span class="keyword">const</span> f32 yy=12*y/s;</div><div class="line"> <span class="keyword">const</span> f32 z = sinf(xx*xx+yy)*sinf(xx+yy*yy);</div><div class="line"> <span class="keywordflow">return</span> 0.25f + 0.25f * z;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// A simple function</span></div><div class="line">f32 justexp(s16 x, s16 y, f32 s)</div><div class="line">{</div><div class="line"> <span class="keyword">const</span> f32 xx=6*x/s;</div><div
|
||
|
<p>s is a scaling factor, which is necessary if the height units are different from the coordinate units; for example, if your map has heights in metres and the coordinates are in units of a kilometer.</p><div class="fragment"><div class="line"> vector3df getnormal(u16 x, u16 y, f32 s)<span class="keyword"> const</span></div><div class="line"><span class="keyword"> </span>{</div><div class="line"> <span class="keyword">const</span> f32 zc = <span class="keyword">get</span>(x, y);</div><div class="line"> f32 zl, zr, zu, zd;</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (x == 0)</div><div class="line"> {</div><div class="line"> zr = <span class="keyword">get</span>(x + 1, y);</div><div class="line"> zl = zc + zc - zr;</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (x == Width - 1)</div><div class="line"> {</div><div class="line"> zl = <span class="keyword">get</span>(x - 1, y);</div><div class="line"> zr = zc + zc - zl;</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> {</div><div class="line"> zr = <span class="keyword">get</span>(x + 1, y);</div><div class="line"> zl = <span class="keyword">get</span>(x - 1, y);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (y == 0)</div><div class="line"> {</div><div class="line"> zd = <span class="keyword">get</span>(x, y + 1);</div><div class="line"> zu = zc + zc - zd;</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (y == Height - 1)</div><div class="line"> {</div><div class="line"> zu = <span class="keyword">get</span>(x, y - 1);</div><div class="line"> zd = zc + zc - zu;</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> {</div><div class="line"> zd = <span class="keyword">get</span>(x, y + 1);</div><div class="line"> zu = <span class="keyword">get</span>(x, y - 1);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> vector3df(s * 2 * (zl - zr), 4, s * 2 * (zd - zu)).normalize();</div><div class="line"> }</div><div class="line">};</div></div><!-- fragment --><p> A class which generates a mesh from a heightmap.</p><div class="fragment"><div class="line"><span class="keyword">class </span>TMesh</div><div class="line">{</div><div class="line"><span class="keyword">private</span>:</div><div class="line"> u16 Width;</div><div class="line"> u16 Height;</div><div class="line"> f32 Scale;</div><div class="line"><span class="keyword">public</span>:</div><div class="line"> SMesh* Mesh;</div><div class="line"></div><div class="line"> TMesh() : Mesh(0), Width(0), Height(0), Scale(1.f)</div><div class="line"> {</div><div class="line"> Mesh = <span class="keyword">new</span> SMesh();</div><div class="line"> }</div><div class="line"></div><div class="line"> ~TMesh()</div><div class="line"> {</div><div class="line"> Mesh->drop();</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// Unless the heightmap is small, it won't all fit into a single</span></div><div class="line"> <span class="comment">// SMeshBuffer. This function chops it into pieces and generates a</span></div><div class="line"> <span class="comment">// buffer from each one.</span></div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> init(<span class="keyword">const</span> HeightMap &hm, f32 scale, colour_func cf, IVideoDriver *driver)</div><div class="line"> {</div><div clas
|
||
|
</div></div><!-- contents -->
|
||
|
<!-- HTML footer for doxygen 1.8.13-->
|
||
|
<!-- start footer part -->
|
||
|
<p> </p>
|
||
|
</body>
|
||
|
</html>
|