aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/doc/html/example018.html
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/doc/html/example018.html')
-rw-r--r--src/others/irrlicht-1.8.1/doc/html/example018.html316
1 files changed, 316 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/doc/html/example018.html b/src/others/irrlicht-1.8.1/doc/html/example018.html
new file mode 100644
index 0000000..1992110
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/doc/html/example018.html
@@ -0,0 +1,316 @@
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 18: Splitscreen</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">
69var 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('example018.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 18: Splitscreen </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="018shot.jpg" alt="018shot.jpg"/>
93</div>
94 <p>A tutorial by Max Winkel.</p>
95<p>In this tutorial we'll learn how to use splitscreen (e.g. for racing-games) with Irrlicht. We'll create a viewport divided into 4 parts, with 3 fixed cameras and one user-controlled.</p>
96<p>Ok, let's start with the headers (I think there's nothing to say about it) </p>
97<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>
98<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>
99
100<span class="preprocessor">#ifdef _MSC_VER</span>
101<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
102<span class="preprocessor"></span><span class="preprocessor">#endif</span>
103<span class="preprocessor"></span>
104<span class="comment">//Namespaces for the engine</span>
105<span class="keyword">using namespace </span>irr;
106<span class="keyword">using namespace </span>core;
107<span class="keyword">using namespace </span>video;
108<span class="keyword">using namespace </span>scene;
109</pre></div><p>Now we'll define the resolution in a constant for use in initializing the device and setting up the viewport. In addition we set up a global variable saying splitscreen is active or not. </p>
110<div class="fragment"><pre class="fragment"><span class="comment">//Resolution</span>
111<span class="keyword">const</span> <span class="keywordtype">int</span> ResX=800;
112<span class="keyword">const</span> <span class="keywordtype">int</span> ResY=600;
113<span class="keyword">const</span> <span class="keywordtype">bool</span> fullScreen=<span class="keyword">false</span>;
114
115<span class="comment">//Use SplitScreen?</span>
116<span class="keywordtype">bool</span> SplitScreen=<span class="keyword">true</span>;
117</pre></div><p>Now we need four pointers to our cameras which are created later: </p>
118<div class="fragment"><pre class="fragment"><span class="comment">//cameras</span>
119ICameraSceneNode *camera[4]={0,0,0,0};
120</pre></div><p>In our event-receiver we switch the SplitScreen-variable, whenever the user press the S-key. All other events are sent to the FPS camera. </p>
121<div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver
122{
123 <span class="keyword">public</span>:
124 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
125 {
126 <span class="comment">//Key S enables/disables SplitScreen</span>
127 <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> &amp;&amp;
128 event.KeyInput.Key == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ae52bafc112fc6c52f6b49cea42fa246e">KEY_KEY_S</a> &amp;&amp; event.KeyInput.PressedDown)
129 {
130 SplitScreen = !SplitScreen;
131 <span class="keywordflow">return</span> <span class="keyword">true</span>;
132 }
133 <span class="comment">//Send all other events to camera4</span>
134 <span class="keywordflow">if</span> (camera[3])
135 <span class="keywordflow">return</span> camera[3]-&gt;OnEvent(event);
136 <span class="keywordflow">return</span> <span class="keyword">false</span>;
137 }
138};
139</pre></div><p>Ok, now the main-function: First, we initialize the device, get the SourceManager and VideoDriver, load an animated mesh from .md2 and a map from .pk3. Because that's old stuff, I won't explain every step. Just take care of the maps position. </p>
140<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
141{
142 <span class="comment">// ask user for driver</span>
143 <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=driverChoiceConsole();
144 <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>)
145 <span class="keywordflow">return</span> 1;
146
147 <span class="comment">//Instance of the EventReceiver</span>
148 MyEventReceiver receiver;
149
150 <span class="comment">//Initialise the engine</span>
151 IrrlichtDevice *device = <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,
152 <a class="code" href="namespaceirr_1_1core.html#ad2e562e3219072e2f7fc7c2bba0ef0cb" title="Typedef for an unsigned integer dimension.">dimension2du</a>(ResX,ResY), 32, fullScreen,
153 <span class="keyword">false</span>, <span class="keyword">false</span>, &amp;receiver);
154 <span class="keywordflow">if</span> (!device)
155 <span class="keywordflow">return</span> 1;
156
157 ISceneManager *smgr = device-&gt;getSceneManager();
158 IVideoDriver *driver = device-&gt;getVideoDriver();
159
160 <span class="comment">//Load model</span>
161 IAnimatedMesh *model = smgr-&gt;getMesh(<span class="stringliteral">&quot;../../media/sydney.md2&quot;</span>);
162 <span class="keywordflow">if</span> (!model)
163 <span class="keywordflow">return</span> 1;
164 IAnimatedMeshSceneNode *model_node = smgr-&gt;addAnimatedMeshSceneNode(model);
165 <span class="comment">//Load texture</span>
166 <span class="keywordflow">if</span> (model_node)
167 {
168 ITexture *texture = driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/sydney.bmp&quot;</span>);
169 model_node-&gt;setMaterialTexture(0,texture);
170 model_node-&gt;setMD2Animation(<a class="code" href="namespaceirr_1_1scene.html#a08d4a84966e1d2886d0d57e4acbb4f19af240ef944e6e257ec369f87053c756e8">scene::EMAT_RUN</a>);
171 <span class="comment">//Disable lighting (we&#39;ve got no light)</span>
172 model_node-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">EMF_LIGHTING</a>,<span class="keyword">false</span>);
173 }
174
175 <span class="comment">//Load map</span>
176 device-&gt;getFileSystem()-&gt;addFileArchive(<span class="stringliteral">&quot;../../media/map-20kdm2.pk3&quot;</span>);
177 IAnimatedMesh *map = smgr-&gt;getMesh(<span class="stringliteral">&quot;20kdm2.bsp&quot;</span>);
178 <span class="keywordflow">if</span> (map)
179 {
180 ISceneNode *map_node = smgr-&gt;addOctreeSceneNode(map-&gt;getMesh(0));
181 <span class="comment">//Set position</span>
182 map_node-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(-850,-220,-850));
183 }
184</pre></div><p>Now we create our four cameras. One is looking at the model from the front, one from the top and one from the side. In addition there's a FPS-camera which can be controlled by the user. </p>
185<div class="fragment"><pre class="fragment"> <span class="comment">// Create 3 fixed and one user-controlled cameras</span>
186 <span class="comment">//Front</span>
187 camera[0] = smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(50,0,0), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,0));
188 <span class="comment">//Top</span>
189 camera[1] = smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,50,0), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,0));
190 <span class="comment">//Left</span>
191 camera[2] = smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,50), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,0));
192 <span class="comment">//User-controlled</span>
193 camera[3] = smgr-&gt;addCameraSceneNodeFPS();
194 <span class="comment">// don&#39;t start at sydney&#39;s position</span>
195 <span class="keywordflow">if</span> (camera[3])
196 camera[3]-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(-50,0,-50));
197</pre></div><p>Create a variable for counting the fps and hide the mouse: </p>
198<div class="fragment"><pre class="fragment"> <span class="comment">//Hide mouse</span>
199 device-&gt;getCursorControl()-&gt;setVisible(<span class="keyword">false</span>);
200 <span class="comment">//We want to count the fps</span>
201 <span class="keywordtype">int</span> lastFPS = -1;
202</pre></div><p>There wasn't much new stuff - till now! Only by defining four cameras, the game won't be splitscreen. To do this you need several steps:</p>
203<ul>
204<li>Set the viewport to the whole screen</li>
205<li>Begin a new scene (Clear screen)</li>
206</ul>
207<ul>
208<li>The following 3 steps are repeated for every viewport in the splitscreen<ul>
209<li>Set the viewport to the area you wish</li>
210<li>Activate the camera which should be "linked" with the viewport</li>
211<li>Render all objects</li>
212</ul>
213</li>
214</ul>
215<ul>
216<li>If you have a GUI:<ul>
217<li>Set the viewport the whole screen</li>
218<li>Display the GUI</li>
219</ul>
220</li>
221<li>End scene</li>
222</ul>
223<p>Sounds a little complicated, but you'll see it isn't: </p>
224<div class="fragment"><pre class="fragment"> <span class="keywordflow">while</span>(device-&gt;run())
225 {
226 <span class="comment">//Set the viewpoint to the whole screen and begin scene</span>
227 driver-&gt;setViewPort(rect&lt;s32&gt;(0,0,ResX,ResY));
228 driver-&gt;beginScene(<span class="keyword">true</span>,<span class="keyword">true</span>,SColor(255,100,100,100));
229 <span class="comment">//If SplitScreen is used</span>
230 <span class="keywordflow">if</span> (SplitScreen)
231 {
232 <span class="comment">//Activate camera1</span>
233 smgr-&gt;setActiveCamera(camera[0]);
234 <span class="comment">//Set viewpoint to the first quarter (left top)</span>
235 driver-&gt;setViewPort(rect&lt;s32&gt;(0,0,ResX/2,ResY/2));
236 <span class="comment">//Draw scene</span>
237 smgr-&gt;drawAll();
238 <span class="comment">//Activate camera2</span>
239 smgr-&gt;setActiveCamera(camera[1]);
240 <span class="comment">//Set viewpoint to the second quarter (right top)</span>
241 driver-&gt;setViewPort(rect&lt;s32&gt;(ResX/2,0,ResX,ResY/2));
242 <span class="comment">//Draw scene</span>
243 smgr-&gt;drawAll();
244 <span class="comment">//Activate camera3</span>
245 smgr-&gt;setActiveCamera(camera[2]);
246 <span class="comment">//Set viewpoint to the third quarter (left bottom)</span>
247 driver-&gt;setViewPort(rect&lt;s32&gt;(0,ResY/2,ResX/2,ResY));
248 <span class="comment">//Draw scene</span>
249 smgr-&gt;drawAll();
250 <span class="comment">//Set viewport the last quarter (right bottom)</span>
251 driver-&gt;setViewPort(rect&lt;s32&gt;(ResX/2,ResY/2,ResX,ResY));
252 }
253 <span class="comment">//Activate camera4</span>
254 smgr-&gt;setActiveCamera(camera[3]);
255 <span class="comment">//Draw scene</span>
256 smgr-&gt;drawAll();
257 driver-&gt;endScene();
258</pre></div><p>As you can probably see, the image is rendered for every viewport separately. That means, that you'll loose much performance. Ok, if you're asking "How do I have to set the viewport
259 to get this or that screen?", don't panic. It's really easy: In the rect-function you define 4 coordinates:</p>
260<ul>
261<li>X-coordinate of the corner left top</li>
262<li>Y-coordinate of the corner left top</li>
263<li>X-coordinate of the corner right bottom</li>
264<li>Y-coordinate of the corner right bottom</li>
265</ul>
266<p>That means, if you want to split the screen into 2 viewports you would give the following coordinates:</p>
267<ul>
268<li>1st viewport: 0,0,ResX/2,ResY</li>
269<li>2nd viewport: ResX/2,0,ResX,ResY</li>
270</ul>
271<p>If you didn't fully understand, just play around with the example to check out what happens.</p>
272<p>Now we just view the current fps and shut down the engine, when the user wants to: </p>
273<div class="fragment"><pre class="fragment"> <span class="comment">//Get and show fps</span>
274 <span class="keywordflow">if</span> (driver-&gt;getFPS() != lastFPS)
275 {
276 lastFPS = driver-&gt;getFPS();
277 <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> tmp = L<span class="stringliteral">&quot;Irrlicht SplitScreen-Example (FPS: &quot;</span>;
278 tmp += lastFPS;
279 tmp += <span class="stringliteral">&quot;)&quot;</span>;
280 device-&gt;setWindowCaption(tmp.c_str());
281 }
282 }
283 <span class="comment">//Delete device</span>
284 device-&gt;drop();
285 <span class="keywordflow">return</span> 0;
286}
287</pre></div><p>That's it! Just compile and play around with the program. Note: With the S-Key you can switch between using splitscreen and not. </p>
288</div></div>
289</div>
290 <div id="nav-path" class="navpath">
291 <ul>
292<!-- window showing the filter options -->
293<div id="MSearchSelectWindow"
294 onmouseover="return searchBox.OnSearchSelectShow()"
295 onmouseout="return searchBox.OnSearchSelectHide()"
296 onkeydown="return searchBox.OnSearchSelectKey(event)">
297<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>
298
299<!-- iframe showing the search results (closed by default) -->
300<div id="MSearchResultsWindow">
301<iframe src="javascript:void(0)" frameborder="0"
302 name="MSearchResults" id="MSearchResults">
303</iframe>
304</div>
305
306
307 <li class="footer">
308<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
309Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:41 for Irrlicht 3D Engine by
310<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
311 </ul>
312 </div>
313
314
315</body>
316</html>