Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2227 lines
64 KiB
C++
2227 lines
64 KiB
C++
// DlgEditTerrain.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "worldcreator.h"
|
|
#include "DlgEditTerrain.h"
|
|
#include <SceneManager.h>
|
|
#include "MainFrm.h"
|
|
#include "WorldCreatorView.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CDlgEditTerrain dialog
|
|
#define KeyPressed( key ) HIBYTE( GetAsyncKeyState( key ) )
|
|
|
|
CDlgEditTerrain::CDlgEditTerrain(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CDlgEditTerrain::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CDlgEditTerrain)
|
|
m_fHeight = 0.0f;
|
|
m_fMaxHeight =14000.0f;
|
|
m_fMinHeight = 0.0f;
|
|
m_isAddHeight = TRUE;
|
|
m_isSubHeight = FALSE;
|
|
m_isAdd1 = TRUE;
|
|
m_isAdd2 = FALSE;
|
|
m_isRange1 = TRUE;
|
|
m_isRange2 = FALSE;
|
|
m_isRange3 = FALSE;
|
|
m_isRange4 = FALSE;
|
|
m_fSelectedHeigth = 0.0f;
|
|
m_isSmallSmooth = FALSE;
|
|
m_fEndHeight = 0.0f;
|
|
m_fStartHeight = 0.0f;
|
|
m_isMakeRoad = FALSE;
|
|
m_fRoadWidth = 0.0f;
|
|
m_isMustDivide = FALSE;
|
|
m_isRange5 = FALSE;
|
|
m_isRange6 = FALSE;
|
|
m_fAllAddHeight = 0.0f;
|
|
//}}AFX_DATA_INIT
|
|
m_SelectSectorScene=NULL;
|
|
m_fAddHeight=100.0f;
|
|
}
|
|
|
|
|
|
void CDlgEditTerrain::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CDlgEditTerrain)
|
|
DDX_Text(pDX, IDC_EDIT_TERRAINHEIGHT, m_fHeight);
|
|
DDX_Text(pDX, IDC_EDIT_MAXHEIGHT, m_fMaxHeight);
|
|
DDX_Text(pDX, IDC_EDIT_MINHEIGHT, m_fMinHeight);
|
|
DDX_Check(pDX, IDC_CHECK_ADDHEIGHT, m_isAddHeight);
|
|
DDX_Check(pDX, IDC_CHECK_SUBHEIGHT, m_isSubHeight);
|
|
DDX_Check(pDX, IDC_CHECK_ADDHEIGHTVALUE1, m_isAdd1);
|
|
DDX_Check(pDX, IDC_CHECK_ADDHEIGHTVALUE2, m_isAdd2);
|
|
DDX_Check(pDX, IDC_CHECK_EDITRANGE1, m_isRange1);
|
|
DDX_Check(pDX, IDC_CHECK_EDITRANGE2, m_isRange2);
|
|
DDX_Check(pDX, IDC_CHECK_EDITRANGE3, m_isRange3);
|
|
DDX_Check(pDX, IDC_CHECK_EDITRANGE4, m_isRange4);
|
|
DDX_Text(pDX, IDC_EDIT_HEIGHT, m_fSelectedHeigth);
|
|
DDX_Check(pDX, IDC_CHECK_SMALLSMOOTH, m_isSmallSmooth);
|
|
DDX_Text(pDX, IDC_EDIT_ENDHEIGHT, m_fEndHeight);
|
|
DDX_Text(pDX, IDC_EDIT_STARTHEIGHT, m_fStartHeight);
|
|
DDX_Check(pDX, IDC_CHECK_MAKEROAD, m_isMakeRoad);
|
|
DDX_Text(pDX, IDC_EDIT_ROADWIDTH, m_fRoadWidth);
|
|
DDX_Check(pDX, IDC_CHECK_MUSTDIVIDE, m_isMustDivide);
|
|
DDX_Check(pDX, IDC_CHECK_EDITRANGE5, m_isRange5);
|
|
DDX_Check(pDX, IDC_CHECK_EDITRANGE6, m_isRange6);
|
|
DDX_Text(pDX, IDC_EDIT_ADDHEIGHT, m_fAllAddHeight);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CDlgEditTerrain, CDialog)
|
|
//{{AFX_MSG_MAP(CDlgEditTerrain)
|
|
ON_BN_CLICKED(IDC_CHECK_ADDHEIGHT, OnCheckAddheight)
|
|
ON_BN_CLICKED(IDC_CHECK_SUBHEIGHT, OnCheckSubheight)
|
|
ON_BN_CLICKED(IDC_BUTTON_TERRAINFASTUP, OnButtonTerrainfastup)
|
|
ON_BN_CLICKED(IDC_BUTTON_HEIGHTSLOWUP, OnButtonHeightslowup)
|
|
ON_BN_CLICKED(IDC_BUTTON_HEIGHTFASTDOWN, OnButtonHeightfastdown)
|
|
ON_BN_CLICKED(IDC_BUTTON_HEIGHTSLOWDOWN, OnButtonHeightslowdown)
|
|
ON_EN_CHANGE(IDC_EDIT_MAXHEIGHT, OnChangeEditMaxheight)
|
|
ON_EN_CHANGE(IDC_EDIT_MINHEIGHT, OnChangeEditMinheight)
|
|
ON_BN_CLICKED(IDC_BUTTON_TERRAINADJUST, OnButtonTerrainadjust)
|
|
ON_BN_CLICKED(IDC_CHECK_ADDHEIGHTVALUE1, OnCheckAddheightvalue1)
|
|
ON_BN_CLICKED(IDC_CHECK_ADDHEIGHTVALUE2, OnCheckAddheightvalue2)
|
|
ON_BN_CLICKED(IDC_CHECK_EDITRANGE1, OnCheckEditrange1)
|
|
ON_BN_CLICKED(IDC_CHECK_EDITRANGE2, OnCheckEditrange2)
|
|
ON_BN_CLICKED(IDC_CHECK_EDITRANGE3, OnCheckEditrange3)
|
|
ON_BN_CLICKED(IDC_CHECK_EDITRANGE4, OnCheckEditrange4)
|
|
ON_BN_CLICKED(IDC_BUTTON_TERRAINSMOOTH, OnButtonTerrainsmooth)
|
|
ON_BN_CLICKED(IDC_BUTTON_SECTOREDGEATTACH, OnButtonSectoredgeattach)
|
|
ON_BN_CLICKED(IDC_CHECK_SMALLSMOOTH, OnCheckSmallsmooth)
|
|
ON_EN_UPDATE(IDC_EDIT_STARTHEIGHT, OnUpdateEditStartheight)
|
|
ON_EN_UPDATE(IDC_EDIT_ENDHEIGHT, OnUpdateEditEndheight)
|
|
ON_BN_CLICKED(IDC_CHECK_MAKEROAD, OnCheckMakeroad)
|
|
ON_EN_UPDATE(IDC_EDIT_ROADWIDTH, OnUpdateEditRoadwidth)
|
|
ON_BN_CLICKED(IDC_CHECK_MUSTDIVIDE, OnCheckMustdivide)
|
|
ON_BN_CLICKED(IDC_CHECK_EDITRANGE5, OnCheckEditrange5)
|
|
ON_BN_CLICKED(IDC_CHECK_EDITRANGE6, OnCheckEditrange6)
|
|
ON_BN_CLICKED(IDC_BUTTON_ALLHEIGHTFIX, OnButtonAllheightfix)
|
|
ON_BN_CLICKED(IDC_BUTTON_HEIGHTFIX, OnButtonHeightfix)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CDlgEditTerrain message handlers
|
|
|
|
void CDlgEditTerrain::OnCheckAddheight()
|
|
{
|
|
UpdateData();
|
|
if(m_isAddHeight)
|
|
m_isSubHeight=FALSE;
|
|
else
|
|
m_isSubHeight=TRUE;
|
|
UpdateData(FALSE);
|
|
// TODO: Add your control notification handler code here
|
|
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckSubheight()
|
|
{
|
|
UpdateData();
|
|
if(m_isSubHeight)
|
|
m_isAddHeight=FALSE;
|
|
else
|
|
m_isAddHeight=TRUE;
|
|
UpdateData(FALSE);
|
|
// TODO: Add your control notification handler code here
|
|
|
|
}
|
|
|
|
BOOL CDlgEditTerrain::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
// TODO: Add extra initialization here
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CDlgEditTerrain::OnButtonTerrainfastup()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
m_fHeight+=1000.0f;
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CDlgEditTerrain::OnButtonHeightslowup()
|
|
{
|
|
UpdateData();
|
|
m_fHeight+=100.0f;
|
|
UpdateData(FALSE);
|
|
|
|
// TODO: Add your control notification handler code here
|
|
|
|
}
|
|
|
|
void CDlgEditTerrain::OnButtonHeightfastdown()
|
|
{
|
|
UpdateData();
|
|
m_fHeight-=1000.0f;
|
|
UpdateData(FALSE);
|
|
// TODO: Add your control notification handler code here
|
|
|
|
}
|
|
|
|
void CDlgEditTerrain::OnButtonHeightslowdown()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
m_fHeight-=100.0f;
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CDlgEditTerrain::InitForEditTerrrain()
|
|
{
|
|
if(m_SelectSectorScene==NULL)
|
|
return;
|
|
|
|
m_isSelectSceneEdit=FALSE;
|
|
for(int i=0;i<8;i++)
|
|
m_isSelectNeighborEdit[i]=FALSE;
|
|
|
|
SectorVertex *pEditSectorVertex;
|
|
WORD *pEditSectorIndices;
|
|
|
|
m_LeftDivideList.num=0;
|
|
m_RightDivideList.num=0;
|
|
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
m_SelectSectorScene->m_pROAMIndices->Lock(0,(SECTORSX-1)*(SECTORSY-1)*ROAMBUFFERSIZE*sizeof(WORD),(BYTE**)&pEditSectorIndices,0);
|
|
|
|
int ix,iy;
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX]=m_SelectSectorScene->m_SectorVertex[ix+iy*SECTORSX];
|
|
//pEditSectorVertex[ix+iy*SECTORSX].n=vector3(0.0f,1.0f,0.0f);
|
|
}
|
|
}
|
|
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY-1;iy++)
|
|
{
|
|
*(pEditSectorIndices++)=(ix+0)+(iy+0)*SECTORSX;
|
|
*(pEditSectorIndices++)=(ix+0)+(iy+1)*SECTORSX;
|
|
*(pEditSectorIndices++)=(ix+1)+(iy+0)*SECTORSX;
|
|
|
|
*(pEditSectorIndices++)=(ix+1)+(iy+0)*SECTORSX;
|
|
*(pEditSectorIndices++)=(ix+0)+(iy+1)*SECTORSX;
|
|
*(pEditSectorIndices++)=(ix+1)+(iy+1)*SECTORSX;
|
|
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_UsedVertex=SECTORSX*SECTORSY;
|
|
m_SelectSectorScene->m_UsedIndices=(SECTORSX-1)*(SECTORSY-1)*6;
|
|
m_SelectSectorScene->m_isEdit=true;
|
|
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
m_SelectSectorScene->m_pROAMIndices->Unlock();
|
|
|
|
POINT ptSectorList[8];
|
|
ptSectorList[0].x=0;
|
|
ptSectorList[0].y=0;
|
|
ptSectorList[1].x=SECTORSX-1;
|
|
ptSectorList[1].y=0;
|
|
ptSectorList[2].x=SECTORSX*2-2;
|
|
ptSectorList[2].y=0;
|
|
|
|
ptSectorList[3].x=0;
|
|
ptSectorList[3].y=SECTORSX-1;
|
|
ptSectorList[4].x=SECTORSX*2-2;
|
|
ptSectorList[4].y=SECTORSX-1;
|
|
|
|
ptSectorList[5].x=0;
|
|
ptSectorList[5].y=SECTORSX*2-2;
|
|
|
|
ptSectorList[6].x=SECTORSX-1;
|
|
ptSectorList[6].y=SECTORSX*2-2;
|
|
|
|
ptSectorList[7].x=SECTORSX*2-2;
|
|
ptSectorList[7].y=SECTORSX*2-2;
|
|
|
|
for(i=0;i<8;i++)
|
|
{
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
m_SelectNeighborScene[i]->m_pROAMIndices->Lock(0,(SECTORSX-1)*(SECTORSY-1)*ROAMBUFFERSIZE*sizeof(WORD),(BYTE**)&pEditSectorIndices,0);
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX]=m_SelectNeighborScene[i]->m_SectorVertex[ix+iy*SECTORSX];
|
|
//pEditSectorVertex[ix+iy*SECTORSX].n=vector3(0.0f,-1.0f,0.0f);
|
|
|
|
m_fSmoothHeight[ptSectorList[i].x+ix+(ptSectorList[i].y+iy)*((SECTORSY*3)-2)]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
}
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY-1;iy++)
|
|
{
|
|
*(pEditSectorIndices++)=(ix+0)+(iy+0)*SECTORSX;
|
|
*(pEditSectorIndices++)=(ix+0)+(iy+1)*SECTORSX;
|
|
*(pEditSectorIndices++)=(ix+1)+(iy+0)*SECTORSX;
|
|
|
|
*(pEditSectorIndices++)=(ix+1)+(iy+0)*SECTORSX;
|
|
*(pEditSectorIndices++)=(ix+0)+(iy+1)*SECTORSX;
|
|
*(pEditSectorIndices++)=(ix+1)+(iy+1)*SECTORSX;
|
|
|
|
}
|
|
}
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Unlock();
|
|
m_SelectNeighborScene[i]->m_pROAMIndices->Unlock();
|
|
m_SelectNeighborScene[i]->m_UsedVertex=SECTORSX*SECTORSY;
|
|
m_SelectNeighborScene[i]->m_UsedIndices=(SECTORSX-1)*(SECTORSY-1)*6;
|
|
m_SelectNeighborScene[i]->m_isEdit=true;
|
|
}
|
|
POINT ptSectorCenter;
|
|
ptSectorCenter.x=SECTORSX-1;
|
|
ptSectorCenter.y=SECTORSX-1;
|
|
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSX-1;iy++)
|
|
{
|
|
m_fSmoothHeight[ptSectorCenter.x+ix+(ptSectorCenter.y+iy)*((SECTORSY*3)-2)]=
|
|
pEditSectorVertex[ix+iy*(SECTORSX)].v.y;
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
|
|
CSceneManager::m_isTessellate=0;
|
|
}
|
|
|
|
void CDlgEditTerrain::MouseEdit(float fPx, float fPy, float fPz)
|
|
{
|
|
if(m_SelectSectorScene==NULL)
|
|
return;
|
|
SectorVertex *pEditSectorVertex;
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
int ix,iy;
|
|
vector3 vecTerrainPos,vecLens;
|
|
vector3 vecMousePos;
|
|
|
|
matrix matTerrainTM,matTM;
|
|
matTerrainTM=m_SelectSectorScene->m_AccumulateTM;
|
|
matTM.Translation(vector3(fPx,fPy,fPz));
|
|
matTerrainTM.Inverse(matTerrainTM);
|
|
matTM=matTM*matTerrainTM;
|
|
|
|
vecMousePos=matTM.GetLoc();
|
|
vecMousePos.y=0.0f;
|
|
BOOL SaveisAddHeight=m_isAddHeight;
|
|
|
|
if(KeyPressed(VK_CONTROL))
|
|
m_isAddHeight=TRUE;
|
|
if(KeyPressed(VK_MENU))
|
|
m_isAddHeight=FALSE;
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
vecTerrainPos=vector3(pEditSectorVertex[ix+iy*SECTORSX].v.x,0.0f,pEditSectorVertex[ix+iy*SECTORSX].v.z);
|
|
vecLens=vecTerrainPos-vecMousePos;
|
|
if(vecLens.GetLens()<=m_fRange)
|
|
{
|
|
m_isSelectSceneEdit=TRUE;
|
|
if(m_isAddHeight)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y+=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y>=m_fMaxHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMaxHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y-=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y<=m_fMinHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMinHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
|
|
|
|
for(int i=0;i<8;i++)
|
|
{
|
|
matTerrainTM=m_SelectNeighborScene[i]->m_AccumulateTM;
|
|
matTM.Translation(vector3(fPx,fPy,fPz));
|
|
matTerrainTM.Inverse(matTerrainTM);
|
|
matTM=matTM*matTerrainTM;
|
|
|
|
vecMousePos=matTM.GetLoc();
|
|
vecMousePos.y=0.0f;
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
vecTerrainPos=vector3(pEditSectorVertex[ix+iy*SECTORSX].v.x,0.0f,pEditSectorVertex[ix+iy*SECTORSX].v.z);
|
|
vecLens=vecTerrainPos-vecMousePos;
|
|
if(vecLens.GetLens()<=m_fRange)
|
|
{
|
|
m_isSelectNeighborEdit[i]=TRUE;
|
|
if(m_isAddHeight)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y+=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y>=m_fMaxHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMaxHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y-=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y<=m_fMinHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMinHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Unlock();
|
|
|
|
}
|
|
m_isAddHeight=SaveisAddHeight;
|
|
|
|
/*
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
vecTerrainPos=vector3(pEditSectorVertex[ix+iy*SECTORSX].v.x,0.0f,pEditSectorVertex[ix+iy*SECTORSX].v.z);
|
|
vecLens=vecTerrainPos-vecMousePos;
|
|
if(vecLens.GetLens()<=m_fRange)
|
|
{
|
|
m_isSelectSceneEdit=TRUE;
|
|
if(m_isAddHeight)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y+=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y>=m_fMaxHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMaxHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y-=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y<=m_fMinHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMinHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
if(ix==0)
|
|
{
|
|
m_SelectNeighborScene[3]->m_HeightData[(SECTORSX-1)+iy*SECTORSX]=
|
|
m_SelectNeighborScene[3]->m_SectorVertex[(SECTORSX-1)+iy*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[3]=TRUE;
|
|
}
|
|
if(ix==SECTORSX-1)
|
|
{
|
|
m_SelectNeighborScene[4]->m_HeightData[0+iy*SECTORSX]=
|
|
m_SelectNeighborScene[4]->m_SectorVertex[0+iy*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[4]=TRUE;
|
|
}
|
|
if(iy==0)
|
|
{
|
|
m_SelectNeighborScene[1]->m_HeightData[ix+(SECTORSY-1)*SECTORSX]=
|
|
m_SelectNeighborScene[1]->m_SectorVertex[ix+(SECTORSY-1)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[1]=TRUE;
|
|
}
|
|
if(iy==SECTORSY-1)
|
|
{
|
|
m_SelectNeighborScene[6]->m_HeightData[ix+(0)*SECTORSX]=
|
|
m_SelectNeighborScene[6]->m_SectorVertex[ix+(0)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[6]=TRUE;
|
|
}
|
|
if(ix==0 && iy==0)
|
|
{
|
|
m_SelectNeighborScene[0]->m_HeightData[(SECTORSX-1)+(SECTORSY-1)*SECTORSX]=
|
|
m_SelectNeighborScene[0]->m_SectorVertex[(SECTORSX-1)+(SECTORSY-1)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[0]=TRUE;
|
|
}
|
|
|
|
if(ix==0 && iy==SECTORSY-1)
|
|
{
|
|
m_SelectNeighborScene[5]->m_HeightData[(SECTORSX-1)+(0)*SECTORSX]=
|
|
m_SelectNeighborScene[5]->m_SectorVertex[(SECTORSX-1)+(0)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[5]=TRUE;
|
|
}
|
|
|
|
if(ix==SECTORSX-1 && iy==0)
|
|
{
|
|
m_SelectNeighborScene[2]->m_HeightData[(0)+(SECTORSY-1)*SECTORSX]=
|
|
m_SelectNeighborScene[2]->m_SectorVertex[(0)+(SECTORSY-1)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[2]=TRUE;
|
|
}
|
|
|
|
if(ix==SECTORSX-1 && iy==SECTORSY-1)
|
|
{
|
|
m_SelectNeighborScene[7]->m_HeightData[(0)+(0)*SECTORSX]=
|
|
m_SelectNeighborScene[7]->m_SectorVertex[(0)+(0)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[7]=TRUE;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
void CDlgEditTerrain::OnChangeEditMaxheight()
|
|
{
|
|
UpdateData();
|
|
}
|
|
|
|
void CDlgEditTerrain::OnChangeEditMinheight()
|
|
{
|
|
UpdateData();
|
|
}
|
|
|
|
void CDlgEditTerrain::EndAndSave()
|
|
{
|
|
if(m_SelectSectorScene==NULL)
|
|
return;
|
|
SectorVertex *pEditSectorVertex;
|
|
float pSaveHeightData[SECTORSX*SECTORSY];
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
int ix,iy;
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
m_SelectSectorScene->m_SectorVertex[ix+iy*SECTORSX].v=pEditSectorVertex[ix+iy*SECTORSX].v;
|
|
pSaveHeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
//if(m_isSelectSceneEdit)
|
|
{
|
|
CMainFrame *mf=(CMainFrame*)AfxGetApp()->m_pMainWnd;
|
|
CWorldCreatorView *av=(CWorldCreatorView *)mf->GetActiveView();
|
|
av->m_SceneManager->m_MapStorage.AddHeightMap(m_SelectSectorScene->m_AccumulateTM._41,0.0f,
|
|
m_SelectSectorScene->m_AccumulateTM._43,pSaveHeightData);
|
|
/*
|
|
CMapStorage::AddHeightMap(m_SelectSectorScene->m_AccumulateTM._41,0.0f,
|
|
m_SelectSectorScene->m_AccumulateTM._43,pSaveHeightData);
|
|
*/
|
|
}
|
|
m_SelectSectorScene->CalcNormal();
|
|
m_SelectSectorScene->ComputeVariance();
|
|
m_SelectSectorScene->GeneratePlant();
|
|
m_SelectSectorScene->Init();
|
|
|
|
if(m_SelectSectorScene->m_MapMustDivideVertex)
|
|
{
|
|
m_LeftDivideList.num=0;
|
|
m_RightDivideList.num=0;
|
|
for(int cVertex=0;cVertex<m_SelectSectorScene->m_MapMustDivideVertex->m_ptMustDivideVertexPosList.num;cVertex++)
|
|
{
|
|
SetMustDivideVertex(m_SelectSectorScene->m_MapMustDivideVertex->m_ptMustDivideVertexPosList[cVertex].x,
|
|
m_SelectSectorScene->m_MapMustDivideVertex->m_ptMustDivideVertexPosList[cVertex].y);
|
|
}
|
|
for(int cLeft=0;cLeft<m_LeftDivideList.num;cLeft++)
|
|
{
|
|
m_SelectSectorScene->m_VarianceLeft[m_LeftDivideList[cLeft]]=10000000;
|
|
}
|
|
for(int cRight=0;cRight<m_RightDivideList.num;cRight++)
|
|
{
|
|
m_SelectSectorScene->m_VarianceRight[m_RightDivideList[cRight]]=10000000;
|
|
}
|
|
memcpy(m_SelectSectorScene->m_MapMustDivideVertex->m_pLeftNodeList,m_SelectSectorScene->m_VarianceLeft,sizeof(int)*(1<<(VARIANCE_DEPTH)));
|
|
memcpy(m_SelectSectorScene->m_MapMustDivideVertex->m_pRightNodeList,m_SelectSectorScene->m_VarianceRight,sizeof(int)*(1<<(VARIANCE_DEPTH)));
|
|
}
|
|
m_LeftDivideList.num=0;
|
|
m_RightDivideList.num=0;
|
|
|
|
for(int i=0;i<8;i++)
|
|
{
|
|
//if(m_isSelectNeighborEdit[i])
|
|
{
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
//m_SelectSectorScene->m_SectorVertex[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX];
|
|
m_SelectNeighborScene[i]->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_SelectNeighborScene[i]->m_SectorVertex[ix+iy*SECTORSX].v=pEditSectorVertex[ix+iy*SECTORSX].v;
|
|
pSaveHeightData[ix+iy*SECTORSX]=m_SelectNeighborScene[i]->m_HeightData[ix+iy*SECTORSX];
|
|
}
|
|
}
|
|
CMainFrame *mf=(CMainFrame*)AfxGetApp()->m_pMainWnd;
|
|
CWorldCreatorView *av=(CWorldCreatorView *)mf->GetActiveView();
|
|
av->m_SceneManager->m_MapStorage.AddHeightMap(m_SelectNeighborScene[i]->m_AccumulateTM._41,0.0f,
|
|
m_SelectNeighborScene[i]->m_AccumulateTM._43,pSaveHeightData);
|
|
/*
|
|
CMapStorage::AddHeightMap(m_SelectNeighborScene[i]->m_AccumulateTM._41,0.0f,
|
|
m_SelectNeighborScene[i]->m_AccumulateTM._43,pSaveHeightData);
|
|
*/
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Unlock();
|
|
}
|
|
}
|
|
|
|
|
|
for(i=0;i<8;i++)
|
|
{
|
|
m_SelectNeighborScene[i]->CalcNormal();
|
|
m_SelectNeighborScene[i]->ComputeVariance();
|
|
m_SelectNeighborScene[i]->GeneratePlant();
|
|
m_SelectNeighborScene[i]->m_isEdit=false;
|
|
m_SelectNeighborScene[i]->Init();
|
|
|
|
}
|
|
}
|
|
|
|
void CDlgEditTerrain::OnButtonTerrainadjust()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
if(m_SelectSectorScene==NULL)
|
|
return;
|
|
|
|
SectorVertex *pEditSectorVertex;
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
int ix,iy;
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fHeight;
|
|
}
|
|
}
|
|
m_isSelectSceneEdit=TRUE;
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=
|
|
m_fHeight;
|
|
if(ix==0)
|
|
{
|
|
m_SelectNeighborScene[3]->m_HeightData[(SECTORSX-1)+iy*SECTORSX]=
|
|
m_SelectNeighborScene[3]->m_SectorVertex[(SECTORSX-1)+iy*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[3]=TRUE;
|
|
}
|
|
if(ix==SECTORSX-1)
|
|
{
|
|
m_SelectNeighborScene[4]->m_HeightData[0+iy*SECTORSX]=
|
|
m_SelectNeighborScene[4]->m_SectorVertex[0+iy*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[4]=TRUE;
|
|
}
|
|
if(iy==0)
|
|
{
|
|
m_SelectNeighborScene[1]->m_HeightData[ix+(SECTORSY-1)*SECTORSX]=
|
|
m_SelectNeighborScene[1]->m_SectorVertex[ix+(SECTORSY-1)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[1]=TRUE;
|
|
}
|
|
if(iy==SECTORSY-1)
|
|
{
|
|
m_SelectNeighborScene[6]->m_HeightData[ix+(0)*SECTORSX]=
|
|
m_SelectNeighborScene[6]->m_SectorVertex[ix+(0)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[6]=TRUE;
|
|
}
|
|
if(ix==0 && iy==0)
|
|
{
|
|
m_SelectNeighborScene[0]->m_HeightData[(SECTORSX-1)+(SECTORSY-1)*SECTORSX]=
|
|
m_SelectNeighborScene[0]->m_SectorVertex[(SECTORSX-1)+(SECTORSY-1)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[0]=TRUE;
|
|
}
|
|
|
|
if(ix==0 && iy==SECTORSY-1)
|
|
{
|
|
m_SelectNeighborScene[5]->m_HeightData[(SECTORSX-1)+(0)*SECTORSX]=
|
|
m_SelectNeighborScene[5]->m_SectorVertex[(SECTORSX-1)+(0)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[5]=TRUE;
|
|
}
|
|
|
|
if(ix==SECTORSX-1 && iy==0)
|
|
{
|
|
m_SelectNeighborScene[2]->m_HeightData[(0)+(SECTORSY-1)*SECTORSX]=
|
|
m_SelectNeighborScene[2]->m_SectorVertex[(0)+(SECTORSY-1)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[2]=TRUE;
|
|
}
|
|
|
|
if(ix==SECTORSX-1 && iy==SECTORSY-1)
|
|
{
|
|
m_SelectNeighborScene[7]->m_HeightData[(0)+(0)*SECTORSX]=
|
|
m_SelectNeighborScene[7]->m_SectorVertex[(0)+(0)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[7]=TRUE;
|
|
}
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckAddheightvalue1()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
if(m_isAdd1)
|
|
{
|
|
m_fAddHeight=500.0f;
|
|
m_isAdd2=FALSE;
|
|
}
|
|
else
|
|
{
|
|
m_fAddHeight=50.0f;
|
|
m_isAdd2=TRUE;
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckAddheightvalue2()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
if(m_isAdd2)
|
|
{
|
|
m_fAddHeight=50.0f;
|
|
m_isAdd1=FALSE;
|
|
}
|
|
else
|
|
{
|
|
m_fAddHeight=500.0f;
|
|
m_isAdd1=TRUE;
|
|
}
|
|
UpdateData(FALSE);
|
|
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckEditrange1()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
if(m_isRange1)
|
|
{
|
|
m_fRange=100.0f;
|
|
m_isRange2=FALSE;
|
|
m_isRange3=FALSE;
|
|
m_isRange4=FALSE;
|
|
m_isRange5=FALSE;
|
|
m_isRange6=FALSE;
|
|
}
|
|
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckEditrange2()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
if(m_isRange2)
|
|
{
|
|
m_fRange=800.0f;
|
|
m_isRange1=FALSE;
|
|
m_isRange3=FALSE;
|
|
m_isRange4=FALSE;
|
|
m_isRange5=FALSE;
|
|
m_isRange6=FALSE;
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckEditrange3()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
if(m_isRange3)
|
|
{
|
|
m_fRange=1200.0f;
|
|
m_isRange1=FALSE;
|
|
m_isRange2=FALSE;
|
|
m_isRange4=FALSE;
|
|
m_isRange5=FALSE;
|
|
m_isRange6=FALSE;
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckEditrange4()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
if(m_isRange4)
|
|
{
|
|
m_fRange=2000.0f;
|
|
m_isRange1=FALSE;
|
|
m_isRange2=FALSE;
|
|
m_isRange3=FALSE;
|
|
m_isRange5=FALSE;
|
|
m_isRange6=FALSE;
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CDlgEditTerrain::OnButtonTerrainsmooth()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
|
|
SectorVertex *pEditSectorVertex;
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
float fAvgHeight;
|
|
int ix,iy;
|
|
for(ix=1;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=1;iy<SECTORSY-1;iy++)
|
|
{
|
|
fAvgHeight=0.0f;
|
|
fAvgHeight+=pEditSectorVertex[(ix-1)+(iy-1)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+0)+(iy-1)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+1)+(iy-1)*SECTORSX].v.y;
|
|
|
|
fAvgHeight+=pEditSectorVertex[(ix-1)+(iy)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+0)+(iy)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+1)+(iy)*SECTORSX].v.y;
|
|
|
|
fAvgHeight+=pEditSectorVertex[(ix-1)+(iy+1)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+1)+(iy+1)*SECTORSX].v.y;
|
|
|
|
fAvgHeight+=pEditSectorVertex[(ix+0)+(iy)*SECTORSX].v.y;
|
|
|
|
fAvgHeight/=10.0f;
|
|
|
|
pEditSectorVertex[(ix+0)+(iy)*SECTORSX].v.y=fAvgHeight;
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
/*
|
|
for(int i=0;i<8;i++)
|
|
{
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
for(ix=1;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=1;iy<SECTORSY-1;iy++)
|
|
{
|
|
fAvgHeight=0.0f;
|
|
fAvgHeight+=pEditSectorVertex[(ix-1)+(iy-1)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+0)+(iy-1)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+1)+(iy-1)*SECTORSX].v.y;
|
|
|
|
fAvgHeight+=pEditSectorVertex[(ix-1)+(iy)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+0)+(iy)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+1)+(iy)*SECTORSX].v.y;
|
|
|
|
fAvgHeight+=pEditSectorVertex[(ix-1)+(iy+1)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v.y;
|
|
fAvgHeight+=pEditSectorVertex[(ix+1)+(iy+1)*SECTORSX].v.y;
|
|
|
|
fAvgHeight+=pEditSectorVertex[(ix+0)+(iy)*SECTORSX].v.y;
|
|
|
|
fAvgHeight/=10.0f;
|
|
|
|
pEditSectorVertex[(ix+0)+(iy)*SECTORSX].v.y=fAvgHeight;
|
|
}
|
|
}
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Unlock();
|
|
}
|
|
*/
|
|
}
|
|
|
|
void CDlgEditTerrain::OnButtonSectoredgeattach()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
SectorEdgeAttach();
|
|
}
|
|
|
|
void CDlgEditTerrain::SectorEdgeAttach()
|
|
{
|
|
SectorVertex *pEditSectorVertex;
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
SectorVertex *pEditNeighborVertex[8];
|
|
|
|
for(int i=0;i<8;i++)
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditNeighborVertex[i],0);
|
|
|
|
int ix,iy;
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
if(ix==0)
|
|
{
|
|
pEditNeighborVertex[3][(SECTORSX-1)+iy*SECTORSX].v.y=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[3]=TRUE;
|
|
}
|
|
if(ix==SECTORSX-1)
|
|
{
|
|
pEditNeighborVertex[4][0+iy*SECTORSX].v.y=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[4]=TRUE;
|
|
}
|
|
if(iy==0)
|
|
{
|
|
pEditNeighborVertex[1][ix+(SECTORSY-1)*SECTORSX].v.y=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[1]=TRUE;
|
|
}
|
|
if(iy==SECTORSY-1)
|
|
{
|
|
pEditNeighborVertex[6][ix+(0)*SECTORSX].v.y=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[6]=TRUE;
|
|
}
|
|
if(ix==0 && iy==0)
|
|
{
|
|
pEditNeighborVertex[0][(SECTORSX-1)+(SECTORSY-1)*SECTORSX].v.y=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[0]=TRUE;
|
|
}
|
|
|
|
if(ix==0 && iy==SECTORSY-1)
|
|
{
|
|
pEditNeighborVertex[5][(SECTORSX-1)+(0)*SECTORSX].v.y=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[5]=TRUE;
|
|
}
|
|
if(ix==SECTORSX-1 && iy==0)
|
|
{
|
|
pEditNeighborVertex[2][(0)+(SECTORSY-1)*SECTORSX].v.y=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[2]=TRUE;
|
|
}
|
|
|
|
if(ix==SECTORSX-1 && iy==SECTORSY-1)
|
|
{
|
|
pEditNeighborVertex[7][(0)+(0)*SECTORSX].v.y=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[7]=TRUE;
|
|
}
|
|
|
|
/*
|
|
if(ix==SECTORSX-1)
|
|
{
|
|
if(m_SelectNeighborScene[4]->m_SectorVertex[0+iy*SECTORSX].v.y!=pEditSectorVertex[ix+iy*SECTORSX].v.y)
|
|
{
|
|
m_SelectNeighborScene[4]->m_HeightData[0+iy*SECTORSX]=
|
|
m_SelectNeighborScene[4]->m_SectorVertex[0+iy*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[4]=TRUE;
|
|
}
|
|
}
|
|
if(iy==0)
|
|
{
|
|
if(m_SelectNeighborScene[1]->m_SectorVertex[ix+(SECTORSY-1)*SECTORSX].v.y!=pEditSectorVertex[ix+iy*SECTORSX].v.y)
|
|
{
|
|
m_SelectNeighborScene[1]->m_HeightData[ix+(SECTORSY-1)*SECTORSX]=
|
|
m_SelectNeighborScene[1]->m_SectorVertex[ix+(SECTORSY-1)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[1]=TRUE;
|
|
}
|
|
}
|
|
if(iy==SECTORSY-1)
|
|
{
|
|
if(m_SelectNeighborScene[6]->m_SectorVertex[ix+(0)*SECTORSX].v.y!=pEditSectorVertex[ix+iy*SECTORSX].v.y)
|
|
{
|
|
m_SelectNeighborScene[6]->m_HeightData[ix+(0)*SECTORSX]=
|
|
m_SelectNeighborScene[6]->m_SectorVertex[ix+(0)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[6]=TRUE;
|
|
}
|
|
}
|
|
if(ix==0 && iy==0)
|
|
{
|
|
m_SelectNeighborScene[0]->m_HeightData[(SECTORSX-1)+(SECTORSY-1)*SECTORSX]=
|
|
m_SelectNeighborScene[0]->m_SectorVertex[(SECTORSX-1)+(SECTORSY-1)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[0]=TRUE;
|
|
}
|
|
|
|
if(ix==0 && iy==SECTORSY-1)
|
|
{
|
|
m_SelectNeighborScene[5]->m_HeightData[(SECTORSX-1)+(0)*SECTORSX]=
|
|
m_SelectNeighborScene[5]->m_SectorVertex[(SECTORSX-1)+(0)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[5]=TRUE;
|
|
}
|
|
|
|
if(ix==SECTORSX-1 && iy==0)
|
|
{
|
|
m_SelectNeighborScene[2]->m_HeightData[(0)+(SECTORSY-1)*SECTORSX]=
|
|
m_SelectNeighborScene[2]->m_SectorVertex[(0)+(SECTORSY-1)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[2]=TRUE;
|
|
}
|
|
|
|
if(ix==SECTORSX-1 && iy==SECTORSY-1)
|
|
{
|
|
m_SelectNeighborScene[7]->m_HeightData[(0)+(0)*SECTORSX]=
|
|
m_SelectNeighborScene[7]->m_SectorVertex[(0)+(0)*SECTORSX].v.y=
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_isSelectNeighborEdit[7]=TRUE;
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
for(i=0;i<8;i++)
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Unlock();
|
|
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
}
|
|
|
|
void CDlgEditTerrain::MouseEdit(vector3 vecStart,vector3 vecDir)
|
|
{
|
|
if(m_SelectSectorScene==NULL)
|
|
return;
|
|
SectorVertex *pEditSectorVertex;
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
SectorVertex *pNeighborSectorVertex[8];
|
|
for(int i=0;i<8;i++)
|
|
{
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Lock(0,0,(BYTE**)&pNeighborSectorVertex[i],0);
|
|
}
|
|
|
|
|
|
int ix,iy;
|
|
|
|
vector3 vecTerrainPos,vecLens;
|
|
vector3 vecMousePos;
|
|
|
|
float fIntersection;
|
|
|
|
vector3 vecIntersectionPoint;
|
|
vecIntersectionPoint.x=-1.0f;
|
|
|
|
vector3 vecCollisionVertex[3];
|
|
|
|
matrix matTerrainTM,matTM;
|
|
matTerrainTM=m_SelectSectorScene->m_AccumulateTM;
|
|
matTM.Translation(vecStart);
|
|
matTerrainTM.Inverse(matTerrainTM);
|
|
matTM=matTM*matTerrainTM;
|
|
vecStart=matTM.GetLoc();
|
|
|
|
float fLens=100000000.0f;
|
|
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY-1;iy++)
|
|
{
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+0)+(iy+0)*SECTORSX].v;
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v;
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v;
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+100000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
}
|
|
}
|
|
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v;
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v;
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+1)*SECTORSX].v;
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+100000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(vecIntersectionPoint.x==-1)
|
|
{
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
for(int i=0;i<8;i++)
|
|
{
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Unlock();
|
|
}
|
|
return;
|
|
}
|
|
|
|
//matTM.Translation(vecIntersectionPoint);
|
|
//matTM=matTM*matTerrainTM;
|
|
|
|
vecMousePos=vecIntersectionPoint;//matTM.GetLoc();
|
|
vecMousePos.y=0.0f;
|
|
BOOL SaveisAddHeight=m_isAddHeight;
|
|
|
|
if(KeyPressed(VK_CONTROL))
|
|
m_isAddHeight=TRUE;
|
|
if(KeyPressed(VK_MENU))
|
|
m_isAddHeight=FALSE;
|
|
|
|
//List<float*> SmoothVertexList;
|
|
List<POINT> SmoothVertexList;
|
|
List<POINT> SmoothVertexNeigborList[8];
|
|
|
|
vector3 vecSideMousePos[8];
|
|
vecSideMousePos[0]=vector3(vecMousePos.x+SECTORSIZE,0.0f,vecMousePos.z+SECTORSIZE);
|
|
vecSideMousePos[1]=vector3(vecMousePos.x,0.0f,vecMousePos.z+SECTORSIZE);
|
|
vecSideMousePos[2]=vector3(vecMousePos.x-SECTORSIZE,0.0f,vecMousePos.z+SECTORSIZE);
|
|
|
|
vecSideMousePos[3]=vector3(vecMousePos.x+SECTORSIZE,0.0f,vecMousePos.z);
|
|
vecSideMousePos[4]=vector3(vecMousePos.x-SECTORSIZE,0.0f,vecMousePos.z);
|
|
|
|
vecSideMousePos[5]=vector3(vecMousePos.x+SECTORSIZE,0.0f,vecMousePos.z-SECTORSIZE);
|
|
vecSideMousePos[6]=vector3(vecMousePos.x,0.0f,vecMousePos.z-SECTORSIZE);
|
|
vecSideMousePos[7]=vector3(vecMousePos.x-SECTORSIZE,0.0f,vecMousePos.z-SECTORSIZE);
|
|
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
vecTerrainPos=vector3(pEditSectorVertex[ix+iy*SECTORSX].v.x,0.0f,pEditSectorVertex[ix+iy*SECTORSX].v.z);
|
|
vecLens=vecTerrainPos-vecMousePos;
|
|
if(vecLens.GetLens()<=m_fRange)
|
|
{
|
|
m_isSelectSceneEdit=TRUE;
|
|
|
|
if(m_isSmallSmooth)
|
|
{
|
|
POINT ptVertexPos;
|
|
ptVertexPos.x=ix;
|
|
ptVertexPos.y=iy;
|
|
SmoothVertexList.Add(ptVertexPos);
|
|
//SmoothVertexList.Add(&pEditSectorVertex[ix+iy*SECTORSX].v.y);
|
|
}
|
|
else
|
|
{
|
|
if(m_isAddHeight)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y+=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y>=m_fMaxHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMaxHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y-=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y<=m_fMinHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMinHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
bool bAlready=false;
|
|
List<int> SeekSectorList;
|
|
if( vecIntersectionPoint.x-m_fRange<0.0f &&
|
|
vecIntersectionPoint.z-m_fRange<0.0f)//side 0
|
|
{
|
|
SeekSectorList.Add(0);
|
|
SeekSectorList.Add(1);
|
|
SeekSectorList.Add(3);
|
|
bAlready=true;
|
|
}
|
|
|
|
if( vecIntersectionPoint.x+m_fRange>SECTORSIZE &&
|
|
vecIntersectionPoint.z-m_fRange<0.0f && bAlready==false)//side 2
|
|
{
|
|
SeekSectorList.Add(1);
|
|
SeekSectorList.Add(2);
|
|
SeekSectorList.Add(4);
|
|
bAlready=true;
|
|
}
|
|
|
|
if( vecIntersectionPoint.x-m_fRange<0.0f &&
|
|
vecIntersectionPoint.z+m_fRange>SECTORSIZE && bAlready==false)//5
|
|
{
|
|
SeekSectorList.Add(3);
|
|
SeekSectorList.Add(5);
|
|
SeekSectorList.Add(6);
|
|
bAlready=true;
|
|
}
|
|
|
|
if( vecIntersectionPoint.x+m_fRange>SECTORSIZE &&
|
|
vecIntersectionPoint.z+m_fRange>SECTORSIZE && bAlready==false)//7
|
|
{
|
|
SeekSectorList.Add(4);
|
|
SeekSectorList.Add(7);
|
|
SeekSectorList.Add(6);
|
|
bAlready=true;
|
|
}
|
|
|
|
if( vecIntersectionPoint.x-m_fRange<0.0f && bAlready==false)//3
|
|
{
|
|
SeekSectorList.Add(3);
|
|
bAlready=true;
|
|
}
|
|
|
|
if( vecIntersectionPoint.x+m_fRange>SECTORSIZE && bAlready==false)//4
|
|
{
|
|
SeekSectorList.Add(4);
|
|
bAlready=true;
|
|
}
|
|
|
|
if( vecIntersectionPoint.z-m_fRange<0.0f && bAlready==false)//1
|
|
{
|
|
SeekSectorList.Add(1);
|
|
bAlready=true;
|
|
}
|
|
|
|
if( vecIntersectionPoint.z+m_fRange>SECTORSIZE && bAlready==false)// 6
|
|
{
|
|
SeekSectorList.Add(6);
|
|
bAlready=true;
|
|
}
|
|
|
|
for(i=0;i<SeekSectorList.num;i++)
|
|
{
|
|
SeekSectorList[i];
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
vecTerrainPos=vector3(pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.x,0.0f,pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.z);
|
|
vecLens=vecTerrainPos-vecSideMousePos[SeekSectorList[i]];
|
|
if(vecLens.GetLens()<=m_fRange)
|
|
{
|
|
m_isSelectSceneEdit=TRUE;
|
|
|
|
if(m_isSmallSmooth)
|
|
{
|
|
POINT ptVertexPos;
|
|
ptVertexPos.x=ix;
|
|
ptVertexPos.y=iy;
|
|
SmoothVertexNeigborList[SeekSectorList[i]].Add(ptVertexPos);
|
|
//SmoothVertexList.Add(&pEditSectorVertex[ix+iy*SECTORSX].v.y);
|
|
}
|
|
else
|
|
{
|
|
if(m_isAddHeight)
|
|
{
|
|
pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.y+=m_fAddHeight;
|
|
if(pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.y>=m_fMaxHeight)
|
|
pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.y=m_fMaxHeight;
|
|
m_SelectNeighborScene[SeekSectorList[i]]->m_HeightData[ix+iy*SECTORSX]=pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.y-=m_fAddHeight;
|
|
if(pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.y<=m_fMinHeight)
|
|
pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.y=m_fMinHeight;
|
|
m_SelectNeighborScene[SeekSectorList[i]]->m_HeightData[ix+iy*SECTORSX]=pNeighborSectorVertex[SeekSectorList[i]][ix+iy*SECTORSX].v.y;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if(m_isSmallSmooth)
|
|
{
|
|
float fAvgHeight;
|
|
float fNeighborHeight[9];
|
|
List<POINT> FixPointPos[8];
|
|
POINT ptFix;
|
|
for(int i=0;i<SmoothVertexList.num;i++)
|
|
{
|
|
fAvgHeight=0.0f;
|
|
|
|
//0
|
|
if(SmoothVertexList[i].x==0 || SmoothVertexList[i].y==0)
|
|
{
|
|
if(SmoothVertexList[i].x==0 && SmoothVertexList[i].y==0)
|
|
{
|
|
fNeighborHeight[0]=pNeighborSectorVertex[0][SECTORSX-2+(SECTORSY-2)*SECTORSX].v.y;
|
|
ptFix.x=SECTORSX-1;
|
|
ptFix.y=SECTORSY-1;
|
|
FixPointPos[0].Add(ptFix);
|
|
}
|
|
else if(SmoothVertexList[i].x==0)
|
|
{
|
|
fNeighborHeight[0]=pNeighborSectorVertex[3][SECTORSX-2+(SmoothVertexList[i].y-1)*SECTORSX].v.y;
|
|
ptFix.x=SECTORSX-1;
|
|
ptFix.y=SmoothVertexList[i].y;
|
|
FixPointPos[3].Add(ptFix);
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[0]=pNeighborSectorVertex[1][(SmoothVertexList[i].x-1)+(SECTORSY-2)*SECTORSX].v.y;
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[0]=pEditSectorVertex[(SmoothVertexList[i].x-1)+(SmoothVertexList[i].y-1)*SECTORSX].v.y;
|
|
}
|
|
//1
|
|
if(SmoothVertexList[i].y==0)
|
|
{
|
|
fNeighborHeight[1]=pNeighborSectorVertex[1][(SmoothVertexList[i].x)+(SECTORSY-2)*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[1]=pEditSectorVertex[(SmoothVertexList[i].x+0)+(SmoothVertexList[i].y-1)*SECTORSX].v.y;
|
|
}
|
|
//2
|
|
if(SmoothVertexList[i].x==SECTORSX-1 || SmoothVertexList[i].y==0)
|
|
{
|
|
if(SmoothVertexList[i].x==SECTORSX-1 && SmoothVertexList[i].y==0)
|
|
{
|
|
fNeighborHeight[2]=pNeighborSectorVertex[2][1+(SECTORSY-2)*SECTORSX].v.y;
|
|
}
|
|
else if(SmoothVertexList[i].x==SECTORSX-1)
|
|
{
|
|
fNeighborHeight[2]=pNeighborSectorVertex[4][1+(SmoothVertexList[i].y-1)*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[2]=pNeighborSectorVertex[1][SmoothVertexList[i].x+1+(SECTORSY-2)*SECTORSX].v.y;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[2]=pEditSectorVertex[(SmoothVertexList[i].x+1)+(SmoothVertexList[i].y-1)*SECTORSX].v.y;
|
|
}
|
|
//3
|
|
if(SmoothVertexList[i].x==0)
|
|
{
|
|
fNeighborHeight[3]=pNeighborSectorVertex[3][SECTORSX-2+(SmoothVertexList[i].y)*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[3]=pEditSectorVertex[(SmoothVertexList[i].x-1)+(SmoothVertexList[i].y)*SECTORSX].v.y;
|
|
}
|
|
//4
|
|
fNeighborHeight[4]=pEditSectorVertex[(SmoothVertexList[i].x+0)+(SmoothVertexList[i].y)*SECTORSX].v.y;
|
|
//5
|
|
if(SmoothVertexList[i].x==SECTORSX-1)
|
|
{
|
|
fNeighborHeight[5]=pNeighborSectorVertex[4][1+(SmoothVertexList[i].y)*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[5]=pEditSectorVertex[(SmoothVertexList[i].x+1)+(SmoothVertexList[i].y)*SECTORSX].v.y;
|
|
}
|
|
//6
|
|
if(SmoothVertexList[i].x==0 || SmoothVertexList[i].y==SECTORSY-1)
|
|
{
|
|
if(SmoothVertexList[i].x==0 && SmoothVertexList[i].y==SECTORSY-1)
|
|
{
|
|
fNeighborHeight[6]=pNeighborSectorVertex[5][SECTORSX-2+(1)*SECTORSX].v.y;
|
|
}
|
|
else if(SmoothVertexList[i].x==0)
|
|
{
|
|
fNeighborHeight[6]=pNeighborSectorVertex[3][SECTORSX-2+(SmoothVertexList[i].y+1)*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[6]=pNeighborSectorVertex[6][SmoothVertexList[i].x-1+(1)*SECTORSX].v.y;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[6]=pEditSectorVertex[(SmoothVertexList[i].x-1)+(SmoothVertexList[i].y+1)*SECTORSX].v.y;
|
|
}
|
|
//7
|
|
if(SmoothVertexList[i].y==SECTORSY-1)
|
|
{
|
|
fNeighborHeight[7]=pNeighborSectorVertex[6][SmoothVertexList[i].x+(1)*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[7]=pEditSectorVertex[(SmoothVertexList[i].x+0)+(SmoothVertexList[i].y+1)*SECTORSX].v.y;
|
|
}
|
|
if(SmoothVertexList[i].x==SECTORSX-1 || SmoothVertexList[i].y==SECTORSY-1)
|
|
{
|
|
if(SmoothVertexList[i].x==SECTORSX-1 && SmoothVertexList[i].y==SECTORSY-1)
|
|
{
|
|
fNeighborHeight[8]=pNeighborSectorVertex[7][1+(1)*SECTORSX].v.y;
|
|
}
|
|
else if(SmoothVertexList[i].x==SECTORSX-1)
|
|
{
|
|
fNeighborHeight[8]=pNeighborSectorVertex[4][1+(SmoothVertexList[i].y+1)*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[8]=pNeighborSectorVertex[6][SmoothVertexList[i].x+1+(1)*SECTORSX].v.y;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fNeighborHeight[8]=pEditSectorVertex[(SmoothVertexList[i].x+1)+(SmoothVertexList[i].y+1)*SECTORSX].v.y;
|
|
}
|
|
|
|
for(int cNei=0;cNei<9;cNei++)
|
|
{
|
|
fAvgHeight+=fNeighborHeight[cNei];
|
|
}
|
|
fAvgHeight+=fNeighborHeight[4];
|
|
|
|
fAvgHeight/=10.0f;
|
|
|
|
pEditSectorVertex[(SmoothVertexList[i].x+0)+(SmoothVertexList[i].y)*SECTORSX].v.y=fAvgHeight;
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
for(i=0;i<8;i++)
|
|
{
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Unlock();
|
|
}
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckSmallsmooth()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
InitSmoothBuffer();
|
|
}
|
|
|
|
void CDlgEditTerrain::OnUpdateEditStartheight()
|
|
{
|
|
// TODO: If this is a RICHEDIT control, the control will not
|
|
// send this notification unless you override the CDialog::OnInitDialog()
|
|
// function to send the EM_SETEVENTMASK message to the control
|
|
// with the ENM_UPDATE flag ORed into the lParam mask.
|
|
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
}
|
|
|
|
void CDlgEditTerrain::OnUpdateEditEndheight()
|
|
{
|
|
// TODO: If this is a RICHEDIT control, the control will not
|
|
// send this notification unless you override the CDialog::OnInitDialog()
|
|
// function to send the EM_SETEVENTMASK message to the control
|
|
// with the ENM_UPDATE flag ORed into the lParam mask.
|
|
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckMakeroad()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
}
|
|
|
|
void CDlgEditTerrain::SetMakeRoadStartVertex(vector3 vecStart,vector3 vecDir)
|
|
{
|
|
if(m_SelectSectorScene==NULL)
|
|
return;
|
|
SectorVertex *pEditSectorVertex;
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
int ix,iy;
|
|
|
|
vector3 vecTerrainPos,vecLens;
|
|
vector3 vecMousePos;
|
|
|
|
float fIntersection;
|
|
|
|
vector3 vecIntersectionPoint;
|
|
vecIntersectionPoint.x=-1.0f;
|
|
|
|
vector3 vecCollisionVertex[3];
|
|
|
|
float fLens=100000000.0f;
|
|
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY-1;iy++)
|
|
{
|
|
/*
|
|
vecTerrainPos=vector3(pEditSectorVertex[ix+iy*SECTORSX].v.x,0.0f,pEditSectorVertex[ix+iy*SECTORSX].v.z);
|
|
vecLens=vecTerrainPos-vecMousePos;
|
|
if(vecLens.GetLens()<=m_fRange)
|
|
{
|
|
m_isSelectSceneEdit=TRUE;
|
|
if(m_isAddHeight)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y+=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y>=m_fMaxHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMaxHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
else
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y-=m_fAddHeight;
|
|
if(pEditSectorVertex[ix+iy*SECTORSX].v.y<=m_fMinHeight)
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fMinHeight;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
}
|
|
*/
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+0)+(iy+0)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+100000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
}
|
|
}
|
|
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+1)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+100000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(vecIntersectionPoint.x==-1)
|
|
return;
|
|
m_vecMakeRoadStart=vecIntersectionPoint;
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
}
|
|
|
|
void CDlgEditTerrain::MakeRoad(vector3 vecStart, vector3 vecDir)
|
|
{
|
|
if(m_SelectSectorScene==NULL)
|
|
return;
|
|
SectorVertex *pEditSectorVertex;
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
int ix,iy;
|
|
|
|
vector3 vecTerrainPos,vecLens;
|
|
vector3 vecMousePos;
|
|
|
|
float fIntersection;
|
|
|
|
vector3 vecIntersectionPoint;
|
|
vecIntersectionPoint.x=-1.0f;
|
|
|
|
vector3 vecCollisionVertex[3];
|
|
float fLens=1000000000.0f;
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY-1;iy++)
|
|
{
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+0)+(iy+0)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+100000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
}
|
|
|
|
}
|
|
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+1)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+100000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
//vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(vecIntersectionPoint.x==-1)
|
|
return;
|
|
vector3 vecMakeRoadEnd=vecIntersectionPoint;
|
|
|
|
matrix matTerrainTM,matTM;
|
|
matTerrainTM=m_SelectSectorScene->m_AccumulateTM;
|
|
matTM.Translation(vecMakeRoadEnd);
|
|
matTerrainTM.Inverse(matTerrainTM);
|
|
matTM=matTM*matTerrainTM;
|
|
vecMakeRoadEnd=matTM.GetLoc();
|
|
|
|
matTM.Translation(m_vecMakeRoadStart);
|
|
matTM=matTM*matTerrainTM;
|
|
m_vecMakeRoadStart=matTM.GetLoc();
|
|
|
|
|
|
|
|
float fRoadWidth=m_fRoadWidth/2.0f;
|
|
float fRoadStartHeight=m_fStartHeight;
|
|
float fRoadEndHeight=m_fEndHeight;
|
|
float fRoadInterHeight=fRoadStartHeight-fRoadEndHeight;
|
|
|
|
vector3 vecMakeRoadRay=m_vecMakeRoadStart-vecMakeRoadEnd;
|
|
|
|
float fRoadLens=vecMakeRoadRay.GetLens();
|
|
|
|
vecMakeRoadRay.y=0.0f;
|
|
|
|
float fASide=vecMakeRoadRay.z/vecMakeRoadRay.x;
|
|
|
|
vector3 vecMakeRoadRayInverse;
|
|
vecMakeRoadRayInverse.z=-vecMakeRoadRay.x;
|
|
vecMakeRoadRayInverse.y=0.0f;
|
|
vecMakeRoadRayInverse.x=vecMakeRoadRay.z;
|
|
vecMakeRoadRayInverse.Normalize();
|
|
|
|
float fA=-1.0f/fASide;
|
|
float fStartB=m_vecMakeRoadStart.z-fA*m_vecMakeRoadStart.x;
|
|
float fEndB=vecMakeRoadEnd.z-fA*vecMakeRoadEnd.x;
|
|
|
|
vector3 vecLeftLine=m_vecMakeRoadStart+vecMakeRoadRayInverse*fRoadWidth;
|
|
vector3 vecRightLine=m_vecMakeRoadStart+vecMakeRoadRayInverse*(-fRoadWidth);
|
|
|
|
float fLeftB=vecLeftLine.z-fASide*vecLeftLine.x;
|
|
float fRightB=vecRightLine.z-fASide*vecRightLine.x;
|
|
|
|
vector3 vecVertex;
|
|
float fLineInter;
|
|
|
|
if(vecMakeRoadRay.z >= 0.0f)
|
|
{
|
|
if(vecMakeRoadRay.x >= 0.0f)
|
|
{
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSX-1;iy++)
|
|
{
|
|
if( fA*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fStartB > pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fA*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fEndB < pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fASide*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fLeftB < pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fASide*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fRightB > pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z)
|
|
{
|
|
vecVertex=pEditSectorVertex[(ix)+(iy)*SECTORSX].v;
|
|
|
|
fLineInter=fabsf(fA*vecVertex.x+(-1.0f)*vecVertex.z+fStartB)/sqrtf( fA*fA+1.0f);
|
|
|
|
pEditSectorVertex[(ix)+(iy)*SECTORSX].v.y=fRoadStartHeight+fRoadInterHeight*(1.0f-(fLineInter/fRoadLens));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSX-1;iy++)
|
|
{
|
|
if( fA*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fStartB > pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fA*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fEndB < pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fASide*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fLeftB > pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fASide*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fRightB < pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z)
|
|
{
|
|
vecVertex=pEditSectorVertex[(ix)+(iy)*SECTORSX].v;
|
|
|
|
fLineInter=fabsf(fA*vecVertex.x+(-1.0f)*vecVertex.z+fStartB)/sqrtf( fA*fA+1.0f);
|
|
|
|
pEditSectorVertex[(ix)+(iy)*SECTORSX].v.y=fRoadStartHeight+fRoadInterHeight*(1.0f-(fLineInter/fRoadLens));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(vecMakeRoadRay.x >= 0.0f)
|
|
{
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSX-1;iy++)
|
|
{
|
|
if( fA*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fStartB < pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fA*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fEndB > pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fASide*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fLeftB < pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fASide*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fRightB > pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z)
|
|
{
|
|
vecVertex=pEditSectorVertex[(ix)+(iy)*SECTORSX].v;
|
|
|
|
fLineInter=fabsf(fA*vecVertex.x+(-1.0f)*vecVertex.z+fStartB)/sqrtf( fA*fA+1.0f);
|
|
|
|
pEditSectorVertex[(ix)+(iy)*SECTORSX].v.y=fRoadStartHeight+fRoadInterHeight*(1.0f-(fLineInter/fRoadLens));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSX-1;iy++)
|
|
{
|
|
if( fA*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fStartB < pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fA*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fEndB > pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fASide*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fLeftB > pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z &&
|
|
fASide*pEditSectorVertex[(ix)+(iy)*SECTORSX].v.x+fRightB < pEditSectorVertex[(ix)+(iy)*SECTORSX].v.z)
|
|
{
|
|
vecVertex=pEditSectorVertex[(ix)+(iy)*SECTORSX].v;
|
|
|
|
fLineInter=fabsf(fA*vecVertex.x+(-1.0f)*vecVertex.z+fStartB)/sqrtf( fA*fA+1.0f);
|
|
|
|
pEditSectorVertex[(ix)+(iy)*SECTORSX].v.y=fRoadStartHeight+fRoadInterHeight*(1.0f-(fLineInter/fRoadLens));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
|
|
}
|
|
|
|
void CDlgEditTerrain::OnUpdateEditRoadwidth()
|
|
{
|
|
// TODO: If this is a RICHEDIT control, the control will not
|
|
// send this notification unless you override the CDialog::OnInitDialog()
|
|
// function to send the EM_SETEVENTMASK message to the control
|
|
// with the ENM_UPDATE flag ORed into the lParam mask.
|
|
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckMustdivide()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
}
|
|
|
|
void CDlgEditTerrain::SetMustDivideVertex(int vx, int vy)
|
|
{
|
|
//m_CurrentVariance = m_SelectSectorScene->m_VarianceLeft;
|
|
POINT ptVertex;
|
|
ptVertex.x=vx;
|
|
ptVertex.y=vy;
|
|
|
|
RecurFindVertex(m_LeftDivideList,vx,vy,
|
|
0,SECTORSY-1,
|
|
SECTORSX-1,0,
|
|
0,0,1);
|
|
//m_CurrentVariance = m_SelectSectorScene->m_VarianceRight;
|
|
|
|
RecurFindVertex(m_RightDivideList,vx,vy,
|
|
SECTORSX-1,0,
|
|
0,SECTORSY-1,
|
|
SECTORSX-1,SECTORSY-1,1);
|
|
}
|
|
|
|
void CDlgEditTerrain::RecurFindVertex(List<int> &DivideList,int vx,int vy,int leftX, int leftY, int rightX, int rightY, int apexX, int apexY,int node)
|
|
{
|
|
int centerX=(leftX+rightX)>>1;
|
|
int centerY=(leftY+rightY)>>1;
|
|
|
|
vector3 vecTest[3];
|
|
vecTest[0].x=leftX;
|
|
vecTest[0].y=leftY;
|
|
vecTest[0].z=0.0f;
|
|
|
|
vecTest[1].x=rightX;
|
|
vecTest[1].y=rightY;
|
|
vecTest[1].z=0.0f;
|
|
|
|
vecTest[2].x=apexX;
|
|
vecTest[2].y=apexY;
|
|
vecTest[2].z=0.0f;
|
|
|
|
vector3 vecStart,vecEnd;
|
|
vecEnd.x=vecStart.x=vx;
|
|
vecEnd.y=vecStart.y=vy;
|
|
vecStart.z=1000.0f;
|
|
vecEnd.z=-1000.0f;
|
|
|
|
float fIntersection;
|
|
if(CIntersection::PolygonRay(vecStart,vecEnd,vecTest,fIntersection)==0)
|
|
{
|
|
return;
|
|
}
|
|
DivideList.Add(node);
|
|
if( (abs(leftX - rightX) >= 8) ||
|
|
(abs(leftY - rightY) >= 8) )
|
|
{
|
|
RecurFindVertex(DivideList,vx,vy,apexX,apexY,leftX,leftY,centerX,centerY,node<<1);
|
|
RecurFindVertex(DivideList,vx,vy,rightX,rightY,apexX,apexY,centerX,centerY,1+(node<<1));
|
|
}
|
|
}
|
|
|
|
void CDlgEditTerrain::SelectMustDivideVertex(vector3 vecStart, vector3 vecDir)
|
|
{
|
|
if(m_SelectSectorScene==NULL)
|
|
return;
|
|
SectorVertex *pEditSectorVertex;
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
int ix,iy;
|
|
|
|
vector3 vecTerrainPos,vecLens;
|
|
vector3 vecMousePos;
|
|
|
|
float fIntersection;
|
|
|
|
vector3 vecIntersectionPoint;
|
|
vecIntersectionPoint.x=-1.0f;
|
|
|
|
vector3 vecVertexLens;
|
|
|
|
vector3 vecCollisionVertex[3];
|
|
|
|
int SelectVX,SelectVY;
|
|
float fLens=1000000000.0f;
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY-1;iy++)
|
|
{
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+0)+(iy+0)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+10000000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
SelectVX=ix;
|
|
SelectVY=iy;
|
|
}
|
|
}
|
|
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+1)*SECTORSX].v+m_SelectSectorScene->m_AccumulateTM.GetLoc();
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+10000000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
SelectVX=ix;
|
|
SelectVY=iy;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
SetMustDivideVertex(SelectVX,SelectVY);
|
|
if(m_SelectSectorScene->m_MapMustDivideVertex==NULL)
|
|
{
|
|
CSectorMustDivideVertexMap *pAddNode=new CSectorMustDivideVertexMap();
|
|
pAddNode->m_IndexX=(int)((m_SelectSectorScene->m_AccumulateTM._41+1000.0f)/SECTORSIZE);
|
|
pAddNode->m_IndexY=(int)((m_SelectSectorScene->m_AccumulateTM._43+1000.0f)/SECTORSIZE);
|
|
POINT ptVertexPos;
|
|
ptVertexPos.x=SelectVX;
|
|
ptVertexPos.y=SelectVY;
|
|
pAddNode->m_ptMustDivideVertexPosList.Add(ptVertexPos);
|
|
|
|
CMainFrame *mf=(CMainFrame*)AfxGetApp()->m_pMainWnd;
|
|
CWorldCreatorView *av=(CWorldCreatorView *)mf->GetActiveView();
|
|
av->m_SceneManager->m_MapStorage.AddMustDivideVertex(pAddNode);
|
|
//CMapStorage::AddMustDivideVertex(pAddNode);
|
|
m_SelectSectorScene->m_MapMustDivideVertex=pAddNode;
|
|
}
|
|
else
|
|
{
|
|
bool bFound=false;
|
|
for(int i=0;i<m_SelectSectorScene->m_MapMustDivideVertex->m_ptMustDivideVertexPosList.num;i++)
|
|
{
|
|
if( m_SelectSectorScene->m_MapMustDivideVertex->m_ptMustDivideVertexPosList[i].x==SelectVX &&
|
|
m_SelectSectorScene->m_MapMustDivideVertex->m_ptMustDivideVertexPosList[i].y==SelectVY)
|
|
{
|
|
bFound=true;
|
|
break;
|
|
}
|
|
}
|
|
if(bFound==false)
|
|
{
|
|
POINT ptVertex;
|
|
ptVertex.x=SelectVX;
|
|
ptVertex.y=SelectVY;
|
|
m_SelectSectorScene->m_MapMustDivideVertex->m_ptMustDivideVertexPosList.Add(ptVertex);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CDlgEditTerrain::MouseEditSmooth(vector3 vecStart, vector3 vecDir)
|
|
{
|
|
if(m_SelectSectorScene==NULL)
|
|
return;
|
|
|
|
SectorVertex *pEditSectorVertex;
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
SectorVertex *pNeighborSectorVertex[8];
|
|
|
|
int ix,iy;
|
|
|
|
vector3 vecTerrainPos,vecLens;
|
|
vector3 vecMousePos;
|
|
|
|
float fIntersection;
|
|
|
|
vector3 vecIntersectionPoint;
|
|
vecIntersectionPoint.x=-1.0f;
|
|
|
|
vector3 vecCollisionVertex[3];
|
|
|
|
matrix matTerrainTM,matTM;
|
|
matTerrainTM=m_SelectSectorScene->m_AccumulateTM;
|
|
matTM.Translation(vecStart);
|
|
matTerrainTM.Inverse(matTerrainTM);
|
|
matTM=matTM*matTerrainTM;
|
|
vecStart=matTM.GetLoc();
|
|
|
|
float fLens=100000000.0f;
|
|
|
|
for(ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY-1;iy++)
|
|
{
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+0)+(iy+0)*SECTORSX].v;
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v;
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v;
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+100000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
}
|
|
}
|
|
|
|
vecCollisionVertex[0]=pEditSectorVertex[(ix+1)+(iy+0)*SECTORSX].v;
|
|
vecCollisionVertex[1]=pEditSectorVertex[(ix+0)+(iy+1)*SECTORSX].v;
|
|
vecCollisionVertex[2]=pEditSectorVertex[(ix+1)+(iy+1)*SECTORSX].v;
|
|
|
|
if(CIntersection::PolygonRay(vecStart,vecStart+100000.0f*vecDir,vecCollisionVertex,fIntersection)==1)
|
|
{
|
|
if(fLens>fIntersection)
|
|
{
|
|
vecIntersectionPoint=vecStart+vecDir*fIntersection;
|
|
fLens=fIntersection;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(vecIntersectionPoint.x==-1)
|
|
return;
|
|
//vecIntersectionPoint.x/(L
|
|
int sx=(int)(vecIntersectionPoint.x/LINTERVAL);
|
|
int sy=(int)(vecIntersectionPoint.z/LINTERVAL);
|
|
vecIntersectionPoint.y=0.0f;
|
|
|
|
//vector3 vecTerrainPos,vecLens;
|
|
List<POINT> ptSmoothList;
|
|
POINT ptPos;
|
|
for(ix=sx-10+65;ix<sx+10+65;ix++)
|
|
{
|
|
for(iy=sy-10+65;iy<sy+10+65;iy++)
|
|
{
|
|
//SECTORSIZE=(int)((SECTORSX-1)*LINTERVAL);
|
|
//vecTerrainPos.x=LINTERVAL*ix-SECTORSIZE;
|
|
vecTerrainPos.x=LINTERVAL*ix;
|
|
vecTerrainPos.y=0.0f;
|
|
vecTerrainPos.z=LINTERVAL*iy;
|
|
//vecTerrainPos.z=LINTERVAL*iy-SECTORSIZE;
|
|
vecLens=(vecIntersectionPoint+vector3(SECTORSIZE,0.0f,SECTORSIZE))-vecTerrainPos;
|
|
if(vecLens.GetLens()<=m_fRange)
|
|
{
|
|
ptPos.x=ix;
|
|
ptPos.y=iy;
|
|
ptSmoothList.Add(ptPos);
|
|
}
|
|
}
|
|
}
|
|
float fAvgHeight;
|
|
float fNeighborHeight[9];
|
|
|
|
for(int i=0;i<ptSmoothList.num;i++)
|
|
{
|
|
fNeighborHeight[0]=m_fSmoothHeight[ptSmoothList[i].x-1+(ptSmoothList[i].y-1)*((SECTORSY*3)-2)];
|
|
fNeighborHeight[1]=m_fSmoothHeight[ptSmoothList[i].x+(ptSmoothList[i].y-1)*((SECTORSY*3)-2)];
|
|
fNeighborHeight[2]=m_fSmoothHeight[ptSmoothList[i].x+1+(ptSmoothList[i].y-1)*((SECTORSY*3)-2)];
|
|
|
|
fNeighborHeight[3]=m_fSmoothHeight[ptSmoothList[i].x-1+(ptSmoothList[i].y)*((SECTORSY*3)-2)];
|
|
fNeighborHeight[4]=m_fSmoothHeight[ptSmoothList[i].x+(ptSmoothList[i].y)*((SECTORSY*3)-2)]*2.0f;
|
|
fNeighborHeight[5]=m_fSmoothHeight[ptSmoothList[i].x+1+(ptSmoothList[i].y)*((SECTORSY*3)-2)];
|
|
|
|
fNeighborHeight[6]=m_fSmoothHeight[ptSmoothList[i].x-1+(ptSmoothList[i].y+1)*((SECTORSY*3)-2)];
|
|
fNeighborHeight[7]=m_fSmoothHeight[ptSmoothList[i].x+(ptSmoothList[i].y+1)*((SECTORSY*3)-2)];
|
|
fNeighborHeight[8]=m_fSmoothHeight[ptSmoothList[i].x+1+(ptSmoothList[i].y+1)*((SECTORSY*3)-2)];
|
|
|
|
fAvgHeight=0.0f;
|
|
|
|
for(int c=0;c<9;c++)
|
|
{
|
|
fAvgHeight+=fNeighborHeight[c];
|
|
}
|
|
fAvgHeight/=10.0f;
|
|
m_fSmoothHeight[ptSmoothList[i].x+(ptSmoothList[i].y)*((SECTORSY*3)-2)]=fAvgHeight;
|
|
}
|
|
|
|
|
|
POINT ptSectorList[8];
|
|
ptSectorList[0].x=0;
|
|
ptSectorList[0].y=0;
|
|
ptSectorList[1].x=SECTORSX-1;
|
|
ptSectorList[1].y=0;
|
|
ptSectorList[2].x=SECTORSX*2-2;
|
|
ptSectorList[2].y=0;
|
|
|
|
ptSectorList[3].x=0;
|
|
ptSectorList[3].y=SECTORSX-1;
|
|
ptSectorList[4].x=SECTORSX*2-2;
|
|
ptSectorList[4].y=SECTORSX-1;
|
|
|
|
ptSectorList[5].x=0;
|
|
ptSectorList[5].y=SECTORSX*2-2;
|
|
|
|
ptSectorList[6].x=SECTORSX-1;
|
|
ptSectorList[6].y=SECTORSX*2-2;
|
|
|
|
ptSectorList[7].x=SECTORSX*2-2;
|
|
ptSectorList[7].y=SECTORSX*2-2;
|
|
|
|
POINT ptSectorCenter;
|
|
ptSectorCenter.x=SECTORSX-1;
|
|
ptSectorCenter.y=SECTORSX-1;
|
|
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSX].v.y=m_fSmoothHeight[(ptSectorCenter.x+ix)+(ptSectorCenter.y+iy)*((SECTORSY*3)-2)];
|
|
//m_SelectSectorScene->m_SectorVertex[ix+iy*SECTORSX].v.y=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
m_SelectSectorScene->m_HeightData[ix+iy*SECTORSX] = pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
|
|
}
|
|
}
|
|
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
|
|
for(i=0;i<8;i++)
|
|
{
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Lock(0,0,(BYTE**)&pNeighborSectorVertex[i],0);
|
|
}
|
|
for(i=0;i<8;i++)
|
|
{
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
pNeighborSectorVertex[i][ix+iy*SECTORSX].v.y=m_fSmoothHeight[(ptSectorList[i].x+ix)+(ptSectorList[i].y+iy)*((SECTORSY*3)-2)];
|
|
//m_SelectNeighborScene[i]->m_SectorVertex[ix+iy*SECTORSX].v.y=pNeighborSectorVertex[i][ix+iy*SECTORSX].v.y;
|
|
m_SelectNeighborScene[i]->m_HeightData[ix+iy*SECTORSX] = m_fSmoothHeight[(ptSectorList[i].x+ix)+(ptSectorList[i].y+iy)*((SECTORSY*3)-2)];;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
for(i=0;i<8;i++)
|
|
{
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Unlock();
|
|
}
|
|
}
|
|
|
|
void CDlgEditTerrain::InitSmoothBuffer()
|
|
{
|
|
SectorVertex *pEditSectorVertex;
|
|
|
|
POINT ptSectorList[8];
|
|
ptSectorList[0].x=0;
|
|
ptSectorList[0].y=0;
|
|
ptSectorList[1].x=SECTORSX-1;
|
|
ptSectorList[1].y=0;
|
|
ptSectorList[2].x=SECTORSX*2-2;
|
|
ptSectorList[2].y=0;
|
|
|
|
ptSectorList[3].x=0;
|
|
ptSectorList[3].y=SECTORSX-1;
|
|
ptSectorList[4].x=SECTORSX*2-2;
|
|
ptSectorList[4].y=SECTORSX-1;
|
|
|
|
ptSectorList[5].x=0;
|
|
ptSectorList[5].y=SECTORSX*2-2;
|
|
|
|
ptSectorList[6].x=SECTORSX-1;
|
|
ptSectorList[6].y=SECTORSX*2-2;
|
|
|
|
ptSectorList[7].x=SECTORSX*2-2;
|
|
ptSectorList[7].y=SECTORSX*2-2;
|
|
|
|
|
|
for(int i=0;i<8;i++)
|
|
{
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
for(int ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(int iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
m_fSmoothHeight[ptSectorList[i].x+ix+(ptSectorList[i].y+iy)*((SECTORSY*3)-2)]=pEditSectorVertex[ix+iy*SECTORSX].v.y;
|
|
}
|
|
}
|
|
m_SelectNeighborScene[i]->m_pROAMVertex->Unlock();
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
POINT ptSectorCenter;
|
|
ptSectorCenter.x=SECTORSX-1;
|
|
ptSectorCenter.y=SECTORSX-1;
|
|
|
|
|
|
for(int ix=0;ix<SECTORSX-1;ix++)
|
|
{
|
|
for(int iy=0;iy<SECTORSX-1;iy++)
|
|
{
|
|
m_fSmoothHeight[ptSectorCenter.x+ix+(ptSectorCenter.y+iy)*((SECTORSY*3)-2)]=
|
|
pEditSectorVertex[ix+iy*(SECTORSX)].v.y;
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
}
|
|
|
|
void CDlgEditTerrain::ShowWalkPossible()
|
|
{
|
|
SectorVertex *pEditSectorVertex;
|
|
|
|
m_LeftDivideList.num=0;
|
|
m_RightDivideList.num=0;
|
|
|
|
m_SelectSectorScene->CalcNormal();
|
|
|
|
|
|
m_SelectSectorScene->m_pROAMVertex->Lock(0,0,(BYTE**)&pEditSectorVertex,0);
|
|
|
|
int ix,iy;
|
|
vector3 vecFlatNormal;
|
|
vector3 vecPoss;
|
|
vecPoss=vector3(1.0f,1.0f,1.0f);
|
|
vecPoss.Normalize();
|
|
for(ix=0;ix<SECTORSX;ix++)
|
|
{
|
|
for(iy=0;iy<SECTORSY;iy++)
|
|
{
|
|
//pEditSectorVertex[ix+iy*SECTORSX]=m_SelectSectorScene->m_SectorVertex[ix+iy*SECTORSX]
|
|
//pEditSectorVertex[ix+iy*SECTORSX].n=vector3(0.0f,1.0f,0.0f);
|
|
//vecFlatNormal=m_SelectSectorScene->m_SectorVertex[ix+iy*SECTORSX].n;
|
|
/*
|
|
vecFlatNormal.y=0.0f;
|
|
vecFlatNormal.Normalize();
|
|
//float fAngle=vecFlatNormal*m_SelectSectorScene->m_SectorVertex[ix+iy*SECTORSX].n;
|
|
fAngle=acosf(fAngle);
|
|
if(fAngle<3.14159f/4.0f)
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSY].n=vecPoss;
|
|
pEditSectorVertex[ix+iy*SECTORSY].spec.c=0x00ff0000;
|
|
}
|
|
else
|
|
{
|
|
pEditSectorVertex[ix+iy*SECTORSY].n=vector3(0.0f,0.0f,0.0f);
|
|
pEditSectorVertex[ix+iy*SECTORSY].spec.c=0x00000000;
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
m_SelectSectorScene->m_pROAMVertex->Unlock();
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckEditrange5()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
if(m_isRange5)
|
|
{
|
|
m_fRange=5000.0f;
|
|
m_isRange1=FALSE;
|
|
m_isRange2=FALSE;
|
|
m_isRange3=FALSE;
|
|
m_isRange4=FALSE;
|
|
m_isRange6=FALSE;
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CDlgEditTerrain::OnCheckEditrange6()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
if(m_isRange6)
|
|
{
|
|
m_fRange=10000.0f;
|
|
m_isRange1=FALSE;
|
|
m_isRange2=FALSE;
|
|
m_isRange3=FALSE;
|
|
m_isRange4=FALSE;
|
|
m_isRange5=FALSE;
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CDlgEditTerrain::OnButtonAllheightfix()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
|
|
CMainFrame *mf=(CMainFrame*)AfxGetApp()->m_pMainWnd;
|
|
CWorldCreatorView *av=(CWorldCreatorView *)mf->GetActiveView();
|
|
|
|
CMapStorage *pMapStorage=&av->m_SceneManager->m_MapStorage;
|
|
|
|
for(int i=0;i<pMapStorage->m_HeightMap.num;i++)
|
|
{
|
|
for(int j=0;j<SECTORSX*SECTORSY;j++)
|
|
{
|
|
pMapStorage->m_HeightMap[i]->m_pHeightData[j]+=m_fAllAddHeight;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void CDlgEditTerrain::OnButtonHeightfix()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
UpdateData();
|
|
|
|
CMainFrame *mf=(CMainFrame*)AfxGetApp()->m_pMainWnd;
|
|
CWorldCreatorView *av=(CWorldCreatorView *)mf->GetActiveView();
|
|
|
|
CMapStorage *pMapStorage=&av->m_SceneManager->m_MapStorage;
|
|
|
|
|
|
for(int i=0;i<pMapStorage->m_HeightMap.num;i++)
|
|
{
|
|
for(int j=0;j<SECTORSX*SECTORSY;j++)
|
|
{
|
|
pMapStorage->m_HeightMap[i]->m_pHeightData[j]=m_fAllAddHeight;
|
|
}
|
|
}
|
|
}
|