博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
《Pro Ogre 3D Programming》 读书笔记 之 第四章 开始使用OGRE (转)
阅读量:5095 次
发布时间:2019-06-13

本文共 5576 字,大约阅读时间需要 18 分钟。

日志系统

日志记录了基于ogre的程序每次运行时的所有事件,系统初始化,状态,性能信息。输出的内容被放在磁盘文件上,文件缺省名是ogre.log。也可以手动显示创建日志系统,这需要在创建Root对象之前实施。
// create an instance of LogManager prior to using LogManager::getSingleton()
LogManager* logMgr = new LogManager;
Log *log = LogManager::getSingleton().createLog("mylog.log", true, true, false);
// third param is not used since we already created a log in the previous step
Root *root = new Root("", "");
可以用Ogre LogManager注册一个Log Listener, 以任何方式重定向log data。可以用这种方式来屏蔽任何日志信息。然后还一个更简单的方法达到上述目的:在实例化Root之前,当实例化一个LogManager后,不调用createLog()方法。
以下是实现日志信息截流的代码片断:
class MyLogListener : public LogListener
{
public:
void write (const String& name, const String& message,
LogMessageLevel level, bool maskDebug)
{
// redirect log output here as needed
};
MyLogListener *myListener = new MyLogListener;
// this is the same as calling LogManager::getSingletonPtr() after the
// LogManager has first been instanced; the same pointer value is returned
LogManager *logMgr = new LogManager;
LogMgr->addListener(myListener);
logMgr->createLog("mylog.log", true, false, true);
logMgr->setLogDetail(LL_NORMAL);
Root *root = new Root("", "", "mylog.log");
Ogre手动初始化
int main(int argc, char *argv[])
{

 // tell Root not to load from any plugins or settings file

 Root *root = new Root("", "");

 // Load feature plugins. Scene managers will register

 // themselves for all scene types they support
 root->loadPlugin("Plugin_CgProgramManager");
 root->loadPlugin("Plugin_OctreeSceneManager");

 // load rendersystem plugin(s). The order is important in that GL

 // should be available on on platforms, while D3D9 would be available
 // only on Windows -- the try/catch will intercept the exception in this
 // case where D3D9 is not available and continue gracefully.
 try {
  root->loadPlugin("RenderSystem_GL");
  root->loadPlugin("RenderSystem_Direct3D9");
 }
 catch (...) {}

 try {

  // We'll simulate the selection of a rendersystem on an arbirtary basis; normally
  // you would have your own code to present the user with options and select the
  // rendersystem on that basis. Since a GUI is beyond the scope of this example, we'll
  // just assume the user selected OpenGL.
  RenderSystemList *rList = root->getAvailableRenderers();
  RenderSystemList::iterator it = rList->begin();
  RenderSystem *rSys = 0;

  while (it != rList->end()) {

   
   rSys = *(it++);
   if (rSys->getName().find("OpenGL")) {
   
    root->setRenderSystem(rSys);
    break;
   }
  }

  // check to see if a render system was selected; if we reached the end of the list

  // without selecting a render system then none was found.
  if (rSys == 0) {
   delete root;
   std::cerr << "No RenderSystem available, exiting..." << std::endl;
   return -1;
  }

  // We can initialize Root here if we want. "false" tells Root NOT to create

  // a render window for us
  root->initialise(false);

  // set up the render window with all default params

  RenderWindow *window = rSys->createRenderWindow(
   "Manual Ogre Window", // window title
   800,     // window width, in pixels
   600,     // window height, in pixels
   false,     // fullscreen or not
   0);      // use defaults for all other values

  // from here you can set up your camera and viewports as normal

  // get a pointer to the default base scene manager -- sufficient for our purposes
  SceneManager *sceneMgr = root->createSceneManager(ST_GENERIC);

  // create a single camera, and a viewport that takes up the whole window (default behavior)

  Camera *camera = sceneMgr->createCamera("MainCam");
  Viewport *vp = window->addViewport(camera);
  vp->setDimensions(0.0f, 0.0f, 1.0f, 1.0f);
  camera->setAspectRatio((float)vp->getActualWidth() / (float) vp->getActualHeight());
  camera->setFarClipDistance(1000.0f);
  camera->setNearClipDistance(5.0f);

  // Run the manual render loop. Since we are not using a frame listener in this case, we

  // will count to 15 seconds and then instead of exiting, we'll change the render window settings
  // and re-initialize it.
  bool renderLoop = true;
  Timer *timer = Ogre::PlatformManager::getSingleton().createTimer();
  timer->reset();
  float s = 0.0f;

  while (renderLoop && window->isActive()) {

   renderLoop = root->renderOneFrame();

   // accumulate total elapsed time

   s += (float)timer->getMilliseconds() / 1000.0f;

   // if greater than 15 seconds, break out of the loop

   if (s >= 15.0f)
    renderLoop = false;

   // we must call the windowing system's message pump each frame to

   // allow Ogre to process messages
   //PlatformManager::getSingleton().messagePump();
  }
 }
 catch (Exception &e) {
  std::cerr << e.getFullDescription() << std::endl;
 }

 delete root;

 return 0;
}

视口

通过视口上的一点与相机的原点产生世界空间中的一条光线
// x and y are in "normalized" (0.0 to 1.0) screen coordinates
Ray getCameraToViewportRay(Real x, Real y) const;

视口,创建多个视口,通过Z序(越高越在上) 确定覆盖效果,每个视口可以有不同的背景。

// assume window is a valid pointer to an existing render window, and
// a valid pointer to an existing camera instance
Viewport *vpTop, *vpBottom;
// second parameter is z-order, remaining params are position and size,
vpBottom = window->addViewport(camera, 0);
// create a smaller viewport on top, in the center, 25% of main vp size
vpTop = window->addViewport(camera, 1,
0.375f, 0.375f,
0.25, 0.25);
// set the background of the top window to blue (the default is black
// need to set the bottom window explicitly)
vpTop->setBackgroundColour(ColourValue(0.0f, 0.0f, 1.0f));
// an alternate way to set the color is to use the manifest constant
// vpTop->setBackgroundColour(ColourValue::Blue);
在多视口情况下,overlay缺省在每个视口中渲染。可以关掉。Skybox, Shadow也是如此。
vpTop->setOverlaysEnabled(false);
vpTop->setSkiesEnabled(false);
vpTop->setShadowsEnabled(true);

转载于:https://www.cnblogs.com/hf621222/archive/2013/05/27/3101088.html

你可能感兴趣的文章
AIO 开始不定时的抛异常: java.io.IOException: 指定的网络名不再可用
查看>>
MyBaits动态sql语句
查看>>
HDU4405(期望DP)
查看>>
拉格朗日乘子法 那些年学过的高数
查看>>
vs code 的便捷使用
查看>>
Spring MVC @ResponseBody返回中文字符串乱码问题
查看>>
用户空间与内核空间,进程上下文与中断上下文[总结]
查看>>
JS 中的跨域请求
查看>>
JAVA开发环境搭建
查看>>
vim插件ctags的安装和使用
查看>>
mysql基础语句
查看>>
Oracle中的rownum不能使用大于>的问题
查看>>
[Data Structure & Algorithm] 有向无环图的拓扑排序及关键路径
查看>>
git 常用命令
查看>>
cassandra vs mongo (1)存储引擎
查看>>
Visual Studio基于CMake配置opencv1.0.0、opencv2.2
查看>>
Vue音乐项目笔记(三)
查看>>
遍历Map对象
查看>>
计算剪贴板里仿制的代码行数
查看>>
MySQL索引背后的数据结构及算法原理
查看>>