📄 code_temp.txt
字号:
{
FILE *fp = fopen("z_buf.dat" , "rb");
if(fp==NULL)
{
MSG_STR("Load ZBuffer Data Error!");
return E_FAIL;
}
int w = 800;
int h = 600;
pwZBuffer = new WORD[w * h];
fread(pwZBuffer , w * h * 2 , 1 , fp);
fclose(fp);
return S_OK;
}
HRESULT SCENE::SetZBuffer()
{
if(pwZBuffer==NULL) return E_FAIL;
DDSURFACEDESC2 ddsd;
INIT_STRUCT(ddsd);
HRESULT r;
r = g_pddsZBuffer->Lock(0 , &ddsd , DDLOCK_WAIT|DDLOCK_WRITEONLY , 0);
if(r!=S_OK)
{
MessageBox(NULL , "Lock ZBuffer failed!" , "error" , 0);
return E_FAIL;
}
LPWORD pwZBufData = (LPWORD)ddsd.lpSurface;
DWORD w = ddsd.dwWidth;
DWORD h = ddsd.dwHeight;
long pitch = ddsd.lPitch / 2;
LPWORD pwTempZBuf = pwZBuffer;
for(DWORD y = 0 ; y < h ; y++)
{
memcpy((LPVOID)pwZBufData , (LPVOID)pwTempZBuf , w * 2);
pwZBufData+=pitch;
pwTempZBuf+=w;
}
g_pddsZBuffer->Unlock(0);
return S_OK;
}
/*
LPDIRECTDRAWSURFACE7 pBlockSurface = NULL;
BORDER_VERTEX *pBorderVertices = NULL;
VOID LoadTextureFromFile(TCHAR *strFileName)
{
HRESULT r;
D3DX_SURFACEFORMAT PixelFormat = D3DX_SF_R5G6B5;
DWORD w = 128 , h = 128;
r = D3DXCreateTextureFromFile(
g_pd3dDevice ,
0 ,
&w ,
&h ,
&PixelFormat ,
NULL ,
&pBlockSurface ,
0 ,
strFileName ,
D3DX_FT_POINT
);
if(r!=S_OK)
{
MSG_STR("Load block.bmp failed!");
}
MSG_NUM(w);
DDSURFACEDESC2 ddsd;
INIT_STRUCT(ddsd);
pBlockSurface->Lock(NULL , &ddsd , DDLOCK_READONLY , NULL);
w = ddsd.dwWidth;
h = ddsd.dwHeight;
DWORD pitch = (DWORD)ddsd.lPitch / 2;
LPWORD pwSurfaceData = (LPWORD)ddsd.lpSurface;
DWORD x , y;
for(y = 0 ; y < h ; y++)
{
for(x = 0 ; x < w ; x++)
{
WORD color = *(pwSurfaceData + x);
}
pwSurfaceData+=pitch;
}
pBlockSurface->Unlock(NULL);
DWORD trans_color = 0;
DDCOLORKEY color_key;
color_key.dwColorSpaceLowValue = trans_color;
color_key.dwColorSpaceHighValue = trans_color;
pBlockSurface->SetColorKey(DDCKEY_SRCBLT, &color_key);
pBorderVertices = new BORDER_VERTEX[4];
float size = scScene.m_iGridNum * scScene.m_fGridSize;
pBorderVertices[0].p = D3DXVECTOR3( 0.0f , size , 0.0f );
pBorderVertices[0].u = 0.0f;
pBorderVertices[0].v = 1.0f;
pBorderVertices[1].p = D3DXVECTOR3( 0.0f , 0.0f , 0.0f );
pBorderVertices[1].u = 0.0f;
pBorderVertices[1].v = 0.0f;
pBorderVertices[2].p = D3DXVECTOR3( size , size , 0.0f );
pBorderVertices[2].u = 1.0f;
pBorderVertices[2].v = 1.0f;
pBorderVertices[3].p = D3DXVECTOR3( size , 0.0f , 0.0f );
pBorderVertices[3].u = 1.0f;
pBorderVertices[3].v = 0.0f;
}
VOID DrawGround()
{
g_pd3dDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE );
D3DXMATRIX matWorld;
D3DXMatrixIdentity(&matWorld);
g_pd3dDevice->SetTransform( D3DTRANSFORMSTATE_WORLD , matWorld );
g_pd3dDevice->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, TRUE);
g_pd3dDevice->SetTexture(0 , pBlockSurface);
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP , D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1 ,
pBorderVertices , 4 , 0);
g_pd3dDevice->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, FALSE);
g_pd3dDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, TRUE );
}*/
/*
RECT rc1 , rc2;
DWORD w , h;
GetSurfaceSize(g_pddsRenderTarget , &w , &h);
DWORD b_w , b_h;
GetSurfaceSize(psurBack , &b_w , &b_h);
RECT rcBack;
//取得源图在世界坐标中的RECT
rcBack.left = iMapStartX;
rcBack.right = rcBack.left + b_w;
rcBack.top = iMapStartY;
rcBack.bottom = rcBack.top + b_h;
RECT rcScreen;
//取得屏幕在世界坐标中的RECT
rcScreen.left = iViewInWorldStartX;
rcScreen.right = rcScreen.left + g_iViewWidth;
rcScreen.top = iViewInWorldStartY;
rcScreen.bottom = rcScreen.top + g_iViewHeight;
//求两者的交集
RECT rcInter;
if(IntersectRect(&rcInter , &rcBack , &rcScreen))
{
//求源图与此交集的交集
IntersectRect(&rc1 , &rcInter , &rcBack);
//转化为源图坐标系
rc1.left-=rcBack.left;
rc1.right-=rcBack.left;
rc1.top-=rcBack.top;
rc1.bottom-=rcBack.top;
//求屏幕与此交集的交集
IntersectRect(&rc2 , &rcInter , &rcScreen);
//转化为屏幕坐标系
rc2.left-=rcScreen.left;
rc2.right-=rcScreen.left;
rc2.top-=rcScreen.top;
rc2.bottom-=rcScreen.top;
//MSG_NUM(rc2.bottom);
g_pddsRenderTarget->Blt(&rc2 , psurBack , &rc1 , DDBLT_WAIT , NULL);
}*/
xTiger.LoadXFile("tiger.x");
xTiger.SetScale(5.0f , 5.0f , 5.0f);
xTiger.InitPosition(20.0f , 20.0f , 7.0f , 0.0f , 90.0f , 0.0f);
RECT rcInter;
if(!IntersectRect(&rcInter , &rcObj , &rcMap)) return;
int w , h ; CoverGrid.GetGridSize(&w , &h);
int w1 , h1; CoverGrid.GetWorldGridSize(&w1 , &h1);
int iStartRectX = (rcObj.left - iMapAtWorldX) / w;
int iStartRectY = (rcObj.top - iMapAtWorldY) / h;
int iEndRectX = (rcObj.right - iMapAtWorldX) / w;
int iEndRectY = (rcObj.bottom - iMapAtWorldY) / h;
LPBYTE pbAttr = CoverGrid.GetAttrPtr();
int iRectOffsetY;
for(int y = iEndRectY ; y >= iStartRectY; y--)
{
iRectOffsetY = y * w1;
for(int x = iStartRectX ; x <= iEndRectX ; x++)
{
int iRectOffset = iRectOffsetY + x;
if(iRectOffset>=0)
{
if( *(pbAttr + iRectOffset) >= (iEndRectY - y) )
{
*(pbCoverRedraw + iRectOffset) = 1;
}
}
}
}
/*
VOID LoadAttr()
{
FILE *fp = fopen("yizhan.atr" , "rb");
if(fp==NULL)
{
return ;
}
LPDWORD pdwCoverAttr;GetMemory(pdwCoverAttr , DWORD , 900);
fread(pdwCoverAttr , 3600 , 1 , fp);
fclose(fp);
LPBYTE pbCoverAttr = g_pGameScene->gridCover.GetAttrPtr();
for(int y = 0 ; y < 36 ; y++)
{
for(int x = 0 ; x < 25 ; x++)
{
int iOffset = y * 25 + x;
*(pbCoverAttr + iOffset) = (BYTE)(*(pdwCoverAttr + iOffset) & 127);
}
}
FreeMemory(pdwCoverAttr);
}*/
if(wParam==VK_SPACE)
{
}
if(wParam==VK_F1)
{
//g_pGameScene->gridCover.SaveAttrFile("yizhan.cov");
//SaveSurface16(g_pSceneView->psurMap , "yizhan.sur");
//GetSurfaceFromSurFile16("caolu.sur");
//CreateSurfaceFromFileList();
//ProcessCoverImage("object.bmp" , 65535);
//ImageFileToRleFile("object.bmp" , "yizhan.rle" , 65535);
}
/*
if(KEY_A)
{
pSceneView->m_Camera.Move(MOVE_UP);
}
if(KEY_Z)
{
pSceneView->m_Camera.Move(MOVE_DOWN);
}
if(KEY_PLUS)
{
pSceneView->ResetGridSize(0.002f);
}
if(KEY_DEC)
{
pSceneView->ResetGridSize(-0.002f);
}
if(KEY_J)
{
//g_pScene->iMapStartX-=2;
}
if(KEY_L)
{
//g_pScene->iMapStartX+=2;
}
if(KEY_I)
{
//g_pScene->iMapStartY-=2;
}
if(KEY_K)
{
//g_pScene->iMapStartY+=2;
}
if(KEY_B)
{
//g_pScene->SetGridBlock(g_pScene->iMouseGridX , g_pScene->iMouseGridY , TRUE);
}
if(KEY_N)
{
//g_pScene->SetGridBlock(g_pScene->iMouseGridX , g_pScene->iMouseGridY , FALSE);
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -