// this function is obsoleted, use ParaMovie::TakeScreenShot3 instead. bool ParaMovie::RenderToTexture(const char* filename, int width, int height) { // code no longer used. it just provides an example of calling render to texture. #if 0 //#include "AutoCamera.h" //#include "SceneObject.h" //#include "FrameRateController.h" LPDIRECT3DDEVICE9 pd3dDevice = CGlobals::GetRenderDevice(); if(pd3dDevice == 0) return false; CSceneObject* pScene = CGlobals::GetScene(); LPDIRECT3DTEXTURE9 m_pRenderTarget = NULL; LPDIRECT3DSURFACE9 m_pRenderTargetSurface = NULL; LPDIRECT3DSURFACE9 m_pDepthSurface = NULL; D3DVIEWPORT9 oldViewport; D3DFORMAT colorFormat = D3DFMT_A8R8G8B8; D3DFORMAT zFormat = D3DFMT_D24S8; // render the scene if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { if(FAILED(pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, colorFormat, D3DPOOL_DEFAULT, &m_pRenderTarget, NULL))) return false; if(FAILED(m_pRenderTarget->GetSurfaceLevel(0, &m_pRenderTargetSurface))) return false; if(FAILED(pd3dDevice->CreateDepthStencilSurface(width, height, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, FALSE, &m_pDepthSurface, NULL))) return false; ////////////////////////////////////////////////////////////////////////// // Render to the reflection map LPDIRECT3DSURFACE9 pOldRenderTarget = CGlobals::GetDirectXEngine().GetRenderTarget(); CGlobals::GetDirectXEngine().SetRenderTarget(0, m_pRenderTargetSurface); CBaseCamera* pCamera = pScene->GetCurrentCamera(); float fOldAspectRatio = pCamera->GetAspectRatio(); pCamera->SetAspectRatio((float)width/(float)height); pd3dDevice->GetViewport(&oldViewport); D3DVIEWPORT9 newViewport; newViewport.X = 0; newViewport.Y = 0; newViewport.Width = width; newViewport.Height = height; newViewport.MinZ = 0.0f; newViewport.MaxZ = 1.0f; pd3dDevice->SetViewport(&newViewport); // set depth surface LPDIRECT3DSURFACE9 pOldZBuffer = NULL; if(FAILED(pd3dDevice->GetDepthStencilSurface(&pOldZBuffer))) { OUTPUT_LOG("GetDepthStencilSurface failed\r\n"); return false; } pd3dDevice->SetDepthStencilSurface( m_pDepthSurface ); ///////////////////////////////////////////////////////////////////////// /// render /// clear to scene pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L ); if(pScene->IsSceneEnabled()) { ///-- set up effects parameters ((CAutoCamera*)pCamera)->UpdateViewProjMatrix(); pScene->AdvanceScene(0); } ////////////////////////////////////////////////////////////////////////// // Restore to old settings D3DXIMAGE_FILEFORMAT FileFormat = D3DXIFF_JPG; D3DXSaveTextureToFile(filename, FileFormat, m_pRenderTarget, NULL); // restore old view port pd3dDevice->SetViewport(&oldViewport); pCamera->SetAspectRatio(fOldAspectRatio); pd3dDevice->SetDepthStencilSurface( pOldZBuffer); SAFE_RELEASE(pOldZBuffer); CGlobals::GetDirectXEngine().SetRenderTarget(0, pOldRenderTarget); SAFE_RELEASE(m_pRenderTargetSurface); SAFE_RELEASE(m_pDepthSurface); SAFE_RELEASE(m_pRenderTarget); pd3dDevice->EndScene(); } #endif return true; }
void CEnvironmentSim::Simulate(double dTimeDelta) { if(dTimeDelta<=0) return; CSceneObject* pScene = CGlobals::GetScene(); if((pScene == NULL) || pScene->IsScenePaused() || (!(pScene->IsSceneEnabled())) ) return; // physics engine frame move. CGlobals::GetPhysicsWorld()->StepSimulation(dTimeDelta); /** advance the game time */ g_gameTime.FrameMoveDelta((float)dTimeDelta); // advance time of day pScene->GetSunLight().AdvanceTimeOfDay((float)dTimeDelta); /** Check load physics around the current player and the camera position * this is very game specific. It only ensures that physics object around the current player and camera is loaded. */ CBipedObject* pPlayer = pScene->GetCurrentPlayer(); int nPointCount = 0; CShapeSphere points[2]; if(pPlayer) { points[nPointCount].Set(pPlayer->GetPosition(), pPlayer->GetPhysicsRadius()*2.f); nPointCount++; } if(pScene->GetCurrentCamera()) { points[nPointCount].Set(pScene->GetCurrentCamera()->GetEyePosition(), pScene->GetCurrentCamera()->GetNearPlane()*2); nPointCount++; } CheckLoadPhysics(points, nPointCount); UpdateGameObjects(dTimeDelta); { PERF1("EnvSim::Frame Move Sentient Objects"); for (auto itCur = pScene->GetSentientObjects().begin(); itCur != pScene->GetSentientObjects().end();) { IGameObject* pObj = (*itCur); if (!pObj) { itCur = pScene->GetSentientObjects().erase(itCur); OUTPUT_LOG("warn: invalid weak ref found in pScene->GetSentientObjects()\n"); continue; } else { itCur++; } if(pObj->GetSimTag() != SIM_TAG_FINISHED) { pScene->SetCurrentActor((CBaseObject*)pObj); if(pObj->GetSimTag() == SIM_TAG_START) { // generate way points pObj->PathFinding(dTimeDelta); // move the biped according to way point commands pObj->AnimateBiped(dTimeDelta); } // apply AI controller if(pObj->GetAIModule()) pObj->GetAIModule()->FrameMove((float)dTimeDelta); if(!pObj->GetPerceiveList().empty()) pObj->On_Perception(); // call the frame move script if any. pObj->On_FrameMove(); pObj->SetSimTag(SIM_TAG_FINISHED); if(pObj->HasReferences()) { RefList::iterator itCur, itEnd = pObj->GetRefList().end(); for (itCur = pObj->GetRefList().begin(); itCur!=itEnd; ++itCur) { if(itCur->m_tag == 0) { IGameObject* pRefObj = ((CBaseObject*)((*itCur).m_object))->QueryIGameObject(); if(pRefObj!=0 && !pRefObj->IsSentient() && pRefObj->IsGlobal() && (pRefObj->GetSimTag() == SIM_TAG_START)) { ////////////////////////////////////////////////////////////////////////// // update reference object in the terrain tile according to its current position Vector3 vPos = pRefObj->GetPosition(); CTerrainTile * pTile = pScene->GetRootTile()->GetTileByPoint(vPos.x, vPos.z); if(pTile != NULL) { pRefObj->SetTileContainer(pTile); } ////////////////////////////////////////////////////////////////////////// // basic simulation: path finding, etc. pScene->SetCurrentActor((CBaseObject*)pRefObj); // generate way points pRefObj->PathFinding(dTimeDelta); // move the biped according to way point commands pRefObj->AnimateBiped(dTimeDelta); pRefObj->SetSimTag(SIM_TAG_BASIC); } } } } } } if(CGlobals::WillGenReport()) { CGlobals::GetReport()->SetValue("sentient objects", (int)pScene->GetSentientObjects().size()); } } /// frame move each unexploded missile objects. { for (auto pMissile : pScene->GetMissiles()) { if( !pMissile->IsExploded() ) { pMissile->Animate(dTimeDelta); } } } }