Qt 使用irrlicht(鬼火)3D引擎

      網友投稿 861 2025-03-31

      Qt 使用irrlicht(鬼火)3D引擎

      項目中需要加載簡單的3D場景。資深老前輩推薦使用開源小巧的引擎irrlicht。

      關于irrlicht,來之百度百科

      Irrlicht引擎是一個用C++書寫的高性能實時的3D引擎,可以應用于C++程序或者.NET語言中。通過使用Direct3D(Windows平臺),OpenGL 1.2或它自己的軟件著色程序,可以實現該引擎的完全跨平臺。盡管是開源的,該Irrlicht庫提供了可以在商業級的3D引擎上具有的藝術特性,例如動態的陰影,粒子系統,角色動畫,室內和室外技術以及碰撞檢測等。

      具體信息?百度百科。

      如何使用,

      首先使用Qt建立工程,略過。

      在Qt pro工程文件總中加入引擎頭文件路徑,和庫文件路徑。

      #包含鬼火3D引擎需要的頭文件路勁

      INCLUDEPATH +=D:\irrlicht-1.8.3\include

      #連接開發需要用到的庫文件

      LIBS +=D:\irrlicht-1.8.3\lib\Win32-gcc\libIrrlicht.a

      如圖所示

      剩下的就是一般的核心代碼部分了,

      包含頭文件部分

      #include

      #include

      #include

      #include

      使用命名空間部分

      using namespace irr;

      using namespace core;

      using namespace scene;

      using namespace video;

      using namespace io;

      using namespace gui;

      引擎初始化

      void Irr_Device::init_Dev()

      {

      if(m_Device != NULL)

      {

      return;

      }

      SIrrlichtCreationParameters params;

      params.AntiAlias = 0;

      params.Bits = 32;

      params.DeviceType = EIDT_BEST;

      params.Doublebuffer = true;

      params.DriverType = EDT_OPENGL;

      params.EventReceiver = 0;

      params.Fullscreen = false;

      params.HighPrecisionFPU = false;

      params.IgnoreInput = false;

      params.LoggingLevel = ELL_INFORMATION;

      params.Stencilbuffer = true;

      params.Stereobuffer = false;

      params.Vsync = false;

      // Specify which window/widget to render to

      // 指定哪個窗口小部件呈現

      params.WindowId = reinterpret_cast(winId());

      params.WindowSize.Width = width();

      params.WindowSize.Height = height();

      params.WithAlphaChannel = true;

      params.ZBufferBits = 16;

      // Create the Irrlicht Device with the previously specified parameters

      // 創建Irrlicht設備的使用與前面指定的參數

      m_Device = createDeviceEx(params);

      /*

      獲取視頻設備,場景管理器和用戶圖形環境的指針并存儲起來。

      */

      video_Driver = m_Device->getVideoDriver();

      scene_Msnsger = m_Device->getSceneManager();

      guienv = m_Device->getGUIEnvironment();

      //smgr->loadScene

      qDebug()<< scene_Msnsger->loadScene("123.irr");

      /*

      Now we'll create a camera, and give it a collision response animator

      that's built from the mesh nodes in the scene we just loaded.

      */

      /*

      現在我們將創建一個相機,給它一個碰撞響應動畫師  由網格節點的現場加載。

      */

      m_Camera = scene_Msnsger->addCameraSceneNodeFPS(0,50.f,0.1f);

      /*

      Now we will find all the nodes in the scene and create triangle

      selectors for all suitable nodes. Typically, you would want to make a

      more informed decision about which nodes to performs collision checks

      on; you could capture that information in the node name or Id.

      */

      /*

      現在我們將在現場找到的所有節點并創建三角形  選擇合適的節點。通常,您會想要  更明智的決定哪些節點執行碰撞檢查  ;你可以捕捉信息的節點名稱或Id。

      */

      scene::IMetaTriangleSelector* meta = scene_Msnsger->createMetaTriangleSelector();

      // core::array nodes;

      // scene_Msnsger->getSceneNodeFromType(scene::ESNT_ANY, nodes);

      core::array nodes;

      scene_Msnsger->getSceneNodesFromType(scene::ESNT_ANY, nodes); // Find all nodes

      for(u32 i =0;i

      {

      scene::ISceneNode* node = nodes[i];

      scene::ITriangleSelector* selector =0;

      switch (node->getType())

      {

      case scene::ESNT_CUBE:

      case scene::ESNT_ANIMATED_MESH:

      // Because the selector won't animate with the mesh,

      // and is only being used for camera collision, we'll just use an approximate

      // bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)

      // 因為選擇器不會與網格動畫,

      // 和僅用于相機碰撞,我們只使用一個近似

      // 邊界框代替((場景::IAnimatedMeshSceneNode *)節點)- > getMesh(0)

      selector = scene_Msnsger->createTriangleSelectorFromBoundingBox(node);

      break;

      case scene::ESNT_MESH:

      case scene::ESNT_SPHERE:

      selector = scene_Msnsger->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(),node);

      break;

      case scene::ESNT_TERRAIN:

      selector = scene_Msnsger->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node);

      break;

      case scene::ESNT_OCTREE:

      selector = scene_Msnsger->createOctreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(),node);

      break;

      default:

      break;

      }

      if(selector)

      {

      meta->addTriangleSelector(selector);

      selector->drop();

      }

      }

      /*

      Now that the mesh scene nodes have had triangle selectors created and added

      to the meta selector, create a collision response animator from that meta selector.

      */

      /*

      現在有三角形網格場景節點選擇器創建和添加  元選擇器,創建一個元的碰撞響應動畫選擇器。

      */

      scene::ISceneNodeAnimator* anim = scene_Msnsger->createCollisionResponseAnimator(

      meta,m_Camera,core::vector3df(5,5,5),core::vector3df(0,0,0));

      meta->drop();

      m_Camera->addAnimator(anim);

      anim->drop();

      m_Camera->setPosition(core::vector3df(0.f,20.f,0.f));

      scene::ISceneNode*cube = scene_Msnsger->getSceneNodeFromType(scene::ESNT_CUBE);

      if(cube)

      {

      m_Camera->setTarget(cube->getAbsolutePosition());

      }

      m_Device->getCursorControl()->setVisible(false);

      connect(this,SIGNAL(sigUpdateIrrlicht(irr::IrrlichtDevice*)),

      this,SLOT(slotUpdateIrrlicht(irr::IrrlichtDevice*)));

      startTimer(0);

      }

      保證實時刷新界面部分

      void Irr_Device::slotUpdateIrrlicht(IrrlichtDevice *device) { if(device != 0) { if (isVisible() && isEnabled()/*&&device->isWindowActive()*/) { device->getTimer()->tick();//在沒有用IrrlichtDevice::run()的情況下,必須加上這句,否則鍵盤不響應 SColor color (255,100,100,140); device->getVideoDriver()->beginScene(true, true, color); device->getSceneManager()->drawAll(); device->getVideoDriver()->endScene(); } else { device->yield(); } } } void Irr_Device::timerEvent(QTimerEvent *event) { if (m_Device != NULL) { emit sigUpdateIrrlicht(m_Device); } event->accept(); }

      這部分代碼暫時還不是很理解,也歡迎大神指出里面存在的問題。

      軟件運行截圖如圖

      Demo 鏈接:http://download.csdn.net/detail/z609932088/9504584

      Qt 網絡

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:word表格下方不能打字怎么辦(word中表格下方無法寫字)
      下一篇:C++多線程筆記(二)
      相關文章
      亚洲bt加勒比一区二区| 亚洲人成网77777色在线播放| 亚洲AV无码成人专区| 亚洲av永久中文无码精品综合| 亚洲精品国精品久久99热| 亚洲视频在线观看一区| 亚洲视频在线视频| 亚洲国产精品久久| 亚洲欧洲日韩国产综合在线二区| 精品国产_亚洲人成在线高清| 亚洲一日韩欧美中文字幕在线| 亚洲伊人久久大香线蕉综合图片| jlzzjlzz亚洲乱熟在线播放| 亚洲成a人片在线看| 精品久久香蕉国产线看观看亚洲| 黑人大战亚洲人精品一区| 亚洲日本VA午夜在线电影| 91在线亚洲精品专区| 亚洲日韩在线观看免费视频| 亚洲国产综合精品一区在线播放| 亚洲国产精品日韩专区AV| 亚洲高清成人一区二区三区| 国产成人亚洲合集青青草原精品| 亚洲w码欧洲s码免费| 亚洲日韩精品国产3区| 亚洲国产精品无码久久98| 亚洲最大黄色网址| 亚洲人成中文字幕在线观看| 精品亚洲永久免费精品| 亚洲色图国产精品| 亚洲国产精品乱码在线观看97| 亚洲人成伊人成综合网久久久| 亚洲AV无码一区二区乱孑伦AS| 亚洲黄片毛片在线观看| 337p日本欧洲亚洲大胆裸体艺术| 亚洲日韩av无码| 亚洲精品综合久久中文字幕| 亚洲va久久久噜噜噜久久| 亚洲综合一区二区精品导航| 亚洲一级高清在线中文字幕| 亚洲精品无码永久在线观看男男|