完整项目下载: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
效果截图: