Commit 4cca69a3 authored by hybrid's avatar hybrid

Some Q3 example changes. OctTree has been reenabled with larger vertex...

Some Q3 example changes. OctTree has been reenabled with larger vertex numbers. Example 16 now accepts pk3 files and bsp levels on the command line, and it can display the bounding boxes of octrees.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1441 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 65cfbeb2
...@@ -101,20 +101,21 @@ int main() ...@@ -101,20 +101,21 @@ int main()
attached. Hence the IAnimated mesh consists of only one frame, attached. Hence the IAnimated mesh consists of only one frame,
so we get the "first frame" of the "animation", which is our quake level so we get the "first frame" of the "animation", which is our quake level
and create an OctTree scene node with it, using addOctTreeSceneNode(). and create an OctTree scene node with it, using addOctTreeSceneNode().
The OctTree optimizes the scene a little bit, trying to draw only geometry The OctTree optimizes the scene a little bit, trying to draw only
which is currently visible. An alternative to the OctTree would be a geometry which is currently visible. An alternative to the OctTree
AnimatedMeshSceneNode, which would draw always the complete geometry of would be a MeshSceneNode, which would draw always the complete geometry
the mesh, without optimization. Try it out: Write addAnimatedMeshSceneNode of the mesh, without optimization. Try it out: Write addMeshSceneNode
instead of addOctTreeSceneNode and compare the primitives drawed by the instead of addOctTreeSceneNode and compare the primitives drawn by the
video driver. (There is a getPrimitiveCountDrawed() method in the video driver. (There is a getPrimitiveCountDrawn() method in the
IVideoDriver class). Note that this optimization with the Octree is only IVideoDriver class). Note that this optimization with the Octree is only
useful when drawing huge meshes consiting of lots of geometry. useful when drawing huge meshes consisting of lots of geometry.
*/ */
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp"); scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0; scene::ISceneNode* node = 0;
if (mesh) if (mesh)
node = smgr->addOctTreeSceneNode(mesh->getMesh(0), 0, -1, 128); node = smgr->addOctTreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
// node = smgr->addMeshSceneNode(mesh->getMesh(0));
/* /*
Because the level was modelled not around the origin (0,0,0), we translate Because the level was modelled not around the origin (0,0,0), we translate
......
...@@ -130,7 +130,6 @@ int main() ...@@ -130,7 +130,6 @@ int main()
selector, camera, core::vector3df(30,50,30), selector, camera, core::vector3df(30,50,30),
core::vector3df(0,-3,0), core::vector3df(0,-3,0),
core::vector3df(0,50,0)); core::vector3df(0,50,0));
selector->drop();
camera->addAnimator(anim); camera->addAnimator(anim);
anim->drop(); anim->drop();
} }
...@@ -286,6 +285,7 @@ int main() ...@@ -286,6 +285,7 @@ int main()
} }
} }
selector->drop();
device->drop(); device->drop();
return 0; return 0;
......
...@@ -65,8 +65,8 @@ class CScreenShotFactory : public IEventReceiver ...@@ -65,8 +65,8 @@ class CScreenShotFactory : public IEventReceiver
{ {
public: public:
CScreenShotFactory( IrrlichtDevice *device, const c8 * templateName ) CScreenShotFactory( IrrlichtDevice *device, const c8 * templateName, ISceneNode* node )
: Device(device), Number(0), FilenameTemplate(templateName) : Device(device), Number(0), FilenameTemplate(templateName), Node(node)
{ {
FilenameTemplate.replace ( '/', '_' ); FilenameTemplate.replace ( '/', '_' );
FilenameTemplate.replace ( '\\', '_' ); FilenameTemplate.replace ( '\\', '_' );
...@@ -75,19 +75,26 @@ public: ...@@ -75,19 +75,26 @@ public:
bool OnEvent(const SEvent& event) bool OnEvent(const SEvent& event)
{ {
// check if user presses the key F9 // check if user presses the key F9
if (event.EventType == EET_KEY_INPUT_EVENT && if ((event.EventType == EET_KEY_INPUT_EVENT) &&
event.KeyInput.Key == KEY_F9 && event.KeyInput.PressedDown)
event.KeyInput.PressedDown == false)
{ {
video::IImage* image = Device->getVideoDriver()->createScreenShot(); if (event.KeyInput.Key == KEY_F9)
if (image)
{ {
c8 buf[256]; video::IImage* image = Device->getVideoDriver()->createScreenShot();
snprintf(buf, 256, "%s_shot%04d.jpg", if (image)
FilenameTemplate.c_str(), {
++Number); c8 buf[256];
Device->getVideoDriver()->writeImageToFile(image, buf, 85 ); snprintf(buf, 256, "%s_shot%04d.jpg",
image->drop(); FilenameTemplate.c_str(),
++Number);
Device->getVideoDriver()->writeImageToFile(image, buf, 85 );
image->drop();
}
}
else
if (event.KeyInput.Key == KEY_F8)
{
Node->setDebugDataVisible(scene::EDS_BBOX_ALL);
} }
} }
return false; return false;
...@@ -97,6 +104,7 @@ private: ...@@ -97,6 +104,7 @@ private:
IrrlichtDevice *Device; IrrlichtDevice *Device;
u32 Number; u32 Number;
core::stringc FilenameTemplate; core::stringc FilenameTemplate;
ISceneNode* Node;
}; };
...@@ -138,13 +146,18 @@ int IRRCALLCONV main(int argc, char* argv[]) ...@@ -138,13 +146,18 @@ int IRRCALLCONV main(int argc, char* argv[])
} }
// create device and exit if creation failed // create device and exit if creation failed
core::dimension2di videoDim ( 800,600 ); const core::dimension2di videoDim ( 800,600 );
IrrlichtDevice *device = createDevice(driverType, videoDim, 32, false ); IrrlichtDevice *device = createDevice(driverType, videoDim, 32, false );
if (device == 0) if (device == 0)
return 1; // could not create selected driver. return 1; // could not create selected driver.
const char* mapname=0;
if (argc>2)
mapname = argv[2];
else
mapname = QUAKE3_MAP_NAME;
/* /*
Get a pointer to the video driver and the SceneManager so that Get a pointer to the video driver and the SceneManager so that
...@@ -155,22 +168,20 @@ int IRRCALLCONV main(int argc, char* argv[]) ...@@ -155,22 +168,20 @@ int IRRCALLCONV main(int argc, char* argv[])
scene::ISceneManager* smgr = device->getSceneManager(); scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* gui = device->getGUIEnvironment(); gui::IGUIEnvironment* gui = device->getGUIEnvironment();
// create an event receiver for making screenshots
CScreenShotFactory screenshotFactory ( device, QUAKE3_MAP_NAME );
device->setEventReceiver ( &screenshotFactory );
//! add our private media directory to the file system //! add our private media directory to the file system
device->getFileSystem()->addFolderFileArchive("../../media/"); device->getFileSystem()->addFolderFileArchive("../../media/");
/* /*
To display the Quake 3 map, we first need to load it. Quake 3 maps To display the Quake 3 map, we first need to load it. Quake 3 maps
are packed into .pk3 files wich are nothing other than .zip files. are packed into .pk3 files, which are nothing other than .zip files.
So we add the .pk3 file to our FileSystem. After it was added, So we add the .pk3 file to our FileSystem. After it was added,
we are able to read from the files in that archive as they would we are able to read from the files in that archive as they would
directly be stored on disk. directly be stored on disk.
*/ */
device->getFileSystem()->QUAKE3_STORAGE_FORMAT ( QUAKE3_STORAGE_1 ); if (argc>2)
device->getFileSystem()->QUAKE3_STORAGE_FORMAT (argv[1]);
else
device->getFileSystem()->QUAKE3_STORAGE_FORMAT ( QUAKE3_STORAGE_1 );
#ifdef QUAKE3_STORAGE_2 #ifdef QUAKE3_STORAGE_2
device->getFileSystem()->QUAKE3_STORAGE_FORMAT ( QUAKE3_STORAGE_2 ); device->getFileSystem()->QUAKE3_STORAGE_FORMAT ( QUAKE3_STORAGE_2 );
#endif #endif
...@@ -193,8 +204,7 @@ int IRRCALLCONV main(int argc, char* argv[]) ...@@ -193,8 +204,7 @@ int IRRCALLCONV main(int argc, char* argv[])
IVideoDriver class). Note that this optimization with the Octree is only IVideoDriver class). Note that this optimization with the Octree is only
useful when drawing huge meshes consisting of lots of geometry. useful when drawing huge meshes consisting of lots of geometry.
*/ */
scene::IQ3LevelMesh* mesh = (scene::IQ3LevelMesh*) smgr->getMesh( QUAKE3_MAP_NAME ); scene::IQ3LevelMesh* mesh = (scene::IQ3LevelMesh*) smgr->getMesh(mapname);
/* /*
add the geometry mesh to the Scene ( polygon & patches ) add the geometry mesh to the Scene ( polygon & patches )
...@@ -203,10 +213,15 @@ int IRRCALLCONV main(int argc, char* argv[]) ...@@ -203,10 +213,15 @@ int IRRCALLCONV main(int argc, char* argv[])
scene::ISceneNode* node = 0; scene::ISceneNode* node = 0;
if ( mesh ) if ( mesh )
{ {
scene::IMesh *geometry = mesh->getMesh(quake3::E_Q3_MESH_GEOMETRY ); scene::IMesh *geometry = mesh->getMesh(quake3::E_Q3_MESH_GEOMETRY);
node = smgr->addMeshSceneNode ( geometry ); // node = smgr->addMeshSceneNode ( geometry );
node = smgr->addOctTreeSceneNode(geometry, 0, -1, 1024);
} }
// create an event receiver for making screenshots
CScreenShotFactory screenshotFactory ( device, mapname, node );
device->setEventReceiver ( &screenshotFactory );
/* /*
now construct SceneNodes for each Shader now construct SceneNodes for each Shader
The Objects are stored in the quake mesh scene::E_Q3_MESH_ITEMS The Objects are stored in the quake mesh scene::E_Q3_MESH_ITEMS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment