Irrlicht简介

Irrlicht在国内也被叫做“鬼火”引擎,是一款用C++编写的开放源代码的高性能游戏引擎。而且是跨平台的,具有很好的移植性,Irrlicht支持OpenGl、Direcx3D渲染,引擎本身也实现了一套自己的渲染系统。在商业引擎中能够找到的艺术特性,Irrlicht基本都支持。目前有很多项目中都使用到它,Irrlicht社区也比较活跃,可以在互联网上找到不少Irrlicht增强工具,例如irrEdit、irrKlang等。在众多开源游戏引擎中,Irrlicht也是比较受笔者青睐的一款。

Irrlicht官方网站:http://irrlicht.sourceforge.net/

Irrlicht下载与使用

Irrlicht目前最新稳定版本为1.8.1,项目发布在sourceforge平台上,用户可以通过sourceforge网站首页面搜索功能找到Irrlicht项目下载地址,或者从Irrlicht官网获取下载链接。

下载地址:http://irrlicht.sourceforge.net/downloads/

1.目录结构

解压后目录结构如下:

bin:不同平台编译Irrlicht生成的可执行文件和动态库文件放在该目录中。

doc : 该目录中为Irrlicht API文档。

examples : Irrlicht官方提供的案例程序存放在该目录中。

include : 存放引擎所有头文件。

lib : 该目录存放Irrlicht引擎编译过后生成的静态库。

media : 官方案例所需资源文件存放在此目录中。

source : 存放引擎源码。

tools : 该目录下为Irrlicht引擎相关工具。如irrEdit、GUIEditor等。

2.官方案例

Irrlicht使用起来是非常方便的,这也是笔者比较喜欢它的原因之一。为了方便用户学习和使用引擎,Irrlicht官方提供了大量的例子程序,而且都比较具有代表性。

打开examples目录,Irrlicht已经为目前主流开发工具Windows平台下Visual Studio、MacOS下的Xcode以及Linux平台下的GNU MAKE做好了项目配置。

笔者是在Windows操作系统下使用VS2012进行演示,双击BuildAllExamples_vc11.sln打开解决方案,无需做任何配置即可编译运行程序。

编译运行Collision案例程序:

看起来效果是不是很炫呢?Irrlicht为我们做了大量的封装,即便看似如此复杂的程序,实际代码不超过200行。

#include <irrlicht.h>
#include "driverChoice.h" using namespace irr; #ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
enum
{
ID_IsNotPickable = 0,
IDFlag_IsPickable = 1 << 0,
IDFlag_IsHighlightable = 1 << 1
};
int main()
{
video::E_DRIVER_TYPE driverType=video::EDT_OPENGL;//driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1; IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<u32>(1024, 768), 16, false);
if (device == 0)
return 1; // could not create selected driver. video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager(); device->getFileSystem()->addFileArchive("../../media/map-20kdm2.pk3"); scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
scene::IMeshSceneNode* q3node = 0; if (q3levelmesh)
q3node = smgr->addOctreeSceneNode(q3levelmesh->getMesh(0), 0, IDFlag_IsPickable);
scene::ITriangleSelector* selector = 0; if (q3node)
{
q3node->setPosition(core::vector3df(-1350,-130,-1400)); selector = smgr->createOctreeTriangleSelector(
q3node->getMesh(), q3node, 128);
q3node->setTriangleSelector(selector);
} scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0, 100.0f, .3f, ID_IsNotPickable, 0, 0, true, 3.f);
camera->setPosition(core::vector3df(50,50,-60));
camera->setTarget(core::vector3df(-70,30,-60)); if (selector)
{
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(30,50,30),
core::vector3df(0,-10,0), core::vector3df(0,30,0));
selector->drop(); // As soon as we're done with the selector, drop it.
camera->addAnimator(anim);
anim->drop();
} device->getCursorControl()->setVisible(false); scene::IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
bill->setMaterialTexture(0, driver->getTexture("../../media/particle.bmp"));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialFlag(video::EMF_ZBUFFER, false);
bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));
bill->setID(ID_IsNotPickable); // This ensures that we don't accidentally ray-pick it scene::IAnimatedMeshSceneNode* node = 0; video::SMaterial material; node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/faerie.md2"),
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
node->setPosition(core::vector3df(-90,-15,-140)); // Put its feet on the floor.
node->setScale(core::vector3df(1.6f)); // Make it appear realistically scaled
node->setMD2Animation(scene::EMAT_POINT);
node->setAnimationSpeed(20.f);
material.setTexture(0, driver->getTexture("../../media/faerie2.bmp"));
material.Lighting = true;
material.NormalizeNormals = true;
node->getMaterial(0) = material; selector = smgr->createTriangleSelector(node);
node->setTriangleSelector(selector);
selector->drop(); // We're done with this selector, so drop it now.
node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/ninja.b3d"),
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
node->setScale(core::vector3df(10));
node->setPosition(core::vector3df(-75,-66,-80));
node->setRotation(core::vector3df(0,90,0));
node->setAnimationSpeed(8.f);
node->getMaterial(0).NormalizeNormals = true;
node->getMaterial(0).Lighting = true;
selector = smgr->createTriangleSelector(node);
node->setTriangleSelector(selector);
selector->drop(); node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/dwarf.x"),
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
node->setPosition(core::vector3df(-70,-66,-30)); // Put its feet on the floor.
node->setRotation(core::vector3df(0,-90,0)); // And turn it towards the camera.
node->setAnimationSpeed(20.f);
node->getMaterial(0).Lighting = true;
selector = smgr->createTriangleSelector(node);
node->setTriangleSelector(selector);
selector->drop(); node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/yodan.mdl"),
0, IDFlag_IsPickable | IDFlag_IsHighlightable);
node->setPosition(core::vector3df(-90,-25,20));
node->setScale(core::vector3df(0.8f));
node->getMaterial(0).Lighting = true;
node->setAnimationSpeed(20.f); // Just do the same as we did above.
selector = smgr->createTriangleSelector(node);
node->setTriangleSelector(selector);
selector->drop(); material.setTexture(0, 0);
material.Lighting = false;
scene::ILightSceneNode * light = smgr->addLightSceneNode(0, core::vector3df(-60,100,400),
video::SColorf(1.0f,1.0f,1.0f,1.0f), 600.0f);
light->setID(ID_IsNotPickable); // Make it an invalid target for selection. scene::ISceneNode* highlightedSceneNode = 0;
scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
int lastFPS = -1;
material.Wireframe=true;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0);
smgr->drawAll();
if (highlightedSceneNode)
{
highlightedSceneNode->setMaterialFlag(video::EMF_LIGHTING, true);
highlightedSceneNode = 0;
} core::line3d<f32> ray;
ray.start = camera->getPosition();
ray.end = ray.start + (camera->getTarget() - ray.start).normalize() * 1000.0f; core::vector3df intersection;
core::triangle3df hitTriangle; scene::ISceneNode * selectedSceneNode =
collMan->getSceneNodeAndCollisionPointFromRay(
ray,
intersection,
hitTriangle,
IDFlag_IsPickable,
0);
if(selectedSceneNode)
{
bill->setPosition(intersection);
driver->setTransform(video::ETS_WORLD, core::matrix4());
driver->setMaterial(material);
driver->draw3DTriangle(hitTriangle, video::SColor(0,255,0,0)); if((selectedSceneNode->getID() & IDFlag_IsHighlightable) == IDFlag_IsHighlightable)
{
highlightedSceneNode = selectedSceneNode;
highlightedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
}
}
driver->endScene(); int fps = driver->getFPS(); if (lastFPS != fps)
{
core::stringw str = L"Collision detection example - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps; device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop(); return 0;
}

