使用IRRLICHT引擎 需要先創建一個DEVICE。
device 里面比較重要的三個方面包括:
- IVideoDriver
- ISceneManager
IAnimatedMesh 是ISceneManager里面3D模型的對象。
IAnimatedMeshSceneNode 則是載入3D模型的模塊 - IGUIEnvironment
創建3d模型以及載入3d模型的代碼
IAnimatedMesh* mesh = smgr->getMesh("../../media/ninja.b3d");
if (!mesh)
{
device->drop();
return 1;
}
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
為展現3d世界,需要設置view point, 代碼如下
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
繪制整個世界的代碼
while(device->run())
{
/*
Anything can be drawn between a beginScene() and an endScene()
call. The beginScene() call clears the screen with a color and
the depth buffer, if desired. Then we let the Scene Manager and
the GUI Environment draw their content. With the endScene()
call everything is presented on the screen.
*/
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
總結:
使用3d引擎的真個流程包括:
創建 DEVICE
配置 SceneManager, 包括創建模型,改變模型的appearance, 載入模型, 設置camera方位 等
設置 GUIEnvironment 參數
繪制畫面
初次接觸引擎方面的東西, 有兩個疑問要好好查查看
1. 動畫是如何實現的, 比如打斗場面, mesh的變形是即時的還是已經設置好的?
2. Texture的載入 這方面的東西還不了解。 如何給一個3d模型加入不同的texture?