diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/examples/15.LoadIrrFile/main.cpp | 346 |
1 files changed, 173 insertions, 173 deletions
diff --git a/libraries/irrlicht-1.8/examples/15.LoadIrrFile/main.cpp b/libraries/irrlicht-1.8/examples/15.LoadIrrFile/main.cpp index 42327cd..4abffb3 100644 --- a/libraries/irrlicht-1.8/examples/15.LoadIrrFile/main.cpp +++ b/libraries/irrlicht-1.8/examples/15.LoadIrrFile/main.cpp | |||
@@ -1,173 +1,173 @@ | |||
1 | /** Example 015 Loading Scenes from .irr Files | 1 | /** Example 015 Loading Scenes from .irr Files |
2 | 2 | ||
3 | Since version 1.1, Irrlicht is able to save and load | 3 | Since version 1.1, Irrlicht is able to save and load |
4 | the full scene graph into an .irr file, an xml based | 4 | the full scene graph into an .irr file, an xml based |
5 | format. There is an editor available to edit | 5 | format. There is an editor available to edit |
6 | those files, named irrEdit (http://www.ambiera.com/irredit) | 6 | those files, named irrEdit (http://www.ambiera.com/irredit) |
7 | which can also be used as world and particle editor. | 7 | which can also be used as world and particle editor. |
8 | This tutorial shows how to use .irr files. | 8 | This tutorial shows how to use .irr files. |
9 | 9 | ||
10 | Lets start: Create an Irrlicht device and setup the window. | 10 | Lets start: Create an Irrlicht device and setup the window. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <irrlicht.h> | 13 | #include <irrlicht.h> |
14 | #include "driverChoice.h" | 14 | #include "driverChoice.h" |
15 | 15 | ||
16 | using namespace irr; | 16 | using namespace irr; |
17 | 17 | ||
18 | #ifdef _MSC_VER | 18 | #ifdef _MSC_VER |
19 | #pragma comment(lib, "Irrlicht.lib") | 19 | #pragma comment(lib, "Irrlicht.lib") |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | int main(int argc, char** argv) | 22 | int main(int argc, char** argv) |
23 | { | 23 | { |
24 | // ask user for driver | 24 | // ask user for driver |
25 | video::E_DRIVER_TYPE driverType=driverChoiceConsole(); | 25 | video::E_DRIVER_TYPE driverType=driverChoiceConsole(); |
26 | if (driverType==video::EDT_COUNT) | 26 | if (driverType==video::EDT_COUNT) |
27 | return 1; | 27 | return 1; |
28 | 28 | ||
29 | // create device and exit if creation failed | 29 | // create device and exit if creation failed |
30 | 30 | ||
31 | IrrlichtDevice* device = | 31 | IrrlichtDevice* device = |
32 | createDevice(driverType, core::dimension2d<u32>(640, 480)); | 32 | createDevice(driverType, core::dimension2d<u32>(640, 480)); |
33 | 33 | ||
34 | if (device == 0) | 34 | if (device == 0) |
35 | return 1; // could not create selected driver. | 35 | return 1; // could not create selected driver. |
36 | 36 | ||
37 | device->setWindowCaption(L"Load .irr file example"); | 37 | device->setWindowCaption(L"Load .irr file example"); |
38 | 38 | ||
39 | video::IVideoDriver* driver = device->getVideoDriver(); | 39 | video::IVideoDriver* driver = device->getVideoDriver(); |
40 | scene::ISceneManager* smgr = device->getSceneManager(); | 40 | scene::ISceneManager* smgr = device->getSceneManager(); |
41 | 41 | ||
42 | /* | 42 | /* |
43 | Now load our .irr file. | 43 | Now load our .irr file. |
44 | .irr files can store the whole scene graph including animators, | 44 | .irr files can store the whole scene graph including animators, |
45 | materials and particle systems. And there is also the possibility to | 45 | materials and particle systems. And there is also the possibility to |
46 | store arbitrary user data for every scene node in that file. To keep | 46 | store arbitrary user data for every scene node in that file. To keep |
47 | this example simple, we are simply loading the scene here. See the | 47 | this example simple, we are simply loading the scene here. See the |
48 | documentation at ISceneManager::loadScene and ISceneManager::saveScene | 48 | documentation at ISceneManager::loadScene and ISceneManager::saveScene |
49 | for more information. So to load and display a complicated huge scene, | 49 | for more information. So to load and display a complicated huge scene, |
50 | we only need a single call to loadScene(). | 50 | we only need a single call to loadScene(). |
51 | */ | 51 | */ |
52 | 52 | ||
53 | // load the scene | 53 | // load the scene |
54 | if (argc>1) | 54 | if (argc>1) |
55 | smgr->loadScene(argv[1]); | 55 | smgr->loadScene(argv[1]); |
56 | else | 56 | else |
57 | smgr->loadScene("../../media/example.irr"); | 57 | smgr->loadScene("../../media/example.irr"); |
58 | 58 | ||
59 | /* | 59 | /* |
60 | Now we'll create a camera, and give it a collision response animator | 60 | Now we'll create a camera, and give it a collision response animator |
61 | that's built from the mesh nodes in the scene we just loaded. | 61 | that's built from the mesh nodes in the scene we just loaded. |
62 | */ | 62 | */ |
63 | scene::ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS(0, 50.f, 0.1f); | 63 | scene::ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS(0, 50.f, 0.1f); |
64 | 64 | ||
65 | // Create a meta triangle selector to hold several triangle selectors. | 65 | // Create a meta triangle selector to hold several triangle selectors. |
66 | scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector(); | 66 | scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector(); |
67 | 67 | ||
68 | /* | 68 | /* |
69 | Now we will find all the nodes in the scene and create triangle | 69 | Now we will find all the nodes in the scene and create triangle |
70 | selectors for all suitable nodes. Typically, you would want to make a | 70 | selectors for all suitable nodes. Typically, you would want to make a |
71 | more informed decision about which nodes to performs collision checks | 71 | more informed decision about which nodes to performs collision checks |
72 | on; you could capture that information in the node name or Id. | 72 | on; you could capture that information in the node name or Id. |
73 | */ | 73 | */ |
74 | core::array<scene::ISceneNode *> nodes; | 74 | core::array<scene::ISceneNode *> nodes; |
75 | smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes); // Find all nodes | 75 | smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes); // Find all nodes |
76 | 76 | ||
77 | for (u32 i=0; i < nodes.size(); ++i) | 77 | for (u32 i=0; i < nodes.size(); ++i) |
78 | { | 78 | { |
79 | scene::ISceneNode * node = nodes[i]; | 79 | scene::ISceneNode * node = nodes[i]; |
80 | scene::ITriangleSelector * selector = 0; | 80 | scene::ITriangleSelector * selector = 0; |
81 | 81 | ||
82 | switch(node->getType()) | 82 | switch(node->getType()) |
83 | { | 83 | { |
84 | case scene::ESNT_CUBE: | 84 | case scene::ESNT_CUBE: |
85 | case scene::ESNT_ANIMATED_MESH: | 85 | case scene::ESNT_ANIMATED_MESH: |
86 | // Because the selector won't animate with the mesh, | 86 | // Because the selector won't animate with the mesh, |
87 | // and is only being used for camera collision, we'll just use an approximate | 87 | // and is only being used for camera collision, we'll just use an approximate |
88 | // bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0) | 88 | // bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0) |
89 | selector = smgr->createTriangleSelectorFromBoundingBox(node); | 89 | selector = smgr->createTriangleSelectorFromBoundingBox(node); |
90 | break; | 90 | break; |
91 | 91 | ||
92 | case scene::ESNT_MESH: | 92 | case scene::ESNT_MESH: |
93 | case scene::ESNT_SPHERE: // Derived from IMeshSceneNode | 93 | case scene::ESNT_SPHERE: // Derived from IMeshSceneNode |
94 | selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node); | 94 | selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node); |
95 | break; | 95 | break; |
96 | 96 | ||
97 | case scene::ESNT_TERRAIN: | 97 | case scene::ESNT_TERRAIN: |
98 | selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node); | 98 | selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node); |
99 | break; | 99 | break; |
100 | 100 | ||
101 | case scene::ESNT_OCTREE: | 101 | case scene::ESNT_OCTREE: |
102 | selector = smgr->createOctreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node); | 102 | selector = smgr->createOctreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node); |
103 | break; | 103 | break; |
104 | 104 | ||
105 | default: | 105 | default: |
106 | // Don't create a selector for this node type | 106 | // Don't create a selector for this node type |
107 | break; | 107 | break; |
108 | } | 108 | } |
109 | 109 | ||
110 | if(selector) | 110 | if(selector) |
111 | { | 111 | { |
112 | // Add it to the meta selector, which will take a reference to it | 112 | // Add it to the meta selector, which will take a reference to it |
113 | meta->addTriangleSelector(selector); | 113 | meta->addTriangleSelector(selector); |
114 | // And drop my reference to it, so that the meta selector owns it. | 114 | // And drop my reference to it, so that the meta selector owns it. |
115 | selector->drop(); | 115 | selector->drop(); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | /* | 119 | /* |
120 | Now that the mesh scene nodes have had triangle selectors created and added | 120 | Now that the mesh scene nodes have had triangle selectors created and added |
121 | to the meta selector, create a collision response animator from that meta selector. | 121 | to the meta selector, create a collision response animator from that meta selector. |
122 | */ | 122 | */ |
123 | scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( | 123 | scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( |
124 | meta, camera, core::vector3df(5,5,5), | 124 | meta, camera, core::vector3df(5,5,5), |
125 | core::vector3df(0,0,0)); | 125 | core::vector3df(0,0,0)); |
126 | meta->drop(); // I'm done with the meta selector now | 126 | meta->drop(); // I'm done with the meta selector now |
127 | 127 | ||
128 | camera->addAnimator(anim); | 128 | camera->addAnimator(anim); |
129 | anim->drop(); // I'm done with the animator now | 129 | anim->drop(); // I'm done with the animator now |
130 | 130 | ||
131 | // And set the camera position so that it doesn't start off stuck in the geometry | 131 | // And set the camera position so that it doesn't start off stuck in the geometry |
132 | camera->setPosition(core::vector3df(0.f, 20.f, 0.f)); | 132 | camera->setPosition(core::vector3df(0.f, 20.f, 0.f)); |
133 | 133 | ||
134 | // Point the camera at the cube node, by finding the first node of type ESNT_CUBE | 134 | // Point the camera at the cube node, by finding the first node of type ESNT_CUBE |
135 | scene::ISceneNode * cube = smgr->getSceneNodeFromType(scene::ESNT_CUBE); | 135 | scene::ISceneNode * cube = smgr->getSceneNodeFromType(scene::ESNT_CUBE); |
136 | if(cube) | 136 | if(cube) |
137 | camera->setTarget(cube->getAbsolutePosition()); | 137 | camera->setTarget(cube->getAbsolutePosition()); |
138 | 138 | ||
139 | /* | 139 | /* |
140 | That's it. Draw everything and finish as usual. | 140 | That's it. Draw everything and finish as usual. |
141 | */ | 141 | */ |
142 | 142 | ||
143 | int lastFPS = -1; | 143 | int lastFPS = -1; |
144 | 144 | ||
145 | while(device->run()) | 145 | while(device->run()) |
146 | if (device->isWindowActive()) | 146 | if (device->isWindowActive()) |
147 | { | 147 | { |
148 | driver->beginScene(true, true, video::SColor(0,200,200,200)); | 148 | driver->beginScene(true, true, video::SColor(0,200,200,200)); |
149 | smgr->drawAll(); | 149 | smgr->drawAll(); |
150 | driver->endScene(); | 150 | driver->endScene(); |
151 | 151 | ||
152 | int fps = driver->getFPS(); | 152 | int fps = driver->getFPS(); |
153 | 153 | ||
154 | if (lastFPS != fps) | 154 | if (lastFPS != fps) |
155 | { | 155 | { |
156 | core::stringw str = L"Load Irrlicht File example - Irrlicht Engine ["; | 156 | core::stringw str = L"Load Irrlicht File example - Irrlicht Engine ["; |
157 | str += driver->getName(); | 157 | str += driver->getName(); |
158 | str += "] FPS:"; | 158 | str += "] FPS:"; |
159 | str += fps; | 159 | str += fps; |
160 | 160 | ||
161 | device->setWindowCaption(str.c_str()); | 161 | device->setWindowCaption(str.c_str()); |
162 | lastFPS = fps; | 162 | lastFPS = fps; |
163 | } | 163 | } |
164 | 164 | ||
165 | } | 165 | } |
166 | 166 | ||
167 | device->drop(); | 167 | device->drop(); |
168 | 168 | ||
169 | return 0; | 169 | return 0; |
170 | } | 170 | } |
171 | 171 | ||
172 | /* | 172 | /* |
173 | **/ | 173 | **/ |