zoukankan      html  css  js  c++  java
  • [转]使用RenderQueueListener针对不同的渲染组改变摄像机的裁剪面

    http://ogre3d.org/forums/viewtopic.php?f=2&t=30450

    I am currently working on a small project where I have to render objects back-to-front, and clear the depth buffer between each rendered object. After some digging on the wiki and the forum, I was led to believe that a combination of a frame listener and render queue listeners (one for each object rendered) would be able to solve this problem.


    Basically, what I have done is this:
    I have one registered frame listener, that is responsible for sorting a list of the objects to be rendered in back-to-front order. Each object also has its own render queue listener, that is added to the scene manager on start-up, and the frame listener sets the render queue group ID of each listener in ascending order (one unique id per object) after sorting the list.
    The code of the frame listener is tested, and appears to be working as intended (far away objects in the beginning of the list, with low render queue group ID's).


    The render queue listener, in turn, tests if queueGroupID = id, and if so calculates the near and far clipping distances needed to be able to render the object without clipping it, set the camera's clipping distances to these values and then clear the depth buffer:

    class CCustomRenderQueueListener : public Ogre::RenderQueueListener
    {
      void CObject::RenderQueueListener::renderQueueStarted(uint8 queueGroupID, const String &, bool &)
      {
        if (queueGroupId == id)
        {
          oldNear = cam->getNearClipDistance();
          oldFar = cam->getFarClipDistance();
    
          // Calculate near and far clipping distances here
    
          cam->setFarClipDistance(farClip);
          cam->setNearClipDistance(nearClip);
          Root::getSingleton().getRenderSystem()->clearFrameBuffer(FBT_DEPTH);
        }
      }
    
      void CCustomRenderQueueListener::renderQueueEnded(uint8 queueGroupId, const String &, bool &)
      {
        if (queueGroupId == id)
        {
          cam->setNearClipDistance(oldNear);
          cam->setFarClipDistance(oldFar);
        }
      }
    
      // Some other stuff here
    };

    在ogre初始后将RenderQueueListener添加到场景管理器中。

    // 设置RenderQueueListener
    CCustomRenderQueueListener* pCustomRenderQueueListener = new CCustomRenderQueueListener;
    m_pSceneManager->addRenderQueueListener(pCustomRenderQueueListener);

  • 相关阅读:
    plsql学习笔记1
    UC 学习之 Linux和C语言的读写比较
    theos遇到*** first argument to `word' function must be greater than 0.的错误咋办~
    最近碰到的小麻烦和解决方式~
    在iOS开发中遇到NSTextField输入后,键盘无法收回的情况咋办~~
    使用nstask的心得体会(转载)
    COCOA中NSOpenPanel的用法
    gdb关闭栈保护
    OSX中编译ideviceinstaller中遇到的问题和解决办法
    stackoverflow中一篇关于让App在后台运行的很好的讨论问答。
  • 原文地址:https://www.cnblogs.com/pulas/p/2351328.html
Copyright © 2011-2022 走看看