irrwowview

Tutorial 15: Load .irr file

Tutorial 15: Load .irr file
1.1版本开始,IrrLicht引擎能够使用*.irr文件(一种基于XML格式文件)对完整的场景图形(scene graph)进行保存和加载,还可以用叫作irrEdit的编辑器来编辑这些文件,可以到http://irredit.irrlicht3d.org网站下载,这个编辑器还可以作为世界和粒子的编辑器。本教程演示如何使用*.irr文件。

程序效果如下图所示:

 

Lets start!

首先:创建一个IrrLicht设备并设置窗口。

#include

 

#include

 

using namespace irr;

 

 

 

#pragma comment(lib, "Irrlicht.lib")

 

 

 

int main()

 

{

 

          // ask user for driver

 

 

 

          video::E_DRIVER_TYPE driverType;

 

 

 

          printf("Please select the driver you want for this example:\n"\

 

                    " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\

 

                    " (d) Software Renderer\n (e) Apfelbaum Software Renderer\n"\

 

                    " (f) NullDevice\n (otherKey) exit\n\n");

 

 

 

          char i;

 

          std::cin >> i;

 

 

 

          switch(i)

 

          {

 

                    case 'a': driverType = video::EDT_DIRECT3D9;break;

 

                    case 'b': driverType = video::EDT_DIRECT3D8;break;

 

                    case 'c': driverType = video::EDT_OPENGL;   break;

 

                    case 'd': driverType = video::EDT_SOFTWARE; break;

 

                    case 'e': driverType = video::EDT_SOFTWARE2;break;

 

                    case 'f': driverType = video::EDT_NULL;     break;

 

                    default: return 1;

 

          }        

 

 

 

          // create device and exit if creation failed

 

 

 

          IrrlichtDevice* device =

 

                    createDevice(driverType, core::dimension2d(640, 480));

 

 

 

          if (device == 0)

 

                    return 1; // could not create selected driver.

 

 

 

          device->setWindowCaption(L"Load .irr file example");

 

 

 

          video::IVideoDriver* driver = device->getVideoDriver();

 

          scene::ISceneManager* smgr = device->getSceneManager();

 

现在加载*.irr文件。*.irr文件可以保存整个场景图,场景图包括动作器,材质和粒子系统。还可以保存为场景节点保存任意的用户数据。为了使例子简单,我们简单地加载场景。查阅文档中的ISceneManager::loadSceneISceneManager::saveScene能够获得更多的信息。因此只需要调用loadScene()函数,就能加载并显示一个复杂的超大场景。

// load the scene
smgr->loadScene("../../media/example.irr");

这样就已经可以了。现在是添加一个摄像机并绘制场景。

          // add a user controlled camera

 

 

 

          smgr->addCameraSceneNodeFPS();

 

 

 

          // and draw everything.

 

         

 

          while(device->run())

 

          if (device->isWindowActive())

 

          {

 

                    driver->beginScene(true, true, video::SColor(0,200,200,200));

 

                    smgr->drawAll();

 

                    driver->endScene();

 

          }

 

 

 

          device->drop();

 

         

 

          return 0;

 

}

 

 

 

posted on 2008-07-04 11:29 shjy 阅读(374) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理