This is the rendering code to render and do a pick test on the terrain
What i want todo next is increase the picked triangles vertices for mouse 1 and decrease for mouse 2 , so that i can sculpt it to how i like
I know i have to lock the vertex buffer but i am unsure how to get the positions and adjust them and when todo it
// Clear the backbuffer and depth buffer.
HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffeeeeee, 1.0f, 0));
HR(gd3dDevice->BeginScene());
// Setup the rendering FX
HR(mFX->SetMatrix(mhViewProj, &(mView*mProj)));
HR(mFX->SetTechnique(mhTech));
UINT numPasses = 0;
HR(mFX->Begin(&numPasses, 0));
HR(mFX->BeginPass(0));
HR(gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME));
HR(mTerrainMesh->DrawSubset(0));
// Switch back to solid mode.
HR(gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID));
// Did we pick anything?
D3DXVECTOR3 originW(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 dirW(0.0f, 0.0f, 0.0f);
if( gDInput->mouseButtonDown(0) )
{
getWorldPickingRay(originW, dirW);
BOOL hit = 0;
DWORD faceIndex = -1;
float u = 0.0f;
float v = 0.0f;
float dist = 0.0f;
ID3DXBuffer* allhits = 0;
DWORD numHits = 0;
HR(D3DXIntersect(mTerrainMesh, &originW, &dirW, &hit,
&faceIndex, &u, &v, &dist, &allhits, &numHits));
ReleaseCOM(allhits);
// We hit anything?
if( hit )
{
// Yes, draw the picked triangle in solid mode.
IDirect3DVertexBuffer9* vb = 0;
IDirect3DIndexBuffer9* ib = 0;
HR(mTerrainMesh->GetVertexBuffer(&vb));
HR(mTerrainMesh->GetIndexBuffer(&ib));
HR(gd3dDevice->SetIndices(ib));
HR(gd3dDevice->SetVertexDeclaration(VertexPNT::Decl));
HR(gd3dDevice->SetStreamSource(0, vb, 0, sizeof(VertexPNT)));
// faceIndex identifies the picked triangle to draw.
HR(gd3dDevice->DrawIndexedPrimitive(
D3DPT_TRIANGLELIST, 0, 0, mTerrainMesh->GetNumVertices(), faceIndex*3, 1))
ReleaseCOM(vb);
ReleaseCOM(ib);
}
}
HR(mFX->EndPass());
HR(mFX->End());
mGfxStats->display();
HR(gd3dDevice->EndScene());
// Present the backbuffer.
HR(gd3dDevice->Present(0, 0, 0, 0));