void CmdMapSetDoor::UnExecute(void)
{
	Cmd::UnExecute();
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	Grid * pGrid = pMap->GetGrid(m_dwGridIndex);
	pGrid->SetDoorIndex(m_dwOldDoorIndex);
}
//----------------------------------------------------------------------------
void E_MainFrame::OnSaveProjectAs()
{
	// save scene first
	EditMap *map = PX2_EDIT.GetEditMap();
	Project *proj = Project::GetSingletonPtr();
	if (proj)
	{
		if (proj->GetScene() && proj->GetSceneFilename().empty())
		{
			OnSaveSceneAs();
		}
	}

	wxFileDialog dlg(this,
		wxT("Save project"),
		wxEmptyString,
		wxEmptyString,
		wxT("Project (*.px2proj)|*.px2proj"),
		wxFD_SAVE | wxFD_OVERWRITE_PROMPT);

	dlg.CenterOnParent();

	if (wxID_OK == dlg.ShowModal())
	{
		std::string path = dlg.GetPath();
		path = StringHelp::StandardiseFilename(path);
		map->SaveProjectAs(path);
	}
}
void CmdMapSetBuildRotationY::UnExecute(void)
{
	Cmd::UnExecute();
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	Grid * pGrid = pMap->GetGrid(m_dwGridIndex);
	pGrid->SetBuildRotationY(m_fOldBuildRotationY);
}
void WndLightAdjust::EndPopUp()
{
	ModifyStyle(0,FWS_VISIBLE);
	ui::Manager::GetInstance()->EndPopupWnd();
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	pMap->SetSunLightAmbientColor(m_dwOldAmbientColor);
	pMap->SetSunLightDiffuseColor(m_dwOldDirectionalColor);
}
//----------------------------------------------------------------------------
void E_MainFrame::OnCloseScene()
{
	EditMap *map = PX2_EDIT.GetEditMap();
	if (map)
	{
		map->CloseScene();
	}
}
Beispiel #6
0
//----------------------------------------------------------------------------
void MainFrame::OnNew (wxCommandEvent &e)
{
	EditMap *map = EditSystem::GetSingleton().GetEditMap();
	map->NewScene();

	mRenderView->SetScene(map->GetScene()->GetSceneNode());

	ViewCtrlInstMan::GetSingleton().GetCurViewCtrlInst()
		->SetInteractionMode(IM_GENERAL);
}
void WndLightAdjust::BeginPopUp(void)
{
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	if (!pMap) return;
	m_dwOldAmbientColor = pMap->GetSunLightAmbientColor();
	m_dwOldDirectionalColor = pMap->GetSunLightDiffuseColor();
	m_pBtnAmbient->SetColor(m_dwOldAmbientColor);
	m_pBtnDirectional->SetColor(m_dwOldDirectionalColor);
	ModifyStyle(FWS_VISIBLE,0);
	ui::Manager::GetInstance()->BeginPopupWnd(this);
}
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 CmdMapFillBlock::UnExecute()
{
	Cmd::UnExecute();
	//»Ö¸´ËùÓÐ
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	for(int i = 0; i < (int)m_vGridIndexArray.size(); i++)
	{
		DWORD dwGridIndex = m_vGridIndexArray[i];
		Grid * pGrid = pMap->GetGrid(dwGridIndex);
		DWORD dwOldBlock = m_vGridOldBlockArray[i];
		pGrid->SetBlock(dwOldBlock);
	}
}
void CmdMapDelDoor::UnExecute()
{
	Cmd::UnExecute();
	//»Ö¸´ËùÓÐ
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	for(int i = 0; i < (int)m_vGridIndexArray.size(); i++)
	{
		DWORD dwGridIndex = m_vGridIndexArray[i];
		Grid * pGrid = pMap->GetGrid(dwGridIndex);
		DWORD dwOldDoorIndex = m_pGridOldDoorIndexArray[i];
		pGrid->SetDoorIndex(dwOldDoorIndex);
	}
	
}
void CmdMapFillBlock::Execute()
{
	Cmd::Execute();
	//Ìî³äËùÓÐ
	m_vGridOldBlockArray.clear();
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	for(int i = 0; i <(int)m_vGridIndexArray.size(); i++)
	{
		DWORD dwGridIndex = m_vGridIndexArray[i];
		Grid * pGrid = pMap->GetGrid(dwGridIndex);
		m_vGridOldBlockArray.push_back(pGrid->GetBlock());
        pGrid->SetBlock(m_dwBlock);
	}
}
void ToolGridVisibleEdit::DrawBrush(void)
{
	if (m_dwCurSelGrid == 0xFFFFFFFF) 
		return;

	render::Interface *pInterface = render::Interface::GetInstance();
	render::Interface::Layer3D *pLayer3D = render::Interface::GetInstance()->GetLayer3D();

	EditMap *pMap = CommDB::GetInstance()->GetMap();
	DWORD dwMapWidth = pMap->GetWidth();
	DWORD dwMapDepth = pMap->GetDepth();
	int iCenterX = m_dwCurSelGrid % dwMapWidth;
	int iCenterZ = m_dwCurSelGrid / dwMapWidth;

	TerrainMesh *pMesh = CommDB::GetInstance()->GetTerrainMesh();
	TerrainMesh::_tagGrid *pGrid(NULL);
	TerrainMesh::_tagVertex *pVertexArray = pMesh->GetVertexList();
	D3DXVECTOR3 pos[4];


	for(int j = - m_iBrushSize; j < m_iBrushSize + 1; j++)
	{
		for(int i = - m_iBrushSize; i < m_iBrushSize + 1;i++)
		{
			int iX = iCenterX + i;
			int iZ = iCenterZ + j;

			if (!(iX < 0 || iX >= (int)dwMapWidth || iZ < 0 || iZ >= (int)dwMapDepth))
			{
				//在地图内
				//显示格子
				DWORD dwGridIndex = iX + iZ * dwMapWidth;
				pGrid = pMesh->GetGrid(dwGridIndex);

				for(DWORD v = 0; v < 4; v++)
				{
					pos[v] = pVertexArray[pGrid->dwVertexIndex[v]].vPosition;
					pos[v].y += 0.02f;
				}

				//pLayer3D->_DEBUG_DrawTriangle(&pos[0],&pos[1],&pos[2],dwMtlColor[iMtlSelIndex]);
				//pLayer3D->_DEBUG_DrawTriangle(&pos[0],&pos[2],&pos[3],dwMtlColor[iMtlSelIndex]);
				pLayer3D->_DEBUG_DrawTriangle(&pos[0],&pos[1],&pos[2],0x8080ff80);
				pLayer3D->_DEBUG_DrawTriangle(&pos[0],&pos[2],&pos[3],0x8080ff80);
				pLayer3D->_DEBUG_DrawWireQuad(&pos[0],&pos[1],&pos[2],&pos[3],0xff00ff00);
			}
		}
	}
}
Beispiel #13
0
//----------------------------------------------------------------------------
void E_MainFrame::OnSaveProject()
{
	EditMap *map = PX2_EDIT.GetEditMap();

	Project *proj = Project::GetSingletonPtr();
	if (proj)
	{
		if (proj->GetScene())
		{
			OnSaveScene();
		}
	}

	map->SaveProject();
}
bool CmdMapSetBuildRotationY::Execute(void)
{
	//±£´æ¾ÉµÄ
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	Grid * pGrid = pMap->GetGrid(m_dwGridIndex);

	m_fOldBuildRotationY = pGrid->GetBuild()->vRotation.y;
	if (m_fOldBuildRotationY == m_fBuildRotationY)
		return false;

	pGrid->SetBuildRotationY(m_fBuildRotationY);

	Cmd::Execute();
	return true;
}
bool CmdMapDelDoor::Execute()
{
	Cmd::Execute();

	//Ìî³äËùÓÐ,ɾ³ý
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	for(int i = 0; i < (int)m_vGridIndexArray.size(); i++)
	{
		DWORD dwGridIndex = m_vGridIndexArray[i];
		Grid * pGrid = pMap->GetGrid(dwGridIndex);
		m_pGridOldDoorIndexArray[i] = pGrid->GetDoorIndex();//0Ϊ¿Õ
        pGrid->SetDoorIndex(0);
	}

	return true;
}
void ToolGridVisibleEdit::PaintBrush(BOOL  bVisible)
{
	if (m_dwCurSelGrid == 0xFFFFFFFF)
		return;       
	
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	DWORD dwMapWidth = pMap->GetWidth();
	DWORD dwMapDepth = pMap->GetDepth();
	int iCenterX = m_dwCurSelGrid % dwMapWidth;
	int iCenterZ = m_dwCurSelGrid / dwMapWidth;

	TerrainMesh *pMesh = CommDB::GetInstance()->GetTerrainMesh();
	TerrainMesh::_tagGrid *pGrid(NULL);
	TerrainMesh::_tagVertex *pVertexArray = pMesh->GetVertexList();
	D3DXVECTOR3 pos[4];

	BOOL bAllLike = TRUE;

	for(int j = - m_iBrushSize; j < m_iBrushSize + 1; j++)
	{
		for(int i = - m_iBrushSize; i < m_iBrushSize + 1;i++)
		{
			int iX = iCenterX + i;
			int iZ = iCenterZ + j;

			if (!(iX < 0 || iX >= (int)dwMapWidth || iZ < 0 || iZ >= (int)dwMapDepth))
			{
				//在地图内
				//显示格子
				DWORD dwGridIndex = iX + iZ * dwMapWidth;
				//检查是否全部相同
				if (pMap->GetGrid(dwGridIndex)->GetVisible() != bVisible)
				{
					bAllLike = FALSE;
					break;
				}
			}
		}
	}
	if (!bAllLike)//有不同,则涂
	{
		CmdMapFillGridVisible *pCmd = new CmdMapFillGridVisible;
		pCmd->SetVisible(bVisible);
		for(int j = - m_iBrushSize; j < m_iBrushSize + 1; j++)
		{
			for(int i = - m_iBrushSize; i < m_iBrushSize + 1;i++)
			{
				int iX = iCenterX + i;
				int iZ = iCenterZ + j;

				if (!(iX < 0 || iX >= (int)dwMapWidth || iZ < 0 || iZ >= (int)dwMapDepth))
				{
					//在地图内
					//显示格子
					DWORD dwGridIndex = iX + iZ * dwMapWidth;
					pCmd->AddGridIndex(dwGridIndex);					
				}
			}
		}
		CmdMgr::GetInstance()->Do(pCmd);
	}
}
Beispiel #17
0
//----------------------------------------------------------------------------
void E_MainFrame::OnNewScene()
{
	EditMap *map = PX2_EDIT.GetEditMap();
	map->NewScene();
}
void CmdMapPaintColor::Execute(void)
{
	Cmd::Execute();
	//保存颜色

	EditMap *pMap = CommDB::GetInstance()->GetMap();
	DWORD dwMapWidth = pMap->GetWidth();
	DWORD dwMapDepth = pMap->GetDepth();
	
	TerrainMesh *pMesh = CommDB::GetInstance()->GetTerrainMesh();
	TerrainMesh::_tagVertex *pTempVertex,*pVertexList = pMesh->GetVertexList();

	D3DXVECTOR3 *pCenterPosition = &pVertexList[m_dwVertexIndex].vPosition;//中心点坐标


    //求出要运算的顶点列表
	int iCenterRow = (int)(m_dwVertexIndex % (dwMapWidth + 1));
	int iCenterCol = (int)(m_dwVertexIndex / (dwMapWidth + 1));
	int iRadius = (int)m_fBrushRadius;
	for(int i = - iRadius; i <= iRadius; i++)
	{
		int iR = iCenterRow + i;
		if (iR < 0 || iR >= (int)(dwMapWidth +1)) 
		{
			continue;//越界
		}
		for(int j = -iRadius; j <=  iRadius; j++)
		{
			int iC =  iCenterCol + j;
			if (iC < 0 || iC >= (int)(dwMapDepth +1)) 
			{
				continue;//越界
			}

			DWORD dwVertexIndex = iR + iC * (int)(dwMapWidth + 1);

			pTempVertex = &pVertexList[dwVertexIndex];
			//计算顶点的距离是否在半径中
			float dx = pTempVertex->vPosition.x - pCenterPosition->x;
			float dz = pTempVertex->vPosition.z - pCenterPosition->z;

			float fDis = sqrtf(dx * dx + dz * dz);

			if (fDis <= m_fBrushRadius)
			{
				//保存要修改的定点索引表
				m_vVertexIndexArray.push_back(dwVertexIndex);
				m_vVertexColorArray.push_back(pTempVertex->cAddColor);
			}
		 }
	}

	std::vector<DWORD>::iterator it;
	//画刷类型
	if (m_dwBrushType == 0)
	{
		//铅笔。。。直接画
		for(it = m_vVertexIndexArray.begin(); it != m_vVertexIndexArray.end(); it++)
		{
			DWORD dwVertexIndex = *it;
			pTempVertex = &pVertexList[dwVertexIndex];
			DWORD &dwDestColor = pTempVertex->cAddColor;
			//混合运算
			DWORD sr = (m_dwColor & 0x00FF0000) >> 16;
			DWORD sg = (m_dwColor & 0x0000FF00) >> 8;
			DWORD sb = (m_dwColor & 0x000000FF);
			DWORD dr = (dwDestColor & 0x00FF0000) >> 16;
			DWORD dg = (dwDestColor & 0x0000FF00) >> 8;
			DWORD db = (dwDestColor & 0x000000FF);

			DWORD a = (DWORD)(m_fColorChroma * 255.0f);

			DWORD r = ((sr * a) + dr * (255 - a)) / 255;
			DWORD g = ((sg * a) + dg * (255 - a)) / 255;
			DWORD b = ((sb * a) + db * (255 - a)) / 255;

			dwDestColor = 0xFF000000 | r << 16 | g <<8 | b;
		}
	}
	else
	{
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();
}
void WndLightAdjust::Update()
{
	//UPDATE DEFAULT
	ui::Wnd::UpdateDefault();
	
	ui::Manager::_tagINPUTINFO *pInputInfo = ui::Manager::GetInstance()->GetInputInfoBuffer();
	render::Interface *pInterface = render::Interface::GetInstance();

	DWORD &dwStyle = m_tWindowInfo.dwStyle;
	if (dwStyle & FWS_VISIBLE && !(dwStyle & FWS_DISABLE))
	{
		if (m_bPickColor)
		{
			if (pInputInfo->eType == UIMT_MS_BTNUP && pInputInfo->dwData == MK_LBUTTON)
			{
				m_bPickColor = FALSE;
			}
			else
			{
				//检查颜色
				DWORD px = (DWORD)pInputInfo->ptMouse.x;
				DWORD py = (DWORD)pInputInfo->ptMouse.y;
				if (px > m_dwPickX && py > m_dwPickY &&
					px < m_dwPickX + m_dwColorMapWidth && 
					py < m_dwPickX + m_dwColorMapHeight)
				{
					//计算位置
					int iPosX = px - m_dwPickX;
					int iPosY = py - m_dwPickY;
					//取得颜色
					render::Texture   * pTexture  = pInterface->GetTexture(m_dwColorMapHandle);
					DWORD dwColor = pTexture->GetPixel(iPosX,iPosY);
					if (m_ePickType == PICK_AMBIENT)
					{
						m_pBtnAmbient->SetColor(dwColor);
						EditMap *pMap = CommDB::GetInstance()->GetMap();
						pMap->SetSunLightAmbientColor(dwColor);
					}
					else
					{
						m_pBtnDirectional->SetColor(dwColor);
						EditMap *pMap = CommDB::GetInstance()->GetMap();
						pMap->SetSunLightDiffuseColor(dwColor);
					}
				}
			}
			
		}
		else
		{
			if (m_pBtnOK->IsClicked())
			{
				EndPopUp();
				m_bIsOK = TRUE;
				m_bIsPopupCheckFlag= TRUE;
			}
			if (m_pBtnCancel->IsClicked())
			{
				EndPopUp();
				m_bIsOK = FALSE;
				m_bIsPopupCheckFlag = TRUE;
			}
			if (m_pBtnAmbient->IsClicked())
			{
				m_ePickType = PICK_AMBIENT;
				m_bPickColor = TRUE;
			}
			if (m_pBtnDirectional->IsClicked())
			{
				m_ePickType = PICK_DIRECTIONAL;
				m_bPickColor = TRUE;
			}
			ui::Wnd::UpdateChild();
		}
		
	}
}
void ToolDoorEdit::DrawSelected(void)
{
	DWORD dwSelCount = (DWORD)m_vSelGridIndexArray.size();
	if (!dwSelCount) return;
	render::Interface::Layer3D *pLayer3D = render::Interface::GetInstance()->GetLayer3D();
	render::Interface::Layer2D *pLayer2D = render::Interface::GetInstance()->GetLayer2D();

	D3DVIEWPORT9 tViewport;
	render::Interface::GetInstance()->GetDevice()->GetViewport(&tViewport);
	D3DXMATRIX matWrold;
	D3DXMatrixIdentity(&matWrold);

	//循环可见格子
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	Grid	*pMapGrid(NULL);
	TerrainMesh *pMesh = CommDB::GetInstance()->GetTerrainMesh();
	TerrainMesh::_tagGrid *pGrid(NULL);
	TerrainMesh::_tagVertex *pVertexArray = pMesh->GetVertexList();
	
	static D3DXVECTOR3 pos[4],vCenter;;
	
	WndDoorEdit *pWndDoorEdit = CommUI::GetInstance()->GetEditWnd()->GetWndDoorEdit();
	render::Camera *pCamera = CommUI::GetInstance()->GetEditWnd()->GetCamera();
	for(DWORD n = 0;n < dwSelCount; n++)
	{
		DWORD dwGridIndex = m_vSelGridIndexArray[n];
		pMapGrid = pMap->GetGrid(dwGridIndex);
		pMap->GetGridPosition(dwGridIndex,pos,&vCenter);
		pLayer3D->_DEBUG_DrawTriangle(&pos[0],&pos[1],&pos[2],0xa077ff77);
		pLayer3D->_DEBUG_DrawTriangle(&pos[0],&pos[2],&pos[3],0xa077ff77);
		//画名字
		int iDoorIndex = pMapGrid->GetDoorIndex() - 1;
		if (iDoorIndex >= 0)
		{
			D3DXVec3Project(&vCenter,&vCenter,&tViewport,pCamera->GetProjectionMatrix(),
				pCamera->GetViewMatrix(),&matWrold);
			tagDoor *pDoor = pWndDoorEdit->GetDoor(iDoorIndex);
			int iTexLen = lstrlen(pDoor->szName);

			int iTextWidth = pLayer2D->CalcTextWidth(pDoor->szName,iTexLen);
			int iTextHeight= pLayer2D->GetFontSize();

			int iWidth = iTextWidth + 16;	

			int iStartX = (int)vCenter.x - iWidth / 2;
			int iStartY = (int)vCenter.y - iTextHeight/2;

			pLayer2D->DrawSolidQuad(iStartX - 2,iStartY ,iTextWidth + 8,iTextHeight + 2 ,0x80bbc5ff);

			ui::Wnd::SetUIRendState();
			pLayer2D->OutPutText(iStartX + 1,iStartY + 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX - 1,iStartY - 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX + 1,iStartY - 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX - 1,iStartY + 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX + 1,iStartY,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX - 1,iStartY,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX,iStartY + 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX,iStartY - 1,pDoor->szName,iTexLen,FWC_BLACK);  
			pLayer2D->OutPutText(iStartX,iStartY,pDoor->szName,iTexLen,0xFF44FF55);  

		}
	}
}
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;
	}
}
Beispiel #23
0
void ONode::OptimizeBuild(std::vector<int> &vParentNodeGridIndexArray,std::vector<int> &vParentNodeBuildGridIndexArray,DWORD &dwNodeCount)
{
	static D3DXVECTOR3 pos[3],center,vMin,vMax; 
	EditWnd *pWndEditor = (EditWnd *)ui::Manager::GetInstance()->GetMainWnd();
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	TerrainMesh *pTerrain = CommDB::GetInstance()->GetTerrainMesh();
	//Terrain *pTerrain = pMap->GetTerrain();
	ToolBuildEdit *  pToolBuildEdit = pWndEditor->GetToolBuildEdit();
	GameBuildList *  pGameBuildList = GameBuildList::GetInstance();  	
	TerrainMesh::_tagVertex *pVertexList = pTerrain->GetVertexList();

	dwNodeCount++;
	
	//1.JDUGE FACE
	m_pBoundingBox->Get(vMin,vMax);
	std::vector<int>::iterator it;
	for(it = vParentNodeGridIndexArray.begin();it != vParentNodeGridIndexArray.end(); it++)
	{
		int iGridIndex = *it;
		TerrainMesh::_tagGrid * pGrid = pTerrain->GetGrid(iGridIndex);
		//计算grid的坐标

		BOOL bAlreadyPush = FALSE;;
		pos[0] = pVertexList[pGrid->dwVertexIndex[0]].vPosition;
		pos[1] = pVertexList[pGrid->dwVertexIndex[1]].vPosition;
		pos[2] = pVertexList[pGrid->dwVertexIndex[2]].vPosition;
	
		//0 1 2
		center = (pos[0] + pos[1] + pos[2] )/ 3.0f;

		if ((pos[0].x >= vMin.x &&
			 pos[0].y  >= vMin.y &&
			 pos[0].z  >= vMin.z &&
			 pos[0].x <= vMax.x &&
			 pos[0].y <= vMax.y &&
			 pos[0].z <= vMax.z) ||

			(pos[1].x >= vMin.x &&
			 pos[1].y  >= vMin.y &&
			 pos[1].z  >= vMin.z &&
  			 pos[1].x <= vMax.x &&
			 pos[1].y <= vMax.y &&
			 pos[1].z <= vMax.z) ||

			(pos[2].x >= vMin.x &&
			 pos[2].y  >= vMin.y &&
			 pos[2].z  >= vMin.z &&
 			 pos[2].x <= vMax.x &&
			 pos[2].y <= vMax.y &&
			 pos[2].z <= vMax.z) ||
			 
			(center.x >= vMin.x &&
			 center.y  >= vMin.y &&
			 center.z  >= vMin.z &&
 			 center.x <= vMax.x &&
			 center.y <= vMax.y &&
			 center.z <= vMax.z)) 
		{
			m_vGridIndexArray.push_back(iGridIndex);
			bAlreadyPush = TRUE;
		}
		else
		{
			if (m_pBoundingBox->TestTriangleIntersected(pos))
			{
				m_vGridIndexArray.push_back(iGridIndex);
				bAlreadyPush = TRUE;
			}
		}

		if (!bAlreadyPush)
		{
			//0 2 3

			pos[0] = pVertexList[pGrid->dwVertexIndex[0]].vPosition;
			pos[1] = pVertexList[pGrid->dwVertexIndex[2]].vPosition;
			pos[2] = pVertexList[pGrid->dwVertexIndex[3]].vPosition;

			center = (pos[0] + pos[1] + pos[2] )/ 3.0f;

			if ((pos[0].x >= vMin.x &&
				pos[0].y  >= vMin.y &&
				pos[0].z  >= vMin.z &&
				pos[0].x <= vMax.x &&
				pos[0].y <= vMax.y &&
				pos[0].z <= vMax.z) ||

				(pos[1].x >= vMin.x &&
				pos[1].y  >= vMin.y &&
				pos[1].z  >= vMin.z &&
				pos[1].x <= vMax.x &&
				pos[1].y <= vMax.y &&
				pos[1].z <= vMax.z) ||

				(pos[2].x >= vMin.x &&
				pos[2].y  >= vMin.y &&
				pos[2].z  >= vMin.z &&
				pos[2].x <= vMax.x &&
				pos[2].y <= vMax.y &&
				pos[2].z <= vMax.z) ||

				(center.x >= vMin.x &&
				center.y  >= vMin.y &&
				center.z  >= vMin.z &&
				center.x <= vMax.x &&
				center.y <= vMax.y &&
				center.z <= vMax.z)) 
			{
				m_vGridIndexArray.push_back(iGridIndex);
			}
			else
			{
				if (m_pBoundingBox->TestTriangleIntersected(pos))
				{
					m_vGridIndexArray.push_back(iGridIndex);
				}
			}
		}
	}

	//judge build 
	static D3DXVECTOR3 vPos[4],vCenter;
	static D3DXMATRIX matWorld,matRot;
	GameBuildList::Build *pBuild;
	for(it = vParentNodeBuildGridIndexArray.begin();it != vParentNodeBuildGridIndexArray.end();it++)
	{
		DWORD dwGridIndex = *it;
		TerrainMesh::_tagGrid *pGrid = pTerrain->GetGrid(dwGridIndex);
		Grid *pMapGrid = pMap->GetGrid(dwGridIndex);
		
		WORD wBuildID = pMapGrid->GetBuild()->wID;
		if (wBuildID != 0xFFFF)
		{
			//计算build点位置
			float fBuildHeight    = pMapGrid->GetBuild()->fHeight;
			float fBuildRotationY =pMapGrid->GetBuild()->fRotationY;

			pBuild = pGameBuildList->AcquireBuild(wBuildID,false);
            
			pMap->GetGridPosition(dwGridIndex,vPos,&vCenter);
			D3DXMatrixTranslation(&matWorld,vCenter.x,vCenter.y + fBuildHeight,vCenter.z);
			D3DXMatrixRotationY(&matRot,fBuildRotationY);
			D3DXMatrixMultiply(&matWorld,&matRot,&matWorld);
			//计算build的size box
			GameBuildList::Build::tagModel *pModel= pBuild->GetModel();
			if (pModel)
			{
				CDisplayModel *pGameModel = pModel->pGameModel;
				if (pGameModel)
				{
					//计算与节点的是否相交或者在里面
					render::BoundingBox *pSizeBox = pGameModel->GetSizeBox();
					if (m_pBoundingBox->GetOutsideRadius() == 0.0000f)
					{
						int x = 0;
					}
					if (m_pBoundingBox->TestBoundingBoxIntersected(&matWorld,pSizeBox))
					{
						//保存index 到数组	
						m_vBuildGridIndexArray.push_back(dwGridIndex);
						//OutputConsole("build:index: %d\n",n);
					}                                     
				}  			
			}
			else
			{
				//1x1单位
				render::BoundingBox cSizeBox;
				cSizeBox.Set(D3DXVECTOR3(0,0,0),0.5f);
				if (m_pBoundingBox->TestBoundingBoxIntersected(&matWorld,&cSizeBox))
				{
					//保存index 到数组	
					m_vBuildGridIndexArray.push_back(dwGridIndex);
					//OutputConsole("build:index: %d\n",n);
				}                                     


			}
		}
	}

	if (m_vGridIndexArray.size() == 0 && m_vBuildGridIndexArray.size() == 0) return ;

	if (m_vGridIndexArray.size() > MAX_GRID_IN_NODE || m_vBuildGridIndexArray.size() > MAX_BUILD_IN_NODE)
	{
		m_pChildNodeArray[0] = new ONode;
		m_pChildNodeArray[1] = new ONode;
		m_pChildNodeArray[2] = new ONode;
		m_pChildNodeArray[3] = new ONode;
		m_pChildNodeArray[4] = new ONode;
		m_pChildNodeArray[5] = new ONode;
		m_pChildNodeArray[6] = new ONode;
		m_pChildNodeArray[7] = new ONode;

		D3DXVECTOR3 vMin,vMax;
		m_pBoundingBox->Get(vMin,vMax);
		if (vMin == vMax)
		{
			char str[512];
			sprintf(str,"%sSIZEBOX太大,导致空间上有点共享的建物的SIZEBOX超过最大数16",CGameModelManager::GetInstance()->GetGameModelInfoFileName(pBuild->GetModel()->pGameModel->GetGameModelID()));
			//CGameModelManager::GetInstance()->GetGameModel(pBuild->GetModel()->pGameModel->GetGameModelID())->GetModelFileName();
			MessageBox(NULL,str,"错误",MB_OK);
		}

		D3DXVECTOR3 vOfs=(vMax-vMin)*0.5f;
		
		m_pChildNodeArray[0]->SetBoundingBox(vMin,vMin+vOfs);
		m_pChildNodeArray[1]->SetBoundingBox(D3DXVECTOR3(vMin.x+vOfs.x,vMin.y,vMin.z),D3DXVECTOR3(vMax.x,vMin.y+vOfs.y,vMin.z+vOfs.z));
		m_pChildNodeArray[2]->SetBoundingBox(D3DXVECTOR3(vMin.x+vOfs.x,vMin.y,vMin.z+vOfs.z),D3DXVECTOR3(vMax.x,vMin.y+vOfs.y,vMax.z));
		m_pChildNodeArray[3]->SetBoundingBox(D3DXVECTOR3(vMin.x,vMin.y,vMin.z+vOfs.z),D3DXVECTOR3(vMin.x+vOfs.x,vMin.y+vOfs.y,vMax.z));
		m_pChildNodeArray[4]->SetBoundingBox(D3DXVECTOR3(vMin.x,vMin.y+vOfs.y,vMin.z),D3DXVECTOR3(vMin.x+vOfs.x,vMax.y,vMin.z+vOfs.z));
		m_pChildNodeArray[5]->SetBoundingBox(D3DXVECTOR3(vMin.x+vOfs.x,vMin.y+vOfs.y,vMin.z),D3DXVECTOR3(vMax.x,vMax.y,vMin.z+vOfs.z));
		m_pChildNodeArray[6]->SetBoundingBox(vMin+vOfs,vMax);
		m_pChildNodeArray[7]->SetBoundingBox(D3DXVECTOR3(vMin.x,vMin.y+vOfs.y,vMin.z+vOfs.z),D3DXVECTOR3(vMin.x+vOfs.x,vMax.y,vMax.z));

		for(DWORD n = 0; n < 8; n++)
		{
			m_pChildNodeArray[n]->OptimizeBuild(m_vGridIndexArray, m_vBuildGridIndexArray,dwNodeCount);
		}
	}
}