开源3D游戏引擎Irrlicht简介的更多相关文章

  1. 基于Java的开源3D游戏引擎jMonkeyEngine

    jMonkeyEngine简介 jMonkeyEngine是一款纯Java语言编写的游戏引擎,继承了Java应用跨平台的特性,而且是开放源代码的,遵循BSD开源协议,BSD开源协议用一句简单的话概括就 ...

  2. 转载:[转]如何学好3D游戏引擎编程

      [转]如何学好3D游戏引擎编程 Albert 本帖被 gamengines 从 游戏引擎(Game Engine) 此文为转载,但是值得一看. 此篇文章献给那些为了游戏编程不怕困难的热血青年,它的 ...

  3. 记录一下八款开源 Android 游戏引擎

    记录一下八款开源 Android 游戏引擎 虽然android学了点点,然后现在又没学了(我为啥这么没有恒心呢大哭).以后有时间还是要继续学android的,一定要啊!虽然现在没学android游戏编 ...

  4. 排名前10的H5、Js 3D游戏引擎和框架

    由于很多人都在用JavaScript.HTML5和WebGL技术创建基于浏览器的3D游戏,所有JavaScript 3D游戏引擎是一个人们主题.基于浏览器的游戏最棒的地方是平台独立,它们能在iOS.A ...

  5. 棒!使用.NET Core构建3D游戏引擎

    原文地址:https://mellinoe.wordpress.com/2017/01/18/net-core-game-engine/ 作者:ERIC MELLINO 翻译:杨晓东(Savorboa ...

  6. Android 八款开源 Android 游戏引擎

    原文地址 本文内容 Angle Rokon LGame AndEngine libgdx jPCT Alien3d Catcake 最近无意间看到一篇关于 Android 搜索引擎的文章,于是搜索了, ...

  7. 八款开源 Android 游戏引擎[转]

    记录一下,以备不时之需~~~~~ 虽然android学了点点,然后现在又没学了(我为啥这么没有恒心呢大哭).以后有时间还是要继续学android的,一定要啊!虽然现在没学android游戏编程,不过还 ...

  8. [转]八款开源Android游戏引擎

    八款开源Android游戏引擎 1.Angle Angle是一款专为Android平台设计的,敏捷且适合快速开发的2D游戏引擎,基于OpenGL ES技术开发.该引擎全部用Java代码编写,并且可以根 ...

  9. 国内开源html5游戏引擎全收录

    本文引自<国内开源html5游戏引擎全收录> 游戏开发这潭水太深,英文水平太差,不敢看国外的, 而且这几年国内技术水平也挺高了不少,特别是JS方面.(我个人感觉) 最近看了几个国产的js游 ...

随机推荐

  1. 数组中出现一次的两个数(三个数)& 求最后一位bit为1

    对于两个数,对于结果中,剩余bit1来异或区分. 下面的解法,非常精简: int lastBitOf1(int number) { ); } void getTwoUnique(vector<i ...

  2. _stat函数/struct stat 结构体使用笔记

    内容来自互联网,非原创,方便以后查看. 另,关于获取文件信息——_stat函数的使用详见 http://blog.csdn.net/frank_liuxing/article/details/1860 ...

  3. Java单例你所不知道的事,与Volatile关键字有染

    版权声明:本文为博主原创文章,未经博主允许不得转载. 如果问一个码农最先接触到的设计模式是什么,单例设计模式一定最差也是“之一”. 单例,Singleton,保证内存中只有一份实例对象存在. 问:为什 ...

  4. nyoj--1009--So Easy[Ⅰ](数学)

    So Easy[Ⅰ] 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 给出任意一个三角形的三个边a,b,c. 要求:求出这个三角形的外接圆半径. 输入 输入数据有多组. ...

  5. Codeforces 708D 费用流 (呃我们的考试题)

    NB的题目背景 输入输出一样 考试的时候貌似只有gzz一个人搞出来了 %gzz 思路: 分情况讨论 add(x,y,C,E) C是费用 E是流量 1. f>c add(x,y,2,inf),ad ...

  6. ios下微信浏览器如何唤醒app?app已上架应用宝

    android下可以通过在应用宝微下载地址后面加参数&android_schema='应用schema'来实现,ios下如何实现? ios下微信浏览器如何唤醒app?app已上架应用宝 > ...

  7. [BeiJing2009 WinterCamp]取石子游戏 Nim SG 函数

    Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...

  8. [笔记-图论]Bellman-Ford

    用于求可带负权的单源有向图 优化后复杂度O(nm) 如果图中存在负环,就不存在最小路 这种情况下,就一定会有一个顶点被松弛多于n-1次,Bellman-Ford可直接判断出来 我在网上看到SPFA,发 ...

  9. [洛谷P1939]【模板】矩阵加速(数列)

    题目大意:给你一个数列a,规定$a[1]=a[2]=a[3]=1$,$a[i]=a[i-1]+a[i-3](i>3)$求$a[n]\ mod\ 10^9+7$的值. 解题思路:这题看似是很简单的 ...

  10. easyui-combobox实现取值范围的联动

    需求:需要用两个combobox来输入一个年月的范围,下拉框的内容从服务器获取.需要实现选中前者后,后者的下拉框中不能显示比前者数值小的:选中后者后,前者的下拉框内容不能显示比后者数值大的 有两个co ...