1.Ogre中的随机函数
例如:Real posX = Math::RangeRandom(0.0, 0.7);
Real posY = Math::RangeRandom(0.1, 0.7);
RangeRandom第1个参数是最小底线值,第2个参数是最高限值;也即是:in [fLow,fHigh]
2.字符串与数据类型之间转换
例如:①. 数据类型转换成字符串Ogre::StringConverter::toString(AddCount)
②. 字符串转换成数据类型int z = StringConverter::parseReal(TempValue);
3.对于在监听器创建的资源,销毁创建的plane资源
在附加依赖项中增加strmiids.lib 和 strmbasd.lib
MeshManager::getSingleton().remove( "FloorPlane" );
//节点和实体分离
mtyremarkNode->detachObject(ent_tyremark);
//销毁实体
mSceneMgr->destroyEntity(ent_tyremark->getName());
// 销毁创建的面的结点
pNode_che->removeAndDestroyChild("tyremark");
4.Ogre中添加视频
#include "UtilsOgreDshow.h"
// 视频播放所需要的变量
OgreUtils::DirectShowMovieTexture* dshowMovieTextureSystem;
Ogre::String movieName = "c:/ss.avi";
Ogre::MaterialPtr VideoMat;
Ogre::TextureUnitState* VideoTex;
Ogre::Overlay* mVideoOverlay;
void InitVideo()
{
dshowMovieTextureSystem = new OgreUtils::DirectShowMovieTexture(768,576);
dshowMovieTextureSystem->loadMovie(movieName);
VideoMat = Ogre::MaterialManager::getSingletonPtr()->create("MovieMaterial",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
VideoTex = VideoMat->getTechnique(0)->getPass(0)->createTextureUnitState();
VideoTex ->setTextureName(dshowMovieTextureSystem->getMovieTexture()->getName() );
VideoMat->load();
// ResourceGroupManager::getSingleton().initialiseResourceGroup("Intro");
OverlayManager& VideooverlayMgr = OverlayManager::getSingleton();
Create a panel
Ogre::OverlayManager* VideoOM = Ogre::OverlayManager::getSingletonPtr();
Ogre::OverlayContainer* Videopanel = static_cast<OverlayContainer*>(VideooverlayMgr.createOverlayElement("Panel", "PanelName"));
// Create Panel, Overlay, and Show the Overlay
Videopanel->setMetricsMode(Ogre::GMM_RELATIVE);
Videopanel->setPosition(0, 0);
Videopanel->setDimensions(1, 1);
Videopanel->setColour(Ogre::ColourValue(1.0,1.0,1.0,1.0));
Videopanel->setMaterialName(VideoMat->getName());
mVideoOverlay = VideoOM->create("OverlayName");
mVideoOverlay->add2D(Videopanel);
mVideoOverlay->setZOrder(600);
mVideoOverlay->show();
dshowMovieTextureSystem->playMovie();
}
别忘了在framelistener中的构造函数中调用 InitViedo()函数
接着在framelistener中,刷新每 一帧:
dshowMovieTextureSystem->updateMovieTexture();
if (IdleStatus == true)
{
if (dshowMovieTextureSystem->isPlayingMovie() == false)
{
dshowMovieTextureSystem->rewindMovie();
mVideoOverlay->show();
dshowMovieTextureSystem->playMovie();
}
}
最后,在程序退出时要释放掉资源
if(this->mKeyboard->isKeyDown(OIS::KC_ESCAPE))
{
VideoTex ->setTextureName("");
VideoMat->unload();
if (dshowMovieTextureSystem!=NULL)
{
delete dshowMovieTextureSystem;
dshowMovieTextureSystem = NULL;
}
return false;
}
PS:基于Direct9x.
UtilsOgreDshow.h UtilsOgreDshow_private.h UtilsOgreDshow.cpp
5.如何不让OGRE程序的配置对话框也显示
在Application中继承configure()函数,在判断条件中加 mRoot->restoreConfig()
如下:
bool configure(void)
{
if( mRoot->restoreConfig() || mRoot->showConfigDialog())
{
mWindow = mRoot->initialise(true);
return true;
}
else
{
return false;
}
}
6.如何去除OGRE中的帧数界面和OGRE标志
在创建帧监听时调用 this->mFrameListener->showDebugOverlay(false);