您的位置:首页 > 编程语言

[OGRE]看备注学编程(01):一个锃光瓦亮的大脑袋

2013-09-28 14:20 288 查看
完整项目下载:http://download.csdn.net/detail/wxg694175346/6333697

头文件EnvMapping.h:

#include "ExampleApplication.h"

class EnvMapApplication : public ExampleApplication
{
public:
EnvMapApplication() {}

protected:
// 重新实现createScene函数,
void createScene(void)
{
// 设置环境光
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
// 创建点光源
Light* l = mSceneMgr->createLight("MainLight");
// 设置点光源 l 的位置,默认颜色为白色
l->setPosition(20,80,50);
// 读入 ogrehead.mesh模型文件,创建为一个Entity
Entity *ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
// 设置食人魔Enmy的材质为指定材质(环境贴图)
ent->setMaterialName("Examples/SphereMappedRustySteel");
// 将食人魔Enmy连接到场景根节点上
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
}
};


源文件EnvMapping.cpp:

#include "EnvMapping.h"

// 判断编译平台 ,ogre3D支持跨平台
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

// 判断编译平台 ,ogre3D支持跨平台
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
// Win32平台
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
// 非Win32平台
int main(int argc, char **argv)
#endif
{
// 创建应用程序对象
EnvMapApplication app;

try {
//执行go函数,开始应用程序过程
app.go();
}
//异常处理
catch( Exception& e )
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
// Win32平台异常提示
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
//非Win32平台异常提示
std::cerr << "An exception has occured: " << e.getFullDescription();
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif


效果截图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: