Ground 생성자 와 Render 함수
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Ground::Ground( int _row, int _col, float _size )
{
    m_iCol = _col;
    m_iRow = _row;
 
    m_dwVertices = (m_iCol+1* (m_iRow+1);
    m_dwIndices = m_iCol * m_iRow * 6;
 
    GROUNDVERTEX* pGroundVertex = new GROUNDVERTEX[m_dwVertices];
 
    int Index = 0;
    Vector3 pos(-1.* m_iCol * _size * 0.5f, 0, m_iRow * _size * 0.5f);
    for(int z = 0; z <= m_iRow; z++)
    {
        for (int x = 0; x <= m_iCol; x++)
        {
            pGroundVertex[Index].Position.x = pos.x + (_size * x);
            pGroundVertex[Index].Position.z = pos.z + -1.* (_size * z);
            pGroundVertex[Index].Diffuse = D3DCOLOR_ARGB(255505050);
            Index++;
        }
    }
 
    m_pDevice->CreateVertexBuffer(sizeof(GROUNDVERTEX)*m_dwVertices, 0, D3DFVF_GROUNDVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL);
 
    void* pVertices;
    m_pVB->Lock(00, &pVertices, NULL);
    memcpy(pVertices, pGroundVertex, sizeof(GROUNDVERTEX)*m_dwVertices);
    m_pVB->Unlock();
 
    WORD* pIndex = new WORD[m_dwIndices];
    Index = 0;
 
    for(int z = 0; z < m_iRow; z++)
    {
        for(int x = 0; x < m_iCol; x++)
        {
            pIndex[Index++= WORD(z * (m_iCol + 1+ x);
            pIndex[Index++= WORD((z +1* (m_iCol + 1+ x + 1);
            pIndex[Index++= WORD((z +1* (m_iCol + 1+ x);
 
            pIndex[Index++= WORD(z * (m_iCol + 1+ x);
            pIndex[Index++= WORD(z * (m_iCol + 1+ x + 1);
            pIndex[Index++= WORD((z +1* (m_iCol + 1+ x + 1);
        }
    }
 
    m_pDevice->CreateIndexBuffer(sizeof(WORD)*m_dwIndices, 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_pIB, NULL);
 
    void* pIndeices;
    m_pIB->Lock(00, &pIndeices, NULL);
    memcpy(pIndeices, pIndex, sizeof(WORD)*m_dwIndices);
    m_pIB->Unlock();
 
    delete[] pGroundVertex;
    delete[] pIndex;
}
cs


결과 화면

아직 버텍스 버퍼와 인덱스 버퍼가 익숙치 않다.

익숙해지려면 좀 더 많이 만들어 봐야겠다.

알록 달록 하구먼 ㅋㅋㅋ

반응형