I have created a vertex buffer which holds the vertices for a circle at (0, 0) with radius 2.5.
I want to draw this circle wherever the mouse is so I captured WM_MOUSEMOVE
and I store the mouse's position in a point P. I've already setup by world, view, and projection upon creation of my Window (my look at is fine).
Upon window creation I did:
D3DXMATRIX World, View, Projection;
D3DXVECTOR3 Camera = {0.0f, 0.0f, 10.0f};
D3DXVECTOR3 LookAt = {0.0f, 0.0f, 0.0f};
D3DXVECTOR3 UpVector = {0.0f, 1.0f, 0.0f};
D3DXMatrixIdentity(&World);
D3DXMatrixLookAtLH(&View, &Camera, &LookAt, &UpVector);
D3DXMatrixPerspectiveFovLH(&Projection, D3DXToRadian(45), static_cast<float>(WindowWidth) / static_cast<float>(WindowHeight), 1.0f, 100.0f);
d3ddevice->SetTransform(D3DTS_WORLD, &World);
d3ddevice->SetTransform(D3DTS_VIEW, &View);
d3ddevice->SetTransform(D3DTS_PROJECTION, &Projection);
To draw the vertex buffer I do:
void DrawFilledCircle(float mx, float my, float r, D3DCOLOR colour)
{
if (!vertexbuffer)
{
CreateVertexBuffer_FilledCircle(mx, my, r, colour, 10); //perfectly fine.
}
d3ddevice->SetFVF(VERTEX_FVF_TEX);
d3ddevice->SetStreamSource(0, vertexbuffer, 0, sizeof(D3DVertex));
d3ddevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 10 - 2);
}
void RenderD3D()
{
d3ddevice->Clear(0, nullptr, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0, 40, 100, 255), 1.0f, 0);
d3ddevice->BeginScene();
D3DXMATRIX World;
D3DXMatrixIdentity(&World);
D3DXMatrixTranslation(&World, P.x, P.y, 0);
d3ddevice->SetTransform(D3DTS_WORLD, &World);
DrawFilledCircle(P.x, P.y, 2.5, D3DCOLOR_RGBA(0xFF, 0x00, 0x00, 0xFF));
d3ddevice->EndScene();
d3ddevice->Present(nullptr, nullptr, nullptr, nullptr);
}
However, the transformations aren't happening. My circle is drawing fine but it is still drawn at (0, 0)
.
Any ideas why my transformations aren't being applied?