CFakeObjectEntityManager::FakeObjectMap::iterator CFakeObjectEntityManager::_GetFakeNode(LPCTSTR szNodeName, tEntityNode* pNode, LPCTSTR szCameraName, int nTexWidth, int nTexHeight, LPCTSTR szBackgroundName) { //缺省摄像机的位置 static const float s_fHeight = 0.8f; static const float s_fDistance = 3.2f; static const float s_fPitch = 0.21f; FakeObjectMap::iterator it = m_mapObject.find(szNodeName); if(it != m_mapObject.end()) return it; //不存在,创建 FakeObject newNode; newNode.strName = szNodeName; //-------------------------------------------------- //创建RenderTarget Ogre::TexturePtr ptrTex = Ogre::TextureManager::getSingleton().createManual( Ogre::String(szNodeName) + "_RenderTexture", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, nTexWidth, nTexHeight, 1, 0, Ogre::PF_R8G8B8A8, Ogre::TU_RENDERTARGET, 0); //ptrTex->load(); newNode.ptrRenderTexture = ptrTex; Ogre::RenderTexture* pTexture = ptrTex->getBuffer()->getRenderTarget(); //缺省不刷新 pTexture->setAutoUpdated(false); pTexture->addListener(&g_theListener); //-------------------------------------------------- //放置摄像机 Ogre::SceneManager* pScnManager = CEngineInterface::GetMe()->GetFairySystem()->getSceneManager(); newNode.pCamera = pScnManager->createCamera(Ogre::String(szNodeName) + "_Camera"); //放缩系数 fVector3 fvScale = CEngineInterface::GetMe()->GetSacle(); newNode.fCameraHeight=s_fHeight; newNode.fCameraDistance=s_fDistance; newNode.fCameraPitch=s_fPitch; STRING szUserCameraValue; pNode->Actor_GetObjectProperty(szCameraName, szUserCameraValue); // if(szUserCameraValue.size() > 2 && szUserCameraValue.find(';') != STRING::npos) // { // sscanf(szUserCameraValue.c_str(), "%f;%f", &(newNode.fCameraHeight), &(newNode.fCameraDistance)); // } int Row_Index; Row_Index = atoi(szUserCameraValue.c_str()); const tDataBase* pDBC = g_pDataBase->GetDataBase(DBC_MODEL_PARAMETER); KLAssert(pDBC); const _DBC_MODEL_PARAMETER* pParameter = NULL; pParameter = (const _DBC_MODEL_PARAMETER*)((tDataBase*)pDBC)->Search_Index_EQU(Row_Index); if(pParameter) { newNode.fCameraHeight = pParameter->nHeight; newNode.fCameraDistance = pParameter->nDistance; } //设置摄像机 _UpdateCamera(newNode); newNode.pCamera->setNearClipDistance(10.f); newNode.pCamera->setAspectRatio((float)nTexWidth/nTexHeight); newNode.pCamera->setFOVy(Ogre::Degree(45.0f)); // 经验值 newNode.pCamera->setProjectionType(Ogre::PT_PERSPECTIVE); //透视投影 (平行投影 Ogre::PT_ORTHOGRAPHIC) //-------------------------------------------------- //创建ViewPort newNode.pViewPort = pTexture->addViewport(newNode.pCamera, 1); newNode.pViewPort->setClearEveryFrame(true); newNode.pViewPort->setBackgroundColour(Ogre::ColourValue(0,0,0,0)); newNode.pViewPort->setOverlaysEnabled(false); newNode.pViewPort->setSkiesEnabled(false); newNode.pViewPort->setShadowsEnabled(false); //-------------------------------------------------- //创建rectangle(如果纹理名称不为空并且所需的material template存在) Ogre::String backgroundTexName(szBackgroundName); Ogre::MaterialPtr originMat = Ogre::MaterialManager::getSingleton().getByName("UIModelBackground"); if (false == backgroundTexName.empty() && false == originMat.isNull()) { newNode.pRectange = new Ogre::Rectangle2D(true); newNode.pRectange->setCorners(-1.0f, 1.0f, 1.0f, -1.0f); Ogre::String cloneMatName = Ogre::String(szNodeName) + "_Rectangle"; Ogre::MaterialPtr cloneMat = Ogre::MaterialManager::getSingleton().getByName(cloneMatName); if (cloneMat.isNull()) { cloneMat = originMat->clone(cloneMatName); if (cloneMat->getNumTechniques()) { Ogre::Technique* tech = cloneMat->getTechnique(0); if (tech->getNumPasses()) { Ogre::Pass* pass = tech->getPass(0); if (pass->getNumTextureUnitStates()) { Ogre::TextureUnitState* tex = pass->getTextureUnitState(0); tex->setTextureName(szBackgroundName); } } } } newNode.pRectange->setMaterial(cloneMat->getName()); newNode.pRectange->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND); newNode.pRectange->setVisibilityFlags(Fairy::OVF_GUI_ELEMENTS); // 设置boundingbox为无限大,以防被camera剔除掉(默认的包围盒大小为-1,1) newNode.pRectange->setBoundingBox( Ogre::AxisAlignedBox( Ogre::Vector3(Ogre::Math::NEG_INFINITY, Ogre::Math::NEG_INFINITY, Ogre::Math::NEG_INFINITY), Ogre::Vector3(Ogre::Math::POS_INFINITY, Ogre::Math::POS_INFINITY, Ogre::Math::POS_INFINITY) ) ); Ogre::SceneNode* parentNode = CEngineInterface::GetMe()->GetFairySystem()->getBaseSceneNode()->createChildSceneNode(); parentNode->attachObject(newNode.pRectange); } //-------------------------------------------------- //加入Map m_mapObject.insert(std::make_pair(newNode.strName, newNode)); it = m_mapObject.find(newNode.strName); KLAssert(it != m_mapObject.end()); //加入索引Map m_mapIndexOfViewPort.insert(std::make_pair(newNode.pViewPort, &(it->second))); return it; }