// If there is a PVS, this tags the associated things. Otherwise, // it tags everything. void d3d_TagVisibleLeaves(const ViewParams& Params) { //go through and queue all objects and the world VisibleSet *pVisibleSet = &g_VisibleSet; // Initialize frame for the world if (g_Device.m_pRenderWorld) { if (g_CV_DrawWorld) g_Device.m_pRenderWorld->StartFrame(Params); } // if(!g_CV_LockPVS) { // Rebuild the visible set. pVisibleSet->ClearSet(); CountAdder cntAdd(&g_pStruct->m_Time_Vis); d3d_QueueObjectsInFrustum(Params); } // Handle the new rendering path. if (g_Device.m_pRenderWorld) { if (g_CV_DrawWorld) g_Device.m_pRenderWorld->Draw(Params); else g_Device.m_pRenderWorld->Release(); } }
void DistantLand::renderReflectedStatics(const D3DXMATRIX *view, const D3DXMATRIX *proj) { // Select appropriate static clipping distance D3DXMATRIX ds_proj = *proj, ds_viewproj; float zn = 4.0f, zf = Configuration.DL.NearStaticEnd * kCellSize; // Don't draw beyond fully fogged distance; early out if frustum is empty zf = std::min(fogEnd, zf); if(zf <= zn) return; // Create a clipping frustum for visibility determination editProjectionZ(&ds_proj, zn, zf); ds_viewproj = (*view) * ds_proj; // Cull sort and draw VisibleSet visReflected; ViewFrustum range_frustum(&ds_viewproj); D3DXVECTOR4 viewsphere(eyePos.x, eyePos.y, eyePos.z, zf); currentWorldSpace->NearStatics->GetVisibleMeshes(range_frustum, viewsphere, visReflected); currentWorldSpace->FarStatics->GetVisibleMeshes(range_frustum, viewsphere, visReflected); currentWorldSpace->VeryFarStatics->GetVisibleMeshes(range_frustum, viewsphere, visReflected); visReflected.SortByState(); device->SetVertexDeclaration(StaticDecl); visReflected.Render(device, effect, effect, &ehTex0, 0, &ehWorld, SIZEOFSTATICVERT); }
DWORD ToolGridVisibleEdit::GetSelectGrid(void) { ui::Manager::_tagINPUTINFO *pInputInfo = ui::Manager::GetInstance()->GetInputInfoBuffer(); //计算选中的格子 static GameSelectRay cSelRay; RECT rc; EditWnd *pEditWnd = CommUI::GetInstance()->GetEditWnd(); pEditWnd->GetWndRect(&rc); cSelRay.CalculateRay(&rc,pEditWnd->GetCamera(),pInputInfo->ptMouse); //显示格子 EditMap *pMap = CommDB::GetInstance()->GetMap(); VisibleSet *pSet = pMap->GetVisibleSet(); DWORD *pVIArray = pSet->GetVisibleIndexArray(); TerrainMesh *pMesh = CommDB::GetInstance()->GetTerrainMesh(); TerrainMesh::_tagGrid *pGrid(NULL); TerrainMesh::_tagVertex *pVertexArray = pMesh->GetVertexList(); D3DXVECTOR3 pos[4]; DWORD dwSelGrid = 0xFFFFFFFF; float fDistance = 100000000.0f; float fTempDist; for(DWORD n = 0; n< pSet->GetVisibleIndexCount(); n++) { DWORD dwGridIndex = pVIArray[n]; pGrid = pMesh->GetGrid(dwGridIndex); for(DWORD v = 0; v < 4; v++) { pos[v] = pVertexArray[pGrid->dwVertexIndex[v]].vPosition; } if (cSelRay.IntersectTri(&pos[0],&pos[1],&pos[2],NULL,&fTempDist)) { if (fTempDist < fDistance) { fDistance = fTempDist; dwSelGrid = dwGridIndex; } } else if (cSelRay.IntersectTri(&pos[0],&pos[2],&pos[3],NULL,&fTempDist)) { if (fTempDist < fDistance) { fDistance = fTempDist; dwSelGrid = dwGridIndex; } } } return dwSelGrid; }
//---------------------------------------------------------------------------- void LinearDepth_Material::Draw(Renderer* renderer, const VisibleSet& visibleSet) { EnvirParamController *curEnvirParam = PX2_GR.GetCurEnvirParamController(); mOverRideOffsetProperty->FillEnabled = true; mOverRideOffsetProperty->Scale = curEnvirParam->GetShadowMap_OffsetPropertyScale(); mOverRideOffsetProperty->Bias = curEnvirParam->GetShadowMap_OffsetPropertyBias(); renderer->SetOverrideOffsetProperty(mOverRideOffsetProperty); const int numVisible = visibleSet.GetNumVisible(); for (int j = 0; j < numVisible; ++j) { Renderable *renderable = visibleSet.GetVisible(j); MaterialInstancePtr save = renderable->GetMaterialInstance(); const std::string &mtlName = save->GetMaterial()->GetName(); if ("std" == mtlName) { mInstanceStd->SetPixelTexture(0, "SampleBase", save->GetPixelTexture(0, "SampleBase")); renderable->SetMaterialInstance(mInstanceStd); renderer->Draw(renderable); renderable->SetMaterialInstance(save); save->Update(0.0f, 0.0f); } else if ("skinskeleton" == mtlName) { //mInstanceSkinSkeleton->SetPixelTexture(0, "SampleBase", save->GetPixelTexture(0, "SampleBase")); //renderable->SetMaterialInstance(mInstanceSkinSkeleton); renderer->Draw(renderable); //renderable->SetMaterialInstance(save); //save->Update(0.0f, 0.0f); } else if ("terrain" == mtlName) { renderable->SetMaterialInstance(mInstanceTerrain); renderer->Draw(renderable); renderable->SetMaterialInstance(save); save->Update(0.0f, 0.0f); } } renderer->SetOverrideOffsetProperty(0); }
//---------------------------------------------------------------------------- void SMShadowEffect::Draw (Renderer* renderer, const VisibleSet& visibleSet) { const int numVisible = visibleSet.GetNumVisible(); for (int j = 0; j < numVisible; ++j) { // Replace the object's effect instance by the shadow-effect instance. Visual* visual = (Visual*)visibleSet.GetVisible(j); VisualEffectInstancePtr save = visual->GetEffectInstance(); visual->SetEffectInstance(mInstance); // Draw the object using the shadow effect. renderer->Draw(visual); // Restore the object's effect instance. visual->SetEffectInstance(save); } }
//---------------------------------------------------------------------------- // 绘制入口点 //---------------------------------------------------------------------------- void Renderer::Draw (const VisibleSet& visibleSet, GlobalMaterial* globalMaterial) { if (!globalMaterial) { const int numVisible = visibleSet.GetNumVisible(); for (int i = 0; i < numVisible; ++i) { const Renderable* renderable = (const Renderable*)visibleSet.GetVisible(i); const MaterialInstance* instance = renderable->GetMaterialInstance(); Draw(renderable, instance); } } else { globalMaterial->Draw(this, visibleSet); } }
//---------------------------------------------------------------------------- void PlanarReflectionEffect::Draw (Renderer* renderer, const VisibleSet& visibleSet) { // Save the current global state overrides for restoration later. const DepthState* saveDState = renderer->GetOverrideDepthState(); const StencilState* saveSState = renderer->GetOverrideStencilState(); // Override the global state to support this effect. renderer->SetOverrideDepthState(mDepthState); renderer->SetOverrideStencilState(mStencilState); // The depth range will be modified during drawing, so save the current // depth range for restoration later. float minDepth, maxDepth; renderer->GetDepthRange(minDepth, maxDepth); // Get the camera to store post-world transformations. Camera* camera = renderer->GetCamera(); const int numVisible = visibleSet.GetNumVisible(); int i, j; for (i = 0; i < mNumPlanes; ++i) { // Render the mirror into the stencil plane. All visible mirror // pixels will have the stencil value of the mirror. Make sure that // no pixels are written to the depth buffer or color buffer, but use // depth buffer testing so that the stencil will not be written where // the plane is behind something already in the depth buffer. mStencilState->Enabled = true; mStencilState->Compare = StencilState::CM_ALWAYS; mStencilState->Reference = (unsigned int)(i + 1); mStencilState->OnFail = StencilState::OT_KEEP; // irrelevant mStencilState->OnZFail = StencilState::OT_KEEP; // invisible to 0 mStencilState->OnZPass = StencilState::OT_REPLACE; // visible to i+1 // Enable depth reads but disable depth writes. mDepthState->Enabled = true; mDepthState->Writable = false; mDepthState->Compare = DepthState::CM_LEQUAL; // Disable color writes. renderer->SetColorMask(false, false, false, false); renderer->Draw(mPlanes[i]); // Enable color writes. renderer->SetColorMask(true, true, true, true); // Render the mirror plane again by only processing pixels where the // stencil buffer contains the reference value. This time there are // no changes to the stencil buffer and the depth buffer value is // reset to the far clipping plane. This is done by setting the range // of depth values in the viewport volume to be [1,1]. Since the // mirror plane cannot also be semi-transparent, we do not care what // is behind the mirror plane in the depth buffer. We need to move // the depth buffer values back where the mirror plane will be // rendered so that when the reflected object is rendered, it can be // depth buffered correctly. Note that the rendering of the reflected // object will cause depth value to be written, which will appear to // be behind the mirror plane. Enable writes to the color buffer. // Later when we want to render the reflecting plane and have it blend // with the background, which should contain the reflected caster, we // want to use the same blending function so that the pixels where the // reflected object was not rendered will contain the reflecting plane // colors. In that case, the blending result will have the reflecting // plane appear to be opaque when in reality it was blended with // blending coefficients adding to one. mStencilState->Enabled = true; mStencilState->Compare = StencilState::CM_EQUAL; mStencilState->Reference = (unsigned int)(i + 1); mStencilState->OnFail = StencilState::OT_KEEP; mStencilState->OnZFail = StencilState::OT_KEEP; mStencilState->OnZPass = StencilState::OT_KEEP; // Set the depth buffer to "infinity" at those pixels for which the // stencil buffer is the reference value i+1. renderer->SetDepthRange(1.0f, 1.0f); mDepthState->Enabled = true; mDepthState->Writable = true; mDepthState->Compare = DepthState::CM_ALWAYS; renderer->Draw(mPlanes[i]); // Restore the depth range and depth testing function. mDepthState->Compare = DepthState::CM_LEQUAL; renderer->SetDepthRange(minDepth, maxDepth); // Compute the equation for the mirror plane in model coordinates // and get the reflection matrix in world coordinates. HMatrix reflection; HPlane modelPlane; GetReflectionMatrixAndModelPlane(i, reflection, modelPlane); // TODO: Add clip plane support to the renderer. // Enable a clip plane so that only objects above the mirror plane // are reflected. This occurs before SetTransformation because it // needs the current geometric pipeline matrices to compute the clip // plane in the correct coordinate system. //pkRenderer->EnableUserClipPlane(0,kPlane); // This temporarily modifies the world matrix to apply the reflection // after the model-to-world transformation. camera->SetPreViewMatrix(reflection); // Reverse the cull direction. Allow for models that are not // necessarily set up with front or back face culling. renderer->SetReverseCullOrder(true); // Render the reflected object. Only render where the stencil buffer // contains the reference value. for (j = 0; j < numVisible; ++j) { renderer->Draw((const Visual*)visibleSet.GetVisible(j)); } renderer->SetReverseCullOrder(false); camera->SetPreViewMatrix(HMatrix::IDENTITY); // TODO: Add clip plane support to the renderer. //pkRenderer->DisableUserClipPlane(0); // We are about to render the reflecting plane again. Reset to the // global state for the reflecting plane. We want to blend the // reflecting plane with what is already in the color buffer, // particularly either the image of the reflected caster or the // reflecting plane. All we want for the reflecting plane at this // stage is to force the alpha channel to always be the reflectance // value for the reflecting plane. Render the reflecting plane // wherever the stencil buffer is set to the reference value. This // time clear the stencil buffer reference value where it is set. // Perform the normal depth buffer testing and writes. Allow the // color buffer to be written to, but this time blend the reflecting // plane with the values in the color buffer based on the reflectance // value. Note that where the stencil buffer is set, the color buffer // has either color values from the reflecting plane or the reflected // object. Blending will use src=1-alpha (reflecting plane) and // dest=alpha background (reflecting plane or reflected object). const AlphaState* saveAState = renderer->GetOverrideAlphaState(); renderer->SetOverrideAlphaState(mAlphaState); mAlphaState->BlendEnabled = true; mAlphaState->SrcBlend = AlphaState::SBM_ONE_MINUS_CONSTANT_ALPHA; mAlphaState->DstBlend = AlphaState::DBM_CONSTANT_ALPHA; mAlphaState->ConstantColor = Float4(0.0f, 0.0f, 0.0f, mReflectances[i]); mStencilState->Compare = StencilState::CM_EQUAL; mStencilState->Reference = (unsigned int)(i + 1); mStencilState->OnFail = StencilState::OT_KEEP; mStencilState->OnZFail = StencilState::OT_KEEP; mStencilState->OnZPass = StencilState::OT_INVERT; renderer->Draw(mPlanes[i]); renderer->SetOverrideAlphaState(saveAState); } // Restore the global state that existed before this function call. renderer->SetOverrideStencilState(saveSState); renderer->SetOverrideDepthState(saveDState); // Render the objects as usual, this time drawing only the potentially // visible objects. for (j = 0; j < numVisible; ++j) { renderer->Draw((const Visual*)visibleSet.GetVisible(j)); } }
//---------------------------------------------------------------------------- void PlanarShadowEffect::Draw (Renderer* renderer, const VisibleSet& visibleSet) { // Draw the potentially visible portions of the shadow caster. const int numVisible = visibleSet.GetNumVisible(); int j; for (j = 0; j < numVisible; ++j) { renderer->Draw((const Visual*)visibleSet.GetVisible(j)); } // Save the current global state overrides for restoration later. const DepthState* saveDState = renderer->GetOverrideDepthState(); const StencilState* saveSState = renderer->GetOverrideStencilState(); // Override the global state to support this effect. renderer->SetOverrideDepthState(mDepthState); renderer->SetOverrideStencilState(mStencilState); // Get the camera to store post-world transformations. Camera* camera = renderer->GetCamera(); for (int i = 0; i < mNumPlanes; ++i) { // Enable depth buffering. NOTE: The plane object should not have a // ZBufferState object that changes the current settings. mDepthState->Enabled = true; mDepthState->Writable = true; mDepthState->Compare = DepthState::CM_LEQUAL; // Enable the stencil buffer so that the shadow can be clipped by the // plane. The stencil values are set whenever the corresponding // plane pixels are visible. mStencilState->Enabled = true; mStencilState->Compare = StencilState::CM_ALWAYS; mStencilState->Reference = (unsigned int)(i + 1); mStencilState->OnFail = StencilState::OT_KEEP; // irrelevant mStencilState->OnZFail = StencilState::OT_KEEP; // invisible to 0 mStencilState->OnZPass = StencilState::OT_REPLACE; // visible to i+1 // Draw the plane. renderer->Draw(mPlanes[i]); // Blend the shadow color with the pixels drawn on the projection // plane. The blending equation is // (rf,gf,bf) = as*(rs,gs,bs) + (1-as)*(rd,gd,bd) // where (rf,gf,bf) is the final color to be written to the frame // buffer, (rs,gs,bs,as) is the shadow color, and (rd,gd,bd) is the // current color of the frame buffer. const AlphaState* saveAState = renderer->GetOverrideAlphaState(); renderer->SetOverrideAlphaState(mAlphaState); mAlphaState->BlendEnabled = true; mAlphaState->SrcBlend = AlphaState::SBM_SRC_ALPHA; mAlphaState->DstBlend = AlphaState::DBM_ONE_MINUS_SRC_ALPHA; mMaterial->Diffuse = mShadowColors[i]; // Disable the depth buffer reading so that no depth-buffer fighting // occurs. The drawing of pixels is controlled solely by the stencil // value. mDepthState->Enabled = false; // Only draw where the plane has been drawn. mStencilState->Enabled = true; mStencilState->Compare = StencilState::CM_EQUAL; mStencilState->Reference = (unsigned int)(i + 1); mStencilState->OnFail = StencilState::OT_KEEP; // invisible kept 0 mStencilState->OnZFail = StencilState::OT_KEEP; // irrelevant mStencilState->OnZPass = StencilState::OT_ZERO; // visible set to 0 // Get the projection matrix relative to the projector (light). HMatrix projection; if (!GetProjectionMatrix(i, projection)) { continue; } camera->SetPreViewMatrix(projection); // Draw the caster again, but temporarily use a material effect so // that the shadow color is blended onto the plane. TODO: This // drawing pass should use a VisibleSet relative to the projector so // that objects that are out of view (i.e. culled relative to the // camera and not in the camera's VisibleSet) can cast shadows. for (j = 0; j < numVisible; ++j) { Visual* visual = (Visual*)visibleSet.GetVisible(j); VisualEffectInstancePtr save = visual->GetEffectInstance(); visual->SetEffectInstance(mMaterialEffectInstance); renderer->Draw(visual); visual->SetEffectInstance(save); } camera->SetPreViewMatrix(HMatrix::IDENTITY); renderer->SetOverrideAlphaState(saveAState); } // Restore the global state that existed before this function call. renderer->SetOverrideStencilState(saveSState); renderer->SetOverrideDepthState(saveDState); }
void ToolDoorEdit::MessageProc(BOOL bActive) { //切换 ui::Manager::_tagINPUTINFO *pInputInfo = ui::Manager::GetInstance()->GetInputInfoBuffer(); EditWnd *pEditWnd = CommUI::GetInstance()->GetEditWnd(); WndDoorEdit *pWndDoorEdit = pEditWnd->GetWndDoorEdit(); int iDoorIndex = pWndDoorEdit->GetCurDoorIndex() + 1; int iDoorCount = pWndDoorEdit->GetDoorCount(); if (pInputInfo->eType == UIMT_KB_KEYDOWN) { switch(pInputInfo->dwData) { case DIK_Q: { m_eEditStatus = (m_eEditStatus == DEST_SELECT)? DEST_PALACE : DEST_SELECT; } break; case DIK_V: //if (pInputInfo->byKeyBuffer[DIK_LCONTROL]) //{ // if (m_eEditStatus == DEST_SELECT) // { // } //} break; case DIK_DELETE: if (m_eEditStatus == DEST_SELECT) { int iSelSize = (int)m_vSelGridIndexArray.size(); if (iSelSize) { ////清除所选择部分D CmdMapDelDoor *pCmd = new CmdMapDelDoor; for(int i = 0; i < iSelSize; i++) { pCmd->AddGridIndex((DWORD)m_vSelGridIndexArray[i]); } CmdMgr::GetInstance()->Do(pCmd); } } break; } } //选择 switch(m_eEditStatus) { case DEST_SELECT: //选择 if (bActive) { switch(pInputInfo->eType) { case UIMT_MS_BTNDOWN: if (pInputInfo->dwData == MK_LBUTTON) { m_bDrag = TRUE; m_ptDragStart.x = GET_X_LPARAM(pInputInfo->lParam); m_ptDragStart.y = GET_Y_LPARAM(pInputInfo->lParam); } break; case UIMT_MS_BTNUP: if (pInputInfo->dwData == MK_LBUTTON) { if (m_bDrag) { m_ptDragEnd.x = GET_X_LPARAM(pInputInfo->lParam); m_ptDragEnd.y = GET_Y_LPARAM(pInputInfo->lParam); m_bDrag = FALSE; //结束,开始选择//画框 SelectFrustum cSelFrustum; RECT rc; pEditWnd->GetWndRect(&rc); cSelFrustum.CalculateFrustum(&rc,pEditWnd->GetCamera(),m_ptDragStart,m_ptDragEnd); std::vector<int>vTempArray; //循环可见格子 EditMap *pMap = CommDB::GetInstance()->GetMap(); VisibleSet *pSet = pMap->GetVisibleSet(); DWORD *pVIArray = pSet->GetVisibleIndexArray(); DWORD dwMapWidth = pMap->GetWidth(); DWORD dwMapDepth = pMap->GetDepth(); for(DWORD n = 0; n< pSet->GetVisibleIndexCount(); n++) { DWORD dwGridIndex = pVIArray[n]; Grid *pGrid = pMap->GetGrid(dwGridIndex); if (pGrid->GetDoorIndex()) { //计算可视格子 in 选择锥 D3DXVECTOR3 pos[4]; D3DXVECTOR3 vCenter; pMap->GetGridPosition(dwGridIndex,pos,&vCenter); /*float x = (float)(dwGridIndex % dwMapWidth); float z = (float)(dwGridIndex / dwMapWidth); pos[0] = D3DXVECTOR3(x,0,z); pos[1] = D3DXVECTOR3(x+1,0,z); pos[2] = D3DXVECTOR3(x,0,z+1); pos[3] = D3DXVECTOR3(x+1,0,z+1);*/ if (cSelFrustum.TestPoint(&vCenter)) { //这个格子被选中 vTempArray.push_back(dwGridIndex); } } } //是否是CTRL按住 if (pInputInfo->byKeyBuffer[DIK_LCONTROL] & 0x80) { //减模式 std::vector<int>::iterator result; std::vector<int> vSelIndexArray = m_vSelGridIndexArray; for(std::vector<int>::iterator it = vSelIndexArray.begin(); it != vSelIndexArray.end();it++) { int iGridIndex = *it; //find result = find(vTempArray.begin(),vTempArray.end(),iGridIndex); if (result != vTempArray.end()) { result = find(m_vSelGridIndexArray.begin(),m_vSelGridIndexArray.end(),iGridIndex); if (result != vTempArray.end()) { //找到,删除 m_vSelGridIndexArray.erase(result); } } } } else if (pInputInfo->byKeyBuffer[DIK_LSHIFT] & 0x80) { //添加模式 std::vector<int>::iterator result; for(DWORD n = 0; n < vTempArray.size(); n++) { int iGridIndex = vTempArray[n]; result = find(m_vSelGridIndexArray.begin(),m_vSelGridIndexArray.end(),iGridIndex); if (result == m_vSelGridIndexArray.end()) { m_vSelGridIndexArray.push_back(iGridIndex); } } } else { //正常选择模式 m_vSelGridIndexArray.clear(); for(DWORD n = 0; n < vTempArray.size(); n++) { m_vSelGridIndexArray.push_back(vTempArray[n]); } } } } break; } } break; case DEST_PALACE: //放置 { if (bActive) { if (pInputInfo->dwMouseButtonState & MK_LBUTTON) { //计算选中的格子 GameSelectRay cSelRay; RECT rc; pEditWnd->GetWndRect(&rc); cSelRay.CalculateRay(&rc,pEditWnd->GetCamera(),pInputInfo->ptMouse); //显示格子 EditMap *pMap = CommDB::GetInstance()->GetMap(); VisibleSet *pSet = pMap->GetVisibleSet(); DWORD *pVIArray = pSet->GetVisibleIndexArray(); DWORD dwMapWidth = pMap->GetWidth(); DWORD dwMapDepth = pMap->GetDepth(); for(DWORD n = 0; n< pSet->GetVisibleIndexCount(); n++) { DWORD dwGridIndex = pVIArray[n]; //计算可视格子 in 选择锥 D3DXVECTOR3 pos[4]; D3DXVECTOR3 vCenter; pMap->GetGridPosition(dwGridIndex,pos,&vCenter); /*float x = (float)(dwGridIndex % dwMapWidth); float z = (float)(dwGridIndex / dwMapWidth);*/ /*pos[0] = D3DXVECTOR3(x,pGrid->,z); pos[1] = D3DXVECTOR3(x+1,0,z); pos[2] = D3DXVECTOR3(x,0,z+1); pos[3] = D3DXVECTOR3(x+1,0,z+1); D3DXVECTOR3 vCenter = (pos[0] + pos[1] + pos[2] + pos[3]) / 4.0f;*/ if (cSelRay.IntersectTri(&pos[0],NULL,NULL) || cSelRay.IntersectTri(&pos[1],NULL,NULL)) { //check grid mtl //equal old? Grid *pGrid = pMap->GetGrid(dwGridIndex); if (pGrid->GetDoorIndex() != iDoorIndex) { //这个格子被选中 CmdMapSetDoor *pCmd = new CmdMapSetDoor; pCmd->SetDoorIndex(dwGridIndex,iDoorIndex); CmdMgr::GetInstance()->Do(pCmd); } break; } } } } } break; } }
void ToolDoorEdit::Render() { ui::Manager::_tagINPUTINFO *pInputInfo = ui::Manager::GetInstance()->GetInputInfoBuffer(); render::Interface *pInterface = render::Interface::GetInstance(); render::Interface::Layer2D *pLayer2D = pInterface->GetLayer2D(); render::Interface::Layer3D *pLayer3D = pInterface->GetLayer3D(); EditWnd *pEditWnd = CommUI::GetInstance()->GetEditWnd(); WndDoorEdit *pWndDoorEdit= pEditWnd->GetWndDoorEdit(); DWORD dwSelIndex = pWndDoorEdit->GetCurDoorIndex(); switch(m_eEditStatus) { case DEST_SELECT: if (m_bDrag) { //画拖动线 pLayer2D->DrawWireQuadRect(m_ptDragStart.x,m_ptDragStart.y,pInputInfo->ptMouse.x,pInputInfo->ptMouse.y,0xffffffff); } DrawSelected(); break; case DEST_PALACE: { D3DXMATRIX matTRS; //显示被点亮的格子 static GameSelectRay cSelRay; RECT rc; pEditWnd->GetWndRect(&rc); cSelRay.CalculateRay(&rc,pEditWnd->GetCamera(),pInputInfo->ptMouse); //显示格子 EditMap *pMap = CommDB::GetInstance()->GetMap(); if (pMap) { VisibleSet *pSet = pMap->GetVisibleSet(); DWORD *pVIArray = pSet->GetVisibleIndexArray(); TerrainMesh *pMesh = CommDB::GetInstance()->GetTerrainMesh(); TerrainMesh::_tagGrid *pGrid(NULL); TerrainMesh::_tagVertex *pVertexArray = pMesh->GetVertexList(); D3DXVECTOR3 pos[4]; D3DXVECTOR3 vCenter; for(DWORD n = 0; n< pSet->GetVisibleIndexCount(); n++) { DWORD dwGridIndex = pVIArray[n]; pGrid = pMesh->GetGrid(dwGridIndex); for(DWORD v= 0; v < 4; v++) { pos[v] = pVertexArray[pGrid->dwVertexIndex[v]].vPosition; } vCenter = (pos[0] + pos[1] + pos[2] + pos[3]) / 4.0f; if (cSelRay.IntersectTri(&pos[0],&pos[1],&pos[2],NULL,NULL) || cSelRay.IntersectTri(&pos[0],&pos[2],&pos[3],NULL,NULL)) { //这个格子被选中 pLayer3D->_DEBUG_DrawWireQuad(&pos[0],&pos[1],&pos[2],&pos[3],0xffff0000); D3DXMatrixTranslation(&matTRS,vCenter.x,vCenter.y,vCenter.z); RnderDoorModel(&matTRS); break; } } } } break; } _ShowStatus(); }