1.这个例子设计内容:
#include <iostream> #include <irrlicht.h> using namespace irr; #ifdef _IRR_WINDOWS_ #pragma comment(lib, "irrlicht.lib") //#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") #endif void mySetCreatParamters(SIrrlichtCreationParameters* cp); void mySetDeviceType(video::E_DRIVER_TYPE* drivertype); int main(int argc, char** argv) { //我们使用其他方式创建一个IrrlichtDevice SIrrlichtCreationParameters cParam; //mySetDeviceType(&cParam.DriverType);//2.用到的 mySetCreatParamters(&cParam); IrrlichtDevice *device = //1. createDevice(video::EDT_OPENGL, core::dimension2d<u32>(720, 455), 32,false, true, false, 0); //2. createDevice(cParam.DriverType, core::dimension2d<u32>(800, 600)); createDeviceEx(cParam);//3. if (!device) return 1; device->setWindowCaption(L"quake3 map"); video::IVideoDriver *driver = device->getVideoDriver(); scene::ISceneManager *smgr = device->getSceneManager(); gui::IGUIEnvironment *guiev = device->getGUIEnvironment(); //为了显示quake3 map,我们要加载它,而其被压缩在map-20kdm2.pk3中, //所以先将压缩包加载到文件系统 //实际调用device->getFileArchive(filename,true,true,EFAT_ZIP); 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); //node = smgr->addMeshSceneNode(mesh->getMesh(0)); } //通过irr::scene::ISceneNode层的方法对node进行属性调整 //位置:irr::scene::ISceneNodeirr::scene::ISceneNode::setPosition() //旋转:irr::scene::ISceneNode::setRotation() //缩放:irr::scene::ISceneNode::setScale(); if (node) { node->setPosition(core::vector3df(-1300, -144, -1249)); // node->setRotation(core::vector3df(0, 0, 0)); // node->setScale(core::vector3df(1, 1, 1)); } //万事俱备,只需要添加一台摄像机, //maya型的摄像机:irr::scene::ISceneManager::addCameraSceneNodeMaya() //FPS:irr::scene::ISceneManager::addCameraSceneNodeFPS() smgr->addCameraSceneNodeFPS(); //隐藏鼠标:irr::IrrlichtDevice::ICursorControl device->getCursorControl()->setVisible(false); int lastFPS = -1; while (device->run()) { if (device->isWindowActive()) { driver->beginScene(true, true, video::SColor(255, 100, 101, 140)); smgr->drawAll(); guiev->drawAll(); driver->endScene(); int fps = driver->getFPS(); if (lastFPS != fps) { core::stringw str = L"quake3 map ["; str += driver->getName(); str += "]FPS.", str += fps; device->setWindowCaption(str.c_str()); lastFPS = fps; } } else //防止一直渲染占用过多cpu device->yield(); } device->drop(); return 0; } void mySetCreatParamters(SIrrlichtCreationParameters* cp) { std::cout << "Please select the driver you want:\n" "(a) opengl\n(b)Direct3D 9.0c\n(c)Direct3D 8.1\n" "(d)Burning's Software render\n(e)Software Renderer\n" "(f)NullDevice\n(otherKey exit\n\n"; char i; std::cin >> i; switch (i) { case 'a': cp->DriverType = video::EDT_OPENGL; break; case 'b': cp->DriverType = video::EDT_DIRECT3D9; break; case 'c': cp->DriverType = video::EDT_DIRECT3D8; break; case 'd': cp->DriverType = video::EDT_BURNINGSVIDEO; break; case 'e': cp->DriverType = video::EDT_SOFTWARE; break; default: exit(1); } cp->DeviceType = EIDT_BEST; cp->WindowSize = core::dimension2d<u32>(800, 600); cp->Bits = 16; cp->ZBufferBits = 16; cp->Fullscreen = false; cp->Stencilbuffer = false; cp->Vsync = false; cp->AntiAlias = 0; cp->WithAlphaChannel = false; cp->Doublebuffer = true; cp->IgnoreInput = false; cp->Stereobuffer = false; cp->HighPrecisionFPU = false; cp->EventReceiver = 0; cp->WindowId = 0; cp->LoggingLevel = ELL_INFORMATION; } void mySetDeviceType(video::E_DRIVER_TYPE* drivertype) { std::cout << "Please select the driver you want:\n" "(a) opengl\n(b)Direct3D 9.0c\n(c)Direct3D 8.1\n" "(d)Burning's Software render\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; default: exit(1); } }