int CMiniSceneGraph::RenderSelection(DWORD dwSelection, double dTimeDelta) { SceneState& sceneState = m_sceneState; sceneState.m_nCurRenderGroup = dwSelection; int nObjCount = 0; if(CHECK_SELECTION(RENDER_SKY_BOX)) { CSkyMesh * pSky = GetCurrentSky(); if(pSky!=0) { // TODO: use culling algorithms pSky->Draw(&sceneState); ++nObjCount; } } if(CHECK_SELECTION(RENDER_MESH_FRONT_TO_BACK)) { /// draw solid object rendering list from front to back. if(!sceneState.listPRSolidObject.empty()) { sceneState.fAlphaFactor=1.0f; nObjCount += RenderList(sceneState.listPRSolidObject, sceneState); } } if(CHECK_SELECTION(RENDER_MESH_TRANSPARENT)) { ////////////////////////////////////////////////////////////////////////// // render without hardware occlusion testing if(!sceneState.listPRTransparentObject.empty()) nObjCount += RenderList(sceneState.listPRTransparentObject, sceneState); } if(CHECK_SELECTION(RENDER_MESH_BACK_TO_FRONT)) { // draw transparent object rendering list from back to front. if(!sceneState.listPRSmallObject.empty()) { ////////////////////////////////////////////////////////////////////////// // render without hardware occlusion testing nObjCount += RenderList(sceneState.listPRSmallObject, sceneState); sceneState.fAlphaFactor=1.0f; } } if(CHECK_SELECTION(RENDER_CHARACTERS)) { /// -- Draw all characters including the player itself. if(!sceneState.listPRBiped.empty()) { CGlobals::GetEffectManager()->BeginEffect(TECH_CHARACTER, &(sceneState.m_pCurrentEffect)); /** sort by the primary asset : in this case it's MA */ SceneState::List_PostRenderObject_Type::iterator itCurCP, itEndCP = sceneState.listPRBiped.end(); for( itCurCP = sceneState.listPRBiped.begin(); itCurCP != itEndCP; ++ itCurCP) { if(itCurCP->m_pRenderObject!=0) { sceneState.SetCameraToCurObjectDistance((*itCurCP).m_fObjectToCameraDistance); ((*itCurCP).m_pRenderObject)->Draw(&sceneState); ++nObjCount; } } } } if(CHECK_SELECTION(RENDER_BOUNDINGBOX)) { if(GetBatchedElementDrawer()) { // draw the oriented bounding box for debugging and editing. { GetBatchedElementDrawer()->SetDefaultColor(PARAVECTOR3(1.f,0,0)); SceneState::List_PostRenderObject_Type::iterator itCurCP, itEndCP = sceneState.listPRSolidObject.end(); for(itCurCP = sceneState.listPRSolidObject.begin(); itCurCP !=itEndCP; ++itCurCP) { IViewClippingObject* pViewClippingObject = (*itCurCP).m_pRenderObject->GetViewClippingObject(); pViewClippingObject->DebugDraw(GetBatchedElementDrawer()); ++nObjCount; } } { GetBatchedElementDrawer()->SetDefaultColor(PARAVECTOR3(0, 0, 1.f)); DWORD dwColor = COLOR_ARGB(255,0,0,255); SceneState::List_AlphaPostRenderObject_Type::iterator itCurCP, itEndCP = sceneState.listPRSmallObject.end(); for(itCurCP = sceneState.listPRSmallObject.begin(); itCurCP !=itEndCP; ++itCurCP) { IViewClippingObject* pViewClippingObject = (*itCurCP).m_pRenderObject->GetViewClippingObject(); pViewClippingObject->DebugDraw(GetBatchedElementDrawer()); ++nObjCount; } } { SceneState::List_PostRenderObject_Type::iterator itCurCP, itEndCP = sceneState.listPRBiped.end(); for( itCurCP = sceneState.listPRBiped.begin(); itCurCP != itEndCP; ++ itCurCP) { if(itCurCP->m_pRenderObject!=0) { GetBatchedElementDrawer()->SetDefaultColor(PARAVECTOR3(0, 0, 1.f)); ((CBipedObject*)((*itCurCP).m_pRenderObject))->DebugDraw(GetBatchedElementDrawer()); GetBatchedElementDrawer()->SetDefaultColor(PARAVECTOR3(0, 1.f, 0)); ((CBipedObject*)((*itCurCP).m_pRenderObject))->GetPhysicsBBObj()->DebugDraw(GetBatchedElementDrawer()); ++nObjCount; } } } if(! m_pBatchedElementDraw->IsEmpty()) { // Turn off effect: CGlobals::GetEffectManager()->BeginEffect(TECH_NONE, &(sceneState.m_pCurrentEffect)); m_pBatchedElementDraw->DrawAll(); } } } if(CHECK_SELECTION(RENDER_TRANSLUCENT_FACE_GROUPS)) { if(!sceneState.GetFaceGroups()->IsEmpty()) { if(!sceneState.GetFaceGroups()->IsSorted()) { sceneState.GetFaceGroups()->Sort(GetCurrentCamera()->GetEyePosition()-GetRenderOrigin()); } CGlobals::GetEffectManager()->BeginEffect(TECH_SIMPLE_MESH_NORMAL); CEffectFile* pEffectFile = CGlobals::GetEffectManager()->GetCurrentEffectFile(); //if(pEffectFile) { sceneState.GetFaceGroups()->Render(); } } } if(CHECK_SELECTION(RENDER_PARTICLES)) { bool bEffectSet = false; Vector3 vRenderOrigin = GetRenderOrigin(); int nPSInstancesCount = 0; // statistic:number of particles instances int nParticlesCount = 0; // statistic:number of particles SceneState::List_ParticleSystemPtr_Type::iterator itCurCP; for (itCurCP = sceneState.listParticleSystems.begin(); itCurCP != sceneState.listParticleSystems.end();) { ParticleSystem* PS = (*itCurCP).get(); map <void*, ParticleList*>& instances = PS->m_instances; map<void*, ParticleList*>::iterator iter; bool bHasInstance = false; for (iter = instances.begin(); iter!=instances.end();) { ParticleList* instancePS = iter->second; if(instancePS->m_pSceneState == (&sceneState)) { bHasInstance = true; } else { ++iter; continue; } if(instancePS->m_bUpdated == false) { if(instancePS->m_bUseAbsCord) { /// for globally un-updated instances, animate the remaining particles Vector3 vRenderOriginOffset = (instancePS->m_vLastRenderOrigin) - vRenderOrigin; instancePS->m_vLastRenderOrigin = (vRenderOrigin);// update render origin if(PS->AnimateExistingParticles((float)dTimeDelta, vRenderOriginOffset, instancePS)) { if(!bEffectSet){ CGlobals::GetEffectManager()->BeginEffect(TECH_PARTICLES, &(sceneState.m_pCurrentEffect)); bEffectSet = true; } PS->drawInstance(instancePS); if(CGlobals::WillGenReport()) nParticlesCount += (int)instancePS->particles.size(); ++iter; } else { // delete the particle system instance, if there is no particle instances left. SAFE_DELETE(instancePS) ; iter = instances.erase(iter); } } else { /// for local un-updated instances, delete the instance. SAFE_DELETE(instancePS) ; iter = instances.erase(iter); } } else { instancePS->m_bUpdated = false; if(instancePS->m_bUseAbsCord) { /// for globally updated instances, just draw it. if(instancePS->m_bRender) { if(!bEffectSet){ CGlobals::GetEffectManager()->BeginEffect(TECH_PARTICLES, &(sceneState.m_pCurrentEffect)); bEffectSet = true; } PS->drawInstance(instancePS); instancePS->m_bRender = false; if(CGlobals::WillGenReport()) nParticlesCount += (int)instancePS->particles.size(); } ++iter; } else { /// for local updated instances, ignore it, since it has already been draw with the model to which it is attached. ++iter; if(CGlobals::WillGenReport()) nParticlesCount += (int)instancePS->particles.size(); } } } // erase particle system from the list if there is no instance left. if(!bHasInstance) itCurCP = sceneState.listParticleSystems.erase(itCurCP); else { ++ itCurCP; if(CGlobals::WillGenReport()) nPSInstancesCount += (int)instances.size(); } } nObjCount = nParticlesCount; } return nObjCount; }