这个例子仅简单的介绍了下如何Load一个Quake3的场景,其中没有什么特殊的概念。
只需注意一下Irr的思想就可以,将场景和摄象机都做为场景节点来处理。

最后,提供了用户选择设备类型的功能,并显示了FPS。

/* Example 002 Quake3Map
This Tutorial shows how to load a Quake 3 map into the engine, create a
SceneNode for optimizing the speed of rendering, and how to create a user
controlled camera.
Please note that you should know the basics of the engine before starting this
tutorial. Just take a short look at the first tutorial, if you haven't done
this yet: http://irrlicht.sourceforge.net/tut001.html
Lets start like the HelloWorld example: We include the irrlicht header files
and an additional file to be able to ask the user for a driver type using the
console.
*/
#include <irrlicht.h>
#include <iostream>
/*
As already written in the HelloWorld example, in the Irrlicht Engine everything
can be found in the namespace 'irr'. To get rid of the irr:: in front of the
name of every class, we tell the compiler that we use that namespace from now
on, and we will not have to write that 'irr::'. There are 5 other sub
namespaces 'core', 'scene', 'video', 'io' and 'gui'. Unlike in the HelloWorld
example, we do not call 'using namespace' for these 5 other namespaces, because
in this way you will see what can be found in which namespace. But if you like,
you can also include the namespaces like in the previous example.
*/
using namespace irr;
/*
Again, to be able to use the Irrlicht.DLL file, we need to link with the
Irrlicht.lib. We could set this option in the project settings, but to make it
easy, we use a pragma comment lib:
*/
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
/*
Ok, lets start. Again, we use the main() method as start, not the WinMain().
*/
int main()
{
   /*
   Like in the HelloWorld example, we create an IrrlichtDevice with
   createDevice(). The difference now is that we ask the user to select
   which video driver to use. The Software device might be
   too slow to draw a huge Quake 3 map, but just for the fun of it, we make
   this decision possible, too.
   Instead of copying this whole code into your app, you can simply include
   driverChoice.h from Irrlicht's include directory. The function
   driverChoiceConsole does exactly the same.
   */
   // ask user for driver
   video::E_DRIVER_TYPE driverType;
   printf("Please select the driver you want for this example:\n"\
       " (a) OpenGL 1.5\n (b) Direct3D 9.0c\n (c) Direct3D 8.1\n"\
       " (d) Burning's Software Renderer\n (e) Software Renderer\n"\
       " (f) NullDevice\n (otherKey) exit\n\n");
   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': driverType = video::EDT_NULL;     break;
       default: return 1;
   }
   // create device and exit if creation failed
   IrrlichtDevice *device =
       createDevice(driverType, core::dimension2d<u32>(640, 480));
   if (device == 0)
       return 1; // could not create selected driver.
   /*
   Get a pointer to the video driver and the SceneManager so that
   we do not always have to call irr::IrrlichtDevice::getVideoDriver() and
   irr::IrrlichtDevice::getSceneManager().
   */
   video::IVideoDriver* driver = device->getVideoDriver();
   scene::ISceneManager* smgr = device->getSceneManager();
   /*
   To display the Quake 3 map, we first need to load it. Quake 3 maps
   are packed into .pk3 files which are nothing else than .zip files.
   So we add the .pk3 file to our irr::io::IFileSystem. After it was added,
   we are able to read from the files in that archive as if they are
   directly stored on the disk.
   */
   device->getFileSystem()->addZipFileArchive("../media/map-20kdm2.pk3");
   /*
   Now we can load the mesh by calling
   irr::scene::ISceneManager::getMesh(). We get a pointer returned to an
   irr::scene::IAnimatedMesh. As you might know, Quake 3 maps are not
   really animated, they are only a huge chunk of static geometry with
   some materials attached. Hence the IAnimatedMesh consists of only one
   frame, so we get the "first frame" of the "animation", which is our
   quake level and create an Octree scene node with it, using
   irr::scene::ISceneManager::addOctreeSceneNode().
   The Octree optimizes the scene a little bit, trying to draw only geometry
   which is currently visible. An alternative to the Octree would be a
   irr::scene::IMeshSceneNode, which would always draw the complete
   geometry of the mesh, without optimization. Try it: Use
   irr::scene::ISceneManager::addMeshSceneNode() instead of
   addOctreeSceneNode() and compare the primitives drawn by the video
   driver. (There is a irr::video::IVideoDriver::getPrimitiveCountDrawn()
   method in the irr::video::IVideoDriver class). Note that this
   optimization with the Octree is only useful when drawing huge meshes
   consisting of lots of geometry.
   */
   scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
   scene::ISceneNode* node = 0;
   if (mesh)
       node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
//     node = smgr->addMeshSceneNode(mesh->getMesh(0));
   /*
   Because the level was not modelled around the origin (0,0,0), we
   translate the whole level a little bit. This is done on
   irr::scene::ISceneNode level using the methods
   irr::scene::ISceneNode::setPosition() (in this case),
   irr::scene::ISceneNode::setRotation(), and
   irr::scene::ISceneNode::setScale().
   */
   if (node)
       node->setPosition(core::vector3df(-1300,-144,-1249));
   /*
   Now we only need a camera to look at the Quake 3 map.
   We want to create a user controlled camera. There are some
   cameras available in the Irrlicht engine. For example the
   MayaCamera which can be controlled like the camera in Maya:
   Rotate with left mouse button pressed, Zoom with both buttons pressed,
   translate with right mouse button pressed. This could be created with
   irr::scene::ISceneManager::addCameraSceneNodeMaya(). But for this
   example, we want to create a camera which behaves like the ones in
   first person shooter games (FPS) and hence use
   irr::scene::ISceneManager::addCameraSceneNodeFPS().
   */
   smgr->addCameraSceneNodeFPS();
   /*
   The mouse cursor needs not be visible, so we hide it via the
   irr::IrrlichtDevice::ICursorControl.
   */
   device->getCursorControl()->setVisible(false);
   /*
   We have done everything, so lets draw it. We also write the current
   frames per second and the primitives drawn into the caption of the
   window. The test for irr::IrrlichtDevice::isWindowActive() is optional,
   but prevents the engine to grab the mouse cursor after task switching
   when other programs are active. The call to
   irr::IrrlichtDevice::yield() will avoid the busy loop to eat up all CPU
   cycles when the window is not active.
   */
   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"Irrlicht Engine - Quake 3 Map example [";
               str += driver->getName();
               str += "] FPS:";
               str += fps;
               device->setWindowCaption(str.c_str());
               lastFPS = fps;
           }
       }
       else
           device->yield();
   }
   /*
   In the end, delete the Irrlicht device.
   */
   device->drop();
   return 0;
}
/*
That's it. Compile and play around with the program.
**/

Irrlicht例002--Quake3Map相关推荐

  1. Irrlicht例001--Hello World

    所有Irr的引擎文件都在Irr命名空间下,Irr命名空间下又分五大模块: Core:包含一些引擎核心类,包括各种数据结构和自定义的数据结构. Gui:一些常用的图形用户接口,实现了各种常用控件. Io ...

  2. 实用ExtJS教程100例-002:MessageBox的三种用法

    在上一节中,我们用到了MessageBox,在本文中,我们将介绍一下ExtJS中常用的三种MessageBox. Ext.MessageBox.alert() 这个方法用来打开一个普通的对话框,对话框 ...

  3. Visual C++ 时尚编程百例002(MFC窗口)

    打开vc2005 新建Win32项目,选择空项目. CWinApp包括启动,初始化,运行和关闭应用程序所需的一切代码. 项目->属性,或者右击项目->属性(注意不是右击解决方案) 项目-& ...

  4. stm32f4 hs 电路_电动机控制电路识图一看就懂

    点击上方电工电气学习,关注并星标 专业的电工电气领域自媒体,不容错过 欢迎转发朋友圈,欢迎文末留言 本书采用原理图与实物接线图一一对照的形式,讲述了常用机械设备.液位控制的水泵.小型机械设备.供排循环 ...

  5. 对正则表达式又重新学了一遍,笔记方便以后查阅

    学习地址:慕课网 JavaScript正则表达式 学习地址:慕课网 JavaScript正则表达式通配符:*测试正则表达式: 在线工具:http://regexper.com 也可以从npm上安装到本 ...

  6. python单元测试框架作用_Python单元测试框架:Pytest简介

    Pytest简介 入门简单,文档丰富 支持单元测试.功能测试 支持参数化 重复执行,部分执行,测试跳过 兼容其他测试框架(nose,unittest等) 支持生成html报告 可集成CI环境(Jenk ...

  7. 【软件测试】自动化测试战零基础教程——Python自动化从入门到实战(六)

    整理不易,希望对各位学习软件测试能带来帮助 软件测试知识持续更新 第五章 自动化测试用例设计 第一节.手工测试用例与自动化测试用例 手工测试用例与自动化测试用例对比: 用例选型注意事项: 第二节.测试 ...

  8. 【pytest】2.pytest的前置、后置

    pytest框架的前后置(固件,夹具)处理,三种方法: 一.setup/teardown,setup_class/teardown_class(全部) class TestLogin:def setu ...

  9. 征服Excel VBA:让你工作效率倍增的239个实用技巧

    下载地址:https://webboy.pipipan.com/fs/19405313-362892031 内容简介: <征服Excel VBA:让你工作效率倍增的239个实用技巧>分16 ...

最新文章

  1. Postgresql 日志收集
  2. Matlab与线性代数--广义逆矩阵
  3. xgboost算法_陈天奇做的XGBoost为什么能横扫机器学习竞赛平台?
  4. REDHAT6.3 udev 配置 存储器磁盘
  5. JavaScript编程艺术-第7章代码汇总(2)
  6. 吴恩达深度学习——深度学习概论
  7. 《设计模式》读懂UML类图
  8. requests 获取百度推广信息
  9. Eclipse无法修改字体
  10. 推荐几个学习JS的站点
  11. FPGA 入门 (一)
  12. 51单片机基础入门教程(精华版)文末有惊喜
  13. 简单一招就能进行不同平台的推文转移,复制粘贴。
  14. maven跳过Test打包
  15. 无盘服务器接几根网线,设置无线路由器需要几根网线_安装路由器需要几根网线?-192路由网...
  16. 微信显示服务器吃撑了,虐死单身狗!微信突然上线新功能:狗粮一下吃到撑
  17. python 日期API
  18. 【完整教程】nginx反向代理wss,实现不修改服务器端websocket代码加密通讯请求
  19. 超详细Netty入门
  20. 游戏直播平台新赛程:负重前行与危中求生

热门文章

  1. 深入理解C# 3.x的新特性(5):Object Initializer 和 Collection Initializer
  2. IOS网络请求的一些需要记录的info设置
  3. Spring Security视频地址
  4. Python进程间传递套接字问题
  5. 成功网络管理员必备“软件”素质
  6. 以太坊开发入门,完整入门篇
  7. Python 类的特殊成员方法
  8. Powershell为接收连接器批量添加RemoteIP地址
  9. Rocky4.2下安装达梦(DM)6数据库
  10. 超酷jQuery进度条加载动画集合