Code:
//GameStart Function
void GameStart()
{
g_pGame->CreateRasterizer(D3D10_FILL_WIREFRAME, D3D10_CULL_NONE, true);
D3D10_INPUT_ELEMENT_DESC layout[] = {
{"Position", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"Color", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0}
};
int numElements = (sizeof(layout) / sizeof(layout[0]));
//Declare the vertices
VertexStruct vertices[NUM_VERTSX * NUM_VERTSY];
// Fill the vertices array with the terrain values
for(int z=0; z < NUM_VERTSY; ++z)
{
for(int x=0; x < NUM_VERTSX; ++x)
{
vertices[x + z * NUM_VERTSX].Pos.x = (float)x * CELL_WIDTH;
vertices[x + z * NUM_VERTSX].Pos.z = (float)z * CELL_HEIGHT;
// Allow the height of the cell to be randomly decided
vertices[x + z * NUM_VERTSX].Pos.y = 1.0f;
// Create the default color
vertices[x + z * NUM_VERTSX].Color = D3DXVECTOR4(1.0, 0.0f, 0.0f, 0.0f);
}
}
//Create the indices array, six vertices for each cell
DWORD indices[NUM_VERTSX * NUM_VERTSY * 6];
//the index counter
int curIndex = 0;
//Fill the indices array to create the triangles needed for the terrain
for (int z=0; z < NUM_ROWS; z++)
{
for (int x=0; x < NUM_COLS; x++)
{
// The current vertex to build off of
int curVertex = x + (z * NUM_VERTSX);
// Create the indices for the first triangle
indices[curIndex] = curVertex;
indices[curIndex+1] = curVertex + NUM_VERTSX;
indices[curIndex+2] = curVertex + 1;
// Create the indices for the second triangle
indices[curIndex+3] = curVertex + 1;
indices[curIndex+4] = curVertex + NUM_VERTSX;
indices[curIndex+5] = curVertex + NUM_VERTSX + 1;
// increment curIndex by the number of vertices for the two triangles
curIndex += 6;
}
}
int i = sizeof(indices) / sizeof(DWORD);
ID3DBlob* pError;
D3DX10CreateEffectFromFile(TEXT("Effect.fx"), NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, g_pGame->GetDevice(),
NULL, NULL, &g_pEffect, &pError, NULL);
LPVOID l_pError = NULL;
if(pError)
l_pError = pError->GetBufferPointer();
g_pModel = new ModelObject(g_pGame->GetDevice(), numElements, layout, i, g_pEffect->GetTechniqueByName("Render"));
//Set the indices to be put in the index buffer
D3D10_SUBRESOURCE_DATA initData;
initData.pSysMem = indices;
g_pModel->CreateIndexBuffer(initData);
initData.pSysMem = vertices;
i = sizeof(vertices) / sizeof(VertexStruct);
g_pModel->CreateVertexBuffer(initData, i);
g_pGame->CreateProjectionMatrix(g_pEffect);
g_pGame->SetCamera(D3DXVECTOR3(0.0f, 95.0f, -300.0f), D3DXVECTOR3(0.0f, 0.0f, 0.0f));
}
//CreateRasterizer function
void BimanEngine::CreateRasterizer(D3D10_FILL_MODE FillMode, D3D10_CULL_MODE CullMode, bool Antialiased)
{
//Fill out the rasterizer description
D3D10_RASTERIZER_DESC desc;
//How to draw objects
desc.FillMode = FillMode;
//What parts of the object to draw
desc.CullMode = CullMode;
desc.FrontCounterClockwise = true;
desc.DepthBias = false;
desc.DepthBiasClamp = 0;
desc.SlopeScaledDepthBias = 0;
desc.DepthClipEnable = false;
desc.ScissorEnable = false;
desc.MultisampleEnable = false;
desc.AntialiasedLineEnable = Antialiased;
//Create the rasterizer state
ID3D10RasterizerState* pRasterizer;
m_pD3DDevice->CreateRasterizerState(&desc, &pRasterizer);
//Set rasterizer state
m_pD3DDevice->RSSetState(pRasterizer);
}
//SetCamera function
void BimanEngine::SetCamera(D3DXVECTOR3 Eye, D3DXVECTOR3 At)
{
D3DXMatrixLookAtLH(&m_mxView, &Eye, &At, new D3DXVECTOR3(0.0f, 1.0f, 0.0f));
}
Thank you