diff options
author | David Walter Seikel | 2013-01-13 17:24:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:24:39 +1000 |
commit | 393b5cd1dc438872af89d334ef6e5fcc59f27d47 (patch) | |
tree | 6a14521219942a08a1b95cb2f5a923a9edd60f63 /libraries/irrlicht-1.8/examples/02.Quake3Map/main.cpp | |
parent | Add a note about rasters suggested start up code. (diff) | |
download | SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.zip SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.gz SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.bz2 SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.xz |
Added Irrlicht 1.8, but without all the Windows binaries.
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/examples/02.Quake3Map/main.cpp | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/examples/02.Quake3Map/main.cpp b/libraries/irrlicht-1.8/examples/02.Quake3Map/main.cpp new file mode 100644 index 0000000..fc7461f --- /dev/null +++ b/libraries/irrlicht-1.8/examples/02.Quake3Map/main.cpp | |||
@@ -0,0 +1,206 @@ | |||
1 | /** Example 002 Quake3Map | ||
2 | |||
3 | This Tutorial shows how to load a Quake 3 map into the engine, create a | ||
4 | SceneNode for optimizing the speed of rendering, and how to create a user | ||
5 | controlled camera. | ||
6 | |||
7 | Please note that you should know the basics of the engine before starting this | ||
8 | tutorial. Just take a short look at the first tutorial, if you haven't done | ||
9 | this yet: http://irrlicht.sourceforge.net/tut001.html | ||
10 | |||
11 | Lets start like the HelloWorld example: We include the irrlicht header files | ||
12 | and an additional file to be able to ask the user for a driver type using the | ||
13 | console. | ||
14 | */ | ||
15 | #include <irrlicht.h> | ||
16 | #include <iostream> | ||
17 | |||
18 | /* | ||
19 | As already written in the HelloWorld example, in the Irrlicht Engine everything | ||
20 | can be found in the namespace 'irr'. To get rid of the irr:: in front of the | ||
21 | name of every class, we tell the compiler that we use that namespace from now | ||
22 | on, and we will not have to write that 'irr::'. There are 5 other sub | ||
23 | namespaces 'core', 'scene', 'video', 'io' and 'gui'. Unlike in the HelloWorld | ||
24 | example, we do not call 'using namespace' for these 5 other namespaces, because | ||
25 | in this way you will see what can be found in which namespace. But if you like, | ||
26 | you can also include the namespaces like in the previous example. | ||
27 | */ | ||
28 | using namespace irr; | ||
29 | |||
30 | /* | ||
31 | Again, to be able to use the Irrlicht.DLL file, we need to link with the | ||
32 | Irrlicht.lib. We could set this option in the project settings, but to make it | ||
33 | easy, we use a pragma comment lib: | ||
34 | */ | ||
35 | #ifdef _MSC_VER | ||
36 | #pragma comment(lib, "Irrlicht.lib") | ||
37 | #endif | ||
38 | |||
39 | /* | ||
40 | Ok, lets start. Again, we use the main() method as start, not the WinMain(). | ||
41 | */ | ||
42 | int main() | ||
43 | { | ||
44 | /* | ||
45 | Like in the HelloWorld example, we create an IrrlichtDevice with | ||
46 | createDevice(). The difference now is that we ask the user to select | ||
47 | which video driver to use. The Software device might be | ||
48 | too slow to draw a huge Quake 3 map, but just for the fun of it, we make | ||
49 | this decision possible, too. | ||
50 | Instead of copying this whole code into your app, you can simply include | ||
51 | driverChoice.h from Irrlicht's include directory. The function | ||
52 | driverChoiceConsole does exactly the same. | ||
53 | */ | ||
54 | |||
55 | // ask user for driver | ||
56 | |||
57 | video::E_DRIVER_TYPE driverType; | ||
58 | |||
59 | printf("Please select the driver you want for this example:\n"\ | ||
60 | " (a) OpenGL 1.5\n (b) Direct3D 9.0c\n (c) Direct3D 8.1\n"\ | ||
61 | " (d) Burning's Software Renderer\n (e) Software Renderer\n"\ | ||
62 | " (f) NullDevice\n (otherKey) exit\n\n"); | ||
63 | |||
64 | char i; | ||
65 | std::cin >> i; | ||
66 | |||
67 | switch(i) | ||
68 | { | ||
69 | case 'a': driverType = video::EDT_OPENGL; break; | ||
70 | case 'b': driverType = video::EDT_DIRECT3D9;break; | ||
71 | case 'c': driverType = video::EDT_DIRECT3D8;break; | ||
72 | case 'd': driverType = video::EDT_BURNINGSVIDEO;break; | ||
73 | case 'e': driverType = video::EDT_SOFTWARE; break; | ||
74 | case 'f': driverType = video::EDT_NULL; break; | ||
75 | default: return 1; | ||
76 | } | ||
77 | |||
78 | // create device and exit if creation failed | ||
79 | |||
80 | IrrlichtDevice *device = | ||
81 | createDevice(driverType, core::dimension2d<u32>(640, 480)); | ||
82 | |||
83 | if (device == 0) | ||
84 | return 1; // could not create selected driver. | ||
85 | |||
86 | /* | ||
87 | Get a pointer to the video driver and the SceneManager so that | ||
88 | we do not always have to call irr::IrrlichtDevice::getVideoDriver() and | ||
89 | irr::IrrlichtDevice::getSceneManager(). | ||
90 | */ | ||
91 | video::IVideoDriver* driver = device->getVideoDriver(); | ||
92 | scene::ISceneManager* smgr = device->getSceneManager(); | ||
93 | |||
94 | /* | ||
95 | To display the Quake 3 map, we first need to load it. Quake 3 maps | ||
96 | are packed into .pk3 files which are nothing else than .zip files. | ||
97 | So we add the .pk3 file to our irr::io::IFileSystem. After it was added, | ||
98 | we are able to read from the files in that archive as if they are | ||
99 | directly stored on the disk. | ||
100 | */ | ||
101 | device->getFileSystem()->addFileArchive("../../media/map-20kdm2.pk3"); | ||
102 | |||
103 | /* | ||
104 | Now we can load the mesh by calling | ||
105 | irr::scene::ISceneManager::getMesh(). We get a pointer returned to an | ||
106 | irr::scene::IAnimatedMesh. As you might know, Quake 3 maps are not | ||
107 | really animated, they are only a huge chunk of static geometry with | ||
108 | some materials attached. Hence the IAnimatedMesh consists of only one | ||
109 | frame, so we get the "first frame" of the "animation", which is our | ||
110 | quake level and create an Octree scene node with it, using | ||
111 | irr::scene::ISceneManager::addOctreeSceneNode(). | ||
112 | The Octree optimizes the scene a little bit, trying to draw only geometry | ||
113 | which is currently visible. An alternative to the Octree would be a | ||
114 | irr::scene::IMeshSceneNode, which would always draw the complete | ||
115 | geometry of the mesh, without optimization. Try it: Use | ||
116 | irr::scene::ISceneManager::addMeshSceneNode() instead of | ||
117 | addOctreeSceneNode() and compare the primitives drawn by the video | ||
118 | driver. (There is a irr::video::IVideoDriver::getPrimitiveCountDrawn() | ||
119 | method in the irr::video::IVideoDriver class). Note that this | ||
120 | optimization with the Octree is only useful when drawing huge meshes | ||
121 | consisting of lots of geometry. | ||
122 | */ | ||
123 | scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp"); | ||
124 | scene::ISceneNode* node = 0; | ||
125 | |||
126 | if (mesh) | ||
127 | node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024); | ||
128 | // node = smgr->addMeshSceneNode(mesh->getMesh(0)); | ||
129 | |||
130 | /* | ||
131 | Because the level was not modelled around the origin (0,0,0), we | ||
132 | translate the whole level a little bit. This is done on | ||
133 | irr::scene::ISceneNode level using the methods | ||
134 | irr::scene::ISceneNode::setPosition() (in this case), | ||
135 | irr::scene::ISceneNode::setRotation(), and | ||
136 | irr::scene::ISceneNode::setScale(). | ||
137 | */ | ||
138 | if (node) | ||
139 | node->setPosition(core::vector3df(-1300,-144,-1249)); | ||
140 | |||
141 | /* | ||
142 | Now we only need a camera to look at the Quake 3 map. | ||
143 | We want to create a user controlled camera. There are some | ||
144 | cameras available in the Irrlicht engine. For example the | ||
145 | MayaCamera which can be controlled like the camera in Maya: | ||
146 | Rotate with left mouse button pressed, Zoom with both buttons pressed, | ||
147 | translate with right mouse button pressed. This could be created with | ||
148 | irr::scene::ISceneManager::addCameraSceneNodeMaya(). But for this | ||
149 | example, we want to create a camera which behaves like the ones in | ||
150 | first person shooter games (FPS) and hence use | ||
151 | irr::scene::ISceneManager::addCameraSceneNodeFPS(). | ||
152 | */ | ||
153 | smgr->addCameraSceneNodeFPS(); | ||
154 | |||
155 | /* | ||
156 | The mouse cursor needs not be visible, so we hide it via the | ||
157 | irr::IrrlichtDevice::ICursorControl. | ||
158 | */ | ||
159 | device->getCursorControl()->setVisible(false); | ||
160 | |||
161 | /* | ||
162 | We have done everything, so lets draw it. We also write the current | ||
163 | frames per second and the primitives drawn into the caption of the | ||
164 | window. The test for irr::IrrlichtDevice::isWindowActive() is optional, | ||
165 | but prevents the engine to grab the mouse cursor after task switching | ||
166 | when other programs are active. The call to | ||
167 | irr::IrrlichtDevice::yield() will avoid the busy loop to eat up all CPU | ||
168 | cycles when the window is not active. | ||
169 | */ | ||
170 | int lastFPS = -1; | ||
171 | |||
172 | while(device->run()) | ||
173 | { | ||
174 | if (device->isWindowActive()) | ||
175 | { | ||
176 | driver->beginScene(true, true, video::SColor(255,200,200,200)); | ||
177 | smgr->drawAll(); | ||
178 | driver->endScene(); | ||
179 | |||
180 | int fps = driver->getFPS(); | ||
181 | |||
182 | if (lastFPS != fps) | ||
183 | { | ||
184 | core::stringw str = L"Irrlicht Engine - Quake 3 Map example ["; | ||
185 | str += driver->getName(); | ||
186 | str += "] FPS:"; | ||
187 | str += fps; | ||
188 | |||
189 | device->setWindowCaption(str.c_str()); | ||
190 | lastFPS = fps; | ||
191 | } | ||
192 | } | ||
193 | else | ||
194 | device->yield(); | ||
195 | } | ||
196 | |||
197 | /* | ||
198 | In the end, delete the Irrlicht device. | ||
199 | */ | ||
200 | device->drop(); | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | /* | ||
205 | That's it. Compile and play around with the program. | ||
206 | **/ | ||