0001:
0002:
0003:
0004:
0005:
0006: #define STRICT
0007: #include <windows.h>
0008: #include <commctrl.h>
0009: #include <commdlg.h>
0010: #include <basetsd.h>
0011: #include <math.h>
0012: #include <stdio.h>
0013: #include <d3dx9.h>
0014: #include <dxerr9.h>
0015: #include <tchar.h>
0016: #include "DXUtil.h"
0017: #include "D3DEnumeration.h"
0018: #include "D3DSettings.h"
0019: #include "D3DApp.h"
0020: #include "D3DFont.h"
0021: #include "D3DFile.h"
0022: #include "D3DUtil.h"
0023: #include "resource.h"
0024: #include "main.h"
0025:
0026:
0027:
0028: #define NUM_X 32
0029: #define NUM_Y 32
0030: #define NUM_VERTICES ((NUM_Y+1)*(NUM_X+1))
0031: #define NUM_INDICES_PERFACE (3*2)
0032: #define NUM_FACES (NUM_Y*NUM_X)
0033: #define NUM_VERTICES_PERFACE 4
0034:
0035:
0036: typedef struct{
0037: float x,y,z;
0038: } FloorVertex;
0039: #define FLOOR_VERTEX (D3DFVF_XYZ)
0040:
0041:
0042:
0043:
0044:
0045: void CMyD3DApplication::InitQuad( )
0046: {
0047:
0048: m_pd3dDevice->CreateVertexBuffer( NUM_VERTICES * sizeof(FloorVertex),
0049: D3DUSAGE_WRITEONLY, FLOOR_VERTEX, D3DPOOL_MANAGED,
0050: &m_pVB, NULL );
0051:
0052: {
0053: FloorVertex *pDest;
0054: m_pVB->Lock ( 0, 0, (VOID**)&pDest, 0 );
0055: for (DWORD i = 0; i <= NUM_X; i++) {
0056: for (DWORD j = 0; j <= NUM_Y; j++) {
0057: pDest->x = ((FLOAT)i - NUM_X/2) * 2.0f / NUM_X;
0058: pDest->y =-((FLOAT)j - NUM_Y/2) * 2.0f / NUM_Y;
0059: pDest->z = 0.5f;
0060: pDest += 1;
0061: }
0062: }
0063: m_pVB->Unlock ();
0064: }
0065:
0066:
0067: WORD *pIndex;
0068: m_pd3dDevice->CreateIndexBuffer( NUM_INDICES_PERFACE * NUM_FACES * sizeof(WORD),
0069: 0 ,
0070: D3DFMT_INDEX16, D3DPOOL_DEFAULT,
0071: &m_pIB,0 );
0072: m_pIB->Lock ( 0, 0, (VOID**)&pIndex, 0 );
0073: {
0074: for (WORD i = 0; i < NUM_X; i++) {
0075: for (WORD j = 0; j < NUM_Y; j++) {
0076: *pIndex++ = j + 0 + (i+0) * (NUM_Y+1);
0077: *pIndex++ = j + 0 + (i+1) * (NUM_Y+1);
0078: *pIndex++ = j + 1 + (i+0) * (NUM_Y+1);
0079:
0080: *pIndex++ = j + 1 + (i+0) * (NUM_Y+1);
0081: *pIndex++ = j + 0 + (i+1) * (NUM_Y+1);
0082: *pIndex++ = j + 1 + (i+1) * (NUM_Y+1);
0083: }
0084: }
0085: }
0086: m_pIB->Unlock ();
0087:
0088: }
0089:
0090: void CMyD3DApplication::RenderQuad()
0091: {
0092: m_pd3dDevice->SetStreamSource(0, m_pVB, 0, sizeof(FloorVertex));
0093: m_pd3dDevice->SetIndices( m_pIB );
0094: m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, NUM_VERTICES, 0, 2*NUM_FACES );
0095: }
0096:
0097:
0098: void CMyD3DApplication::DeleteQuad( )
0099: {
0100: SAFE_RELEASE(m_pIB);
0101: SAFE_RELEASE(m_pVB);
0102: }