zoukankan      html  css  js  c++  java
  • 在Ogre中设置固定流水线的用户自定义裁剪平面的方法

    转载请注明出处!Pulas

    http://www.cnblogs.com/pulas/archive/2012/02/16/2354542.html

    首先自定义一个场景管理器的监听器.

    头文件:

    #ifndef __CustomSceneManagerListener_H__
    #define __CustomSceneManagerListener_H__
    
    #include <Ogre.h>
    
    class CCustomSceneManagerListener : public Ogre::SceneManager::Listener
    {
    public:
    	CCustomSceneManagerListener();
    	~CCustomSceneManagerListener();
     
    public:
    	/** Called prior to searching for visible objects in this SceneManager.
    	@remarks
    		Note that the render queue at this stage will be full of the last
    		render's contents and will be cleared after this method is called.
    	@param source The SceneManager instance raising this event.
    	@param irs The stage of illumination being dealt with. IRS_NONE for 
    		a regular render, IRS_RENDER_TO_TEXTURE for a shadow caster render.
    	@param v The viewport being updated. You can get the camera from here.
    	*/
    	virtual void preFindVisibleObjects(Ogre::SceneManager* source, Ogre::SceneManager::IlluminationRenderStage irs, Ogre::Viewport* v);
    
    public:
    	/** Sets the user clipping region.
    	*/
    	virtual void setClipPlanes(const Ogre::PlaneList& clipPlanes);
    
    	/** Add a user clipping plane. */
    	virtual void addClipPlane (const Ogre::Plane &p);
    	/** Add a user clipping plane. */
    	virtual void addClipPlane (Ogre::Real A, Ogre::Real B, Ogre::Real C, Ogre::Real D);
    
    	/** Clears the user clipping region.
    	*/
    	virtual void resetClipPlanes();
    
    	void enableClipPlane(bool bEnable);
    
    	bool isClipPlaneEnabled();
    
    protected:
    	// Recording user clip planes
    	Ogre::PlaneList m_ClipPlanes;
    
    	bool m_bEnableClipPlane;
    };
    
    #endif
     
    实现文件:
    #include "stdafx.h"
    #include "CustomSceneManagerListener.h"
    using namespace Ogre;
    
    CCustomSceneManagerListener::CCustomSceneManagerListener() : m_bEnableClipPlane(true)
    {
    }
    
    CCustomSceneManagerListener::~CCustomSceneManagerListener()
    {
    }
    
    void CCustomSceneManagerListener::preFindVisibleObjects(Ogre::SceneManager* source, Ogre::SceneManager::IlluminationRenderStage irs, Ogre::Viewport* v)
    {
    	if (m_bEnableClipPlane)
    	{
    		Ogre::Root::getSingletonPtr()->getRenderSystem()->setClipPlanes(m_ClipPlanes);
    	}
    }
    
    //---------------------------------------------------------------------
    void CCustomSceneManagerListener::addClipPlane (const Plane &p)
    {
    	m_ClipPlanes.push_back(p);
    }
    //---------------------------------------------------------------------
    void CCustomSceneManagerListener::addClipPlane (Real A, Real B, Real C, Real D)
    {
    	addClipPlane(Plane(A, B, C, D));
    }
    //---------------------------------------------------------------------
    void CCustomSceneManagerListener::setClipPlanes(const PlaneList& clipPlanes)
    {
    	if (clipPlanes != m_ClipPlanes)
    	{
    		m_ClipPlanes = clipPlanes;
    	}
    }
    //---------------------------------------------------------------------
    void CCustomSceneManagerListener::resetClipPlanes()
    {
    	if (!m_ClipPlanes.empty())
    	{
    		m_ClipPlanes.clear();
    	}
    }
    
    void CCustomSceneManagerListener::enableClipPlane( bool bEnable )
    {
    	m_bEnableClipPlane = bEnable;
    }
    
    bool CCustomSceneManagerListener::isClipPlaneEnabled()
    {
    	return m_bEnableClipPlane;
    }
     
    在初始化完Ogre后,添加自定义裁剪面:
    m_pCustomSceneManagerListener = new CCustomSceneManagerListener;
    mSceneMgr->addListener(m_pCustomSceneManagerListener);
    
    Ogre::Plane SectionClipPlane;
    SectionClipPlane.normal = Ogre::Vector3::NEGATIVE_UNIT_Y;
    SectionClipPlane.d = -4.9;
    m_pCustomSceneManagerListener->addClipPlane(SectionClipPlane);
  • 相关阅读:
    sql server 分组,取每组的前几行数据
    安装vim的ycm
    Linux下管道重定向使用以及Shell编程(操作系统)
    VirtualBox安装及Linux基本操作(操作系统实验一)
    创建表并查看表(数据库实验一)
    SQL SERVER安装(2008)
    ADT图及图的实现及图的应用
    并查集实现及使用
    堆及堆的应用/单调队列/堆排序
    AVL树/线索二叉树
  • 原文地址:https://www.cnblogs.com/pulas/p/2354542.html
Copyright © 2011-2022 走看看