首先你得准备一个3D模型,下面是用3ds max导出的人物模型
导出为*.obj格式,同时把贴图也一起导出
下面是完整的代码
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
#pragma comment(lib,"irrlicht.lib")
int main(void)
{
//设置控制台窗口的标题与窗口颜色
system("TITLE Irrlicht Demo - StaticMesh");
system("COLOR E0");
//用3ds max等导出的*.obj格式模型文件
const char* meshFile = "Assets/DivineWalk.obj";
try
{
IrrlichtDevice* device = createDevice(EDT_DIRECT3D9, dimension2d<u32>(800, 600), 32U);
device->setWindowCaption(L"Divine Walk");
if (device == NULL)
{
//抛出异常(字符串型, char*)
throw("An error occurred in function \'createDevice\'");
}
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
//载入模型
IMesh* mesh = smgr->getMesh(meshFile);
IMeshSceneNode* node = smgr->addMeshSceneNode(mesh);
node->setMaterialFlag(EMF_LIGHTING, false);
node->setPosition(vector3df(0, 0, 0));
//添加摄像机,设置观察点
smgr->addCameraSceneNode(0, vector3df(20, 50, 50),vector3df(10, 30, 20));
//渲染循环
while (device->run())
{
driver->beginScene(true, true, SColor(255, 0, 0, 0));
smgr->drawAll();
driver->endScene();
}
device->drop();
}
catch (char* pszError)
{
puts(pszError);
}
return 0;
}
运行结果
没怎么接触过3ds max,想自己做模型但是又做不了,所以就去网上找了一个然后自己导出为obj格式,发现能用。
我的能力也是有限的,写到这里已经是挖掘了自己的潜能,每次都想写一些比较深刻的东西但是碍于自身能力有限
也只能倾囊而出,自己学到的都倾倒出来与大家共享。有分享,一份快乐就会变成很多,成为大家的快乐。
http://blog.csdn.net/fengyhack/article/details/38300399