/*
-----------------------------------------------------------------------------
Filename: BaseApplication.cpp
-----------------------------------------------------------------------------
This source file is part of the
___ __ __ _ _ _
/___\__ _ _ __ ___ / / /\ \ (_) | _(_)
// // _` | '__/ _ \ \ \/ \/ / | |/ / |
/ \_// (_| | | | __/ \ /\ /| | <| |
\___/ \__, |_| \___| \/ \/ |_|_|\_\_|
|___/
Tutorial Framework
http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/
#include "BaseApplication.h"
//-------------------------------------------------------------------------------------
BaseApplication::BaseApplication(void)
: mRoot(0),
mCamera(0),
mSceneMgr(0),
mWindow(0),
mResourcesCfg(Ogre::StringUtil::BLANK),
mPluginsCfg(Ogre::StringUtil::BLANK),
mTrayMgr(0),
mCameraMan(0),
mDetailsPanel(0),
mCursorWasVisible(false),
mShutDown(false),
mInputManager(0),
mMouse(0),
mKeyboard(0)
{
}
//-------------------------------------------------------------------------------------
BaseApplication::~BaseApplication(void)
{
if (mTrayMgr) delete mTrayMgr;
if (mCameraMan) delete mCameraMan;
//Remove ourself as a Window listener
Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this);
windowClosed(mWindow);
delete mRoot;
}
//-------------------------------------------------------------------------------------
bool BaseApplication::configure(void)
{
// Show the configuration dialog and initialise the system
// You can skip this and use root.restoreConfig() to load configuration
// settings if you were sure there are valid ones saved in ogre.cfg
if(mRoot->showConfigDialog())
{
// If returned true, user clicked OK so initialise
// Here we choose to let the system create a default rendering window by passing 'true'
mWindow = mRoot->initialise(true, "TutorialApplication Render Window");
return true;
}
else
{
return false;
}
}
//-------------------------------------------------------------------------------------
void BaseApplication::chooseSceneManager(void)
{
// Get the SceneManager, in this case a generic one
mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
}
//-------------------------------------------------------------------------------------
void BaseApplication::createCamera(void)
{
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");
// Position it at 500 in Z direction
mCamera->setPosition(Ogre::Vector3(0,0,80));
// Look back along -Z
mCamera->lookAt(Ogre::Vector3(0,0,-300));
mCamera->setNearClipDistance(5);
mCameraMan = new OgreBites::SdkCameraMan(mCamera); // create a default camera controller
}
//-------------------------------------------------------------------------------------
void BaseApplication::createFrameListener(void)
{
Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
OIS::ParamList pl;
size_t windowHnd = 0;
std::ostringstream windowHndStr;
mWindow->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
mInputManager = OIS::InputManager::createInputSystem( pl );
mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));
mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this);
//Set initial mouse clipping size
windowResized(mWindow);
//Register as a Window listener
Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
mTrayMgr = new OgreBites::SdkTrayManager("InterfaceName", mWindow, mMouse, this);
mTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
mTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
mTrayMgr->hideCursor();
// create a params panel for displaying sample details
Ogre::StringVector items;
items.push_back("cam.pX");
items.push_back("cam.pY");
items.push_back("cam.pZ");
items.push_back("");
items.push_back("cam.oW");
items.push_back("cam.oX");
items.push_back("cam.oY");
items.push_back("cam.oZ");
items.push_back("");
items.push_back("Filtering");
items.push_back("Poly Mode");
mDetailsPanel = mTrayMgr->createParamsPanel(OgreBites::TL_NONE, "DetailsPanel", 200, items);
mDetailsPanel->setParamValue(9, "Bilinear");
mDetailsPanel->setParamValue(10, "Solid");
mDetailsPanel->hide();
mRoot->addFrameListener(this);
}
//-------------------------------------------------------------------------------------
void BaseApplication::destroyScene(void)
{
}
//-------------------------------------------------------------------------------------
void BaseApplication::createViewports(void)
{
// Create one viewport, entire window
Ogre::Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(
Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
}
//-------------------------------------------------------------------------------------
void BaseApplication::setupResources(void)
{
// Load resource paths from config file
Ogre::ConfigFile cf;
cf.load(mResourcesCfg);
// Go through all sections & settings in the file
Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
Ogre::String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
Ogre::ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
}
//-------------------------------------------------------------------------------------
void BaseApplication::createResourceListener(void)
{
}
//-------------------------------------------------------------------------------------
void BaseApplication::loadResources(void)
{
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
//-------------------------------------------------------------------------------------
void BaseApplication::go(void)
{
#ifdef _DEBUG
mResourcesCfg = "resources_d.cfg";
mPluginsCfg = "plugins_d.cfg";
#else
mResourcesCfg = "resources.cfg";
mPluginsCfg = "plugins.cfg";
#endif
if (!setup())
return;
mRoot->startRendering();
// clean up
destroyScene();
}
//-------------------------------------------------------------------------------------
bool BaseApplication::setup(void)
{
mRoot = new Ogre::Root(mPluginsCfg);
setupResources();
bool carryOn = configure();
if (!carryOn) return false;
chooseSceneManager();
createCamera();
createViewports();
// Set default mipmap level (NB some APIs ignore this)
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
// Create any resource listeners (for loading screens)
createResourceListener();
// Load resources
loadResources();
// Create the scene
createScene();
createFrameListener();
return true;
};
//-------------------------------------------------
OGRE(Object-Oriented Graphics Rendering Engine)是一个开源的3D图形渲染引擎,广泛用于游戏开发和其他需要高质量3D图形的应用。"OGRE配置文件TutorialFramework"是一个学习和实践OGRE引擎使用的教程框架,它包括了几个核心的配置和源代码文件。下面将详细介绍这些文件在OGRE框架中的作用。 1. **BaseApplication.h**: 这是基础应用程序类的头文件,通常包含了OGRE应用的基本设置和管理功能。BaseApplication类通常会处理初始化和清理OGRE渲染环境,加载资源,处理窗口事件,以及提供一个框架来管理场景和渲染循环。开发者可以基于这个基类来创建自己的应用程序,重写或扩展其中的方法以满足特定需求。 2. **BaseApplication.cpp**: 对应于BaseApplication.h的实现文件,包含所有在头文件中声明的函数的具体实现。这可能包括初始化OGRE渲染窗口,设置渲染场景,加载纹理和模型,以及处理用户输入等操作。开发者可以在该文件中添加或修改代码来扩展基本功能。 3. **TutorialApplication.h**: 这是针对OGRE教程应用的特定头文件,它继承自BaseApplication类。这个类可能包含了一些针对教程目的的额外功能或方法,比如特定的场景设置,教程特定的用户交互逻辑,或者对渲染过程的特殊处理。通过这种方式,开发者可以专注于教程的特定目标,而不必关心底层的OGRE引擎配置。 4. **TutorialApplication.cpp**: 对应于TutorialApplication.h的实现文件,这里会实现所有与教程相关的逻辑。这可能包括创建特定的3D对象,添加光照效果,实现动画,或者其他与教程主题相关的内容。开发者可以通过这个文件深入理解OGRE引擎的工作原理和API使用。 在学习和使用这些文件时,开发者通常会经历以下步骤: 1. **理解BaseApplication**: 先了解BaseApplication类如何初始化OGRE环境,设置渲染循环,以及如何处理窗口事件。 2. **扩展BaseApplication**: 根据项目需求,重写或添加方法以实现自定义功能。 3. **学习TutorialApplication**: 分析教程应用如何利用BaseApplication的基础结构,实现特定的3D效果或场景。 4. **实践编写教程**: 在TutorialApplication.cpp中编写代码,按照教程指导进行练习,逐步掌握OGRE引擎的使用。 通过这个"OGRE配置文件TutorialFramework",开发者不仅可以学习到如何配置和管理OGRE项目,还能通过实践来提升对3D图形编程的理解和技能。这个框架为初学者提供了一个良好的起点,同时也为有经验的开发者提供了快速构建新项目的基础。

























- 1

- 粉丝: 0
- 资源: 5
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 超好用的卸载软件HibitUninstaller
- 2024年全国地区工程审计总监职位薪酬调查报告
- 物联网实时操作系统_RT-Thread_学习笔记_辅助教学_1741164527.zip
- 博创杯App_厨艺分享社交平台_1741163838.zip
- 2024年全国地区工程预决算工程师职位薪酬调查报告
- 微服务架构_社区团购_尚上优选_企业级应用_1741166080.zip
- Cron组件能设置能回填
- 永磁同步电机最大转矩电流比控制优化研究:基于高频信号注入法的仿真分析与实践探索,基于高频信号注入法的永磁同步电机最大转矩电流比控制算法的在线参数辨识与MATLAB Simulink仿真研究,永磁同步电
- 物联网_智能家居_BS_SmartHome_应用场景_1741164215.zip
- 物联网_智能硬件_数据采集_应用_1741164785.zip
- 物联网_万联平台_统一设备管理_业务系统构建_1741164869.zip
- 机器人开发教程&案例-2025.zip
- 基于模糊PID控制算法的双容水箱液位精确调控设计与Simulink仿真实验,基于模糊PID算法的双容水箱液位控制系统的设计与仿真实验报告,基于模糊pid的双容水箱设计 1.双容水箱液位控制系统 基于模
- C#实现三菱FX5U PLC通信控制:实例展示,包含辅助继电器读写、单双子读写、IO监控与报警显示功能,C#实现三菱FX5U PLC通信控制:实例展示,包含辅助继电器读写、单双子读写、IO监控与报警显
- delphi 实现的 走马灯效果.rar
- 标题:基于SVPWM技术的直接转矩控制(DTC-SVM)算法仿真研究及MATLAB Simulink模型构建 该标题满足了您的要求,涵盖了永磁同步电机控制算法的核心理念-空间电压矢量调制(SVPW



- 1
- 2
- 3
前往页