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