开源3d游戏引擎irrlicht(鬼火)example讲解——quake3map

上传人:j****9 文档编号:46255883 上传时间:2018-06-24 格式:DOC 页数:6 大小:2.32MB
返回 下载 相关 举报
开源3d游戏引擎irrlicht(鬼火)example讲解——quake3map_第1页
第1页 / 共6页
开源3d游戏引擎irrlicht(鬼火)example讲解——quake3map_第2页
第2页 / 共6页
开源3d游戏引擎irrlicht(鬼火)example讲解——quake3map_第3页
第3页 / 共6页
开源3d游戏引擎irrlicht(鬼火)example讲解——quake3map_第4页
第4页 / 共6页
开源3d游戏引擎irrlicht(鬼火)example讲解——quake3map_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《开源3d游戏引擎irrlicht(鬼火)example讲解——quake3map》由会员分享,可在线阅读,更多相关《开源3d游戏引擎irrlicht(鬼火)example讲解——quake3map(6页珍藏版)》请在金锄头文库上搜索。

1、开源 3D 游戏引擎 Irrlicht(鬼火)Example 讲解Quake3Map赵刚Irrlicht 引擎自带的第 2 个 Example 叫做 Quake3Map,她演示了利用 irrlicht 引擎载入 Quake3 场景文件(.pk3)的过程,程序运行起来如下图:运行 02.Quake3Map.exe 的时候会先出来一个控制台窗口,按 a,再按回车 即可,表示选择 OpenGL 作为渲染 API。进入 bin 目录下的 examples 目录可以看到 02.Quake3Map 目录,双击 Quake3Map_vc9.vcproj 文件打开工程文件,工程文件中只有一个 main.cpp

2、 文 件。内容如下(去除了英文注释):#include #include using namespace irr; #ifdef _MSC_VER #pragma comment(lib, “Irrlicht.lib“) #endifint main() video:E_DRIVER_TYPE driverType;printf(“Please select the driver you want for this example:n“ “ (a) OpenGL 1.5n (b) Direct3D 9.0cn (c) Direct3D 8.1n“ “ (d) Burnings Software

3、 Renderern (e) Software Renderern“ “ (f) NullDevicen (otherKey) exitnn“);char i; std:cin i;switch(i) case a: driverType = video:EDT_OPENGL; break; case b: driverType = video:EDT_DIRECT3D9;break; case c: driverType = video:EDT_DIRECT3D8;break; case d: driverType = video:EDT_BURNINGSVIDEO;break; case

4、e: driverType = video:EDT_SOFTWARE; break; case f: driverType = video:EDT_NULL; break;default: return 1; IrrlichtDevice *device = createDevice(driverType, core:dimension2d(640, 480);if (device = 0) return 1;video:IVideoDriver* driver = device-getVideoDriver(); scene:ISceneManager* smgr = device-getS

5、ceneManager();device-getFileSystem()-addZipFileArchive(“././media/map- 20kdm2.pk3“);scene:IAnimatedMesh* mesh = smgr-getMesh(“20kdm2.bsp“); scene:ISceneNode* node = 0;if (mesh) node = smgr-addOctreeSceneNode(mesh-getMesh(0), 0, -1, 1024);if (node) node-setPosition(core:vector3df(-1300,-144,-1249);sm

6、gr-addCameraSceneNodeFPS();device-getCursorControl()-setVisible(false);int lastFPS = -1;while(device-run() if (device-isWindowActive() driver-beginScene(true, true, video:SColor(255,200,200,200); smgr-drawAll(); driver-endScene();int fps = driver-getFPS();if (lastFPS != fps) core:stringw str = L“Irr

7、licht Engine - Quake 3 Map example “; str += driver-getName(); str += “ FPS:“; str += fps;device-setWindowCaption(str.c_str(); lastFPS = fps; else device-yield(); device-drop(); return 0; 程序很简洁,条理也很清晰,下面讲解一下代码。首先每个使用 irrlicht 的程序都必须包含:#include #pragma comment(lib, “Irrlicht.lib“)表示要使用 irrlicht SDK由于

8、 irrlicht 可以使用多种底层的绘图 API(如 Direct3D,OpenGL,Software) ,程序一开始时需要用户选择一个绘图 API,video:E_DRIVER_TYPE driverType;printf(“Please select the driver you want for this example:n“ “ (a) OpenGL 1.5n (b) Direct3D 9.0cn (c) Direct3D 8.1n“ “ (d) Burnings Software Renderern (e) Software Renderern“ “ (f) NullDevicen

9、 (otherKey) exitnn“);char i; std:cin i;switch(i) case a: driverType = video:EDT_OPENGL; break; case b: driverType = video:EDT_DIRECT3D9;break; case c: driverType = video:EDT_DIRECT3D8;break; case d: driverType = video:EDT_BURNINGSVIDEO;break; case e: driverType = video:EDT_SOFTWARE; break; case f: d

10、riverType = video:EDT_NULL; break; default: return 1; 这里用字母“a”表示 OpenGL,“b”表示 Direct3D 9, “c”表示 Direct3D 8,“d”表示 Burnings Software,“e”表示 Software, “f”表示不绘图。一般选择“a”即可,用户选择的绘图 API 类型保存在变量 driverType 里,driverType 是 irrlicht 内部定义的一个叫 E_DRIVER_TYPE 枚举类型的对象,该枚举类型在 video 名字空间中。接下来根据用户的选择建立 irrlicht 设备对象:Ir

11、rlichtDevice *device = createDevice(driverType, core:dimension2d(640, 480);if (device = 0) return 1;当然如果设备对象建立失败那就没戏了,只有退出程序。video:IVideoDriver* driver = device-getVideoDriver(); scene:ISceneManager* smgr = device-getSceneManager();device-getFileSystem()-addZipFileArchive(“././media/map- 20kdm2.pk3“

12、);上面这前两行只是将设备对象中的视频驱动对象(绘图 API)对象和场景 管理对象保存在临时对象中以备后用。第三行表示将一个名为 map-20kdm2.pk3 的文件加载到 irrlicht 文件系统 中,这个文件是一个压缩文件,irrlicht 引擎自己可以处理压缩文件。scene:IAnimatedMesh* mesh = smgr-getMesh(“20kdm2.bsp“);这行程序表示从 20kdm2.bsp 文件中建立一个带动画的网格对象, 20kdm2.bsp 这个文件首先会在当前磁盘目录下查找,如果没有找到就会在irrlicht 的文件系统中查找,前面已经往 irrlicht 的

13、文件系统中加载了一个 map-20kdm2.pk3 文件,irrlicht 会自动解压这个压缩文件,查找里面是否有一 个名为 20kdm2.bsp 的文件,有则加载,没有则宣告加载失败。scene:ISceneNode* node = 0; if (mesh) node = smgr-addOctreeSceneNode(mesh-getMesh(0), 0, -1, 1024); if (node) node-setPosition(core:vector3df(-1300,-144,-1249);这几行程序表示从网格对象中建立一个场景节点并加入场景管理器中,网 格对象只有加入场景管理器才能

14、被 irrlicht 绘制,否则只是保存在内存中。这里程序选择将场景节点按照八叉树分割管理,每个八叉树节点的多边形 数量不少于 1024 个,节点的被置于位置(-1300,-144,-1249)中。smgr-addCameraSceneNodeFPS(); device-getCursorControl()-setVisible(false);第一行告诉 irrlicht 的场景管理器,场景中需要一个 FPS(第一人称射击) 类型的摄像机。 第二行告诉 irrlicht,鼠标的光标没有必要显示出来。while(device-run() if (device-isWindowActive() d

15、river-beginScene(true, true, video:SColor(255,200,200,200); smgr-drawAll(); driver-endScene();int fps = driver-getFPS();if (lastFPS != fps) core:stringw str = L“Irrlicht Engine - Quake 3 Map example “; str += driver-getName(); str += “ FPS:“; str += fps;device-setWindowCaption(str.c_str(); lastFPS = fps; else device-yield(); 接下来这些代码就是开始无休无止的渲染循环,直到用户退出程序。 device-isWindowActive() 这一行可以判断窗口是否在前端,如果窗口不 在前端,而是被其他窗口遮盖了,那就不用渲染了,省点电力也好。渲染过程还将 FPS 显示到了窗口的标题栏上。用户觉得没什么新鲜感了,关闭程序后执行:device-drop();return 0;释放设备对象,返回系统即可。Quake3Map 程序就讲到这里好了。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号