Translating Transformed Vertices
Hullo hullo.
I'm in a 2D jam. I've got a some Transformed vertices:
Code:
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
And I'm trying to use:
Code:
D3DXMATRIX matTrans;
Kinetics.Update();
m_pD3DDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
m_pD3DDevice->SetStreamSource(0, m_pVBuffer, sizeof(CUSTOMVERTEX));
D3DXMatrixTranslation(&matTrans, (float)Kinetics.pX, (float)Kinetics.pY, 0.0f);
m_pD3DDevice->SetTransform(D3DTS_WORLD, &matTrans);
m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
Kinetics.Update just assigns new values to pX and pY each time.
However, my fancy little box is just sitting still. Is this not a valid method to move vertices in screen space? If not, are there any suggestions on how to do it?
Thanks
Oh where oh where has my little box gone?
I've been staring at this code for about three hours now. My little box just doesn't want to come back...
Note: These are pieces of my files.
Code:
CAMERA AND PROJECTION INITIALIZATION
D3DXMATRIX matOrtho;
D3DXMATRIX matIdentity;
D3DXMatrixOrthoLH(&matOrtho, (float)GetSystemMetrics(SM_CXSCREEN), (float)GetSystemMetrics(SM_CYSCREEN), 0.0f, 1.0f);
D3DXMatrixIdentity(&matIdentity);
m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matOrtho);
m_pD3DDevice->SetTransform(D3DTS_WORLD, &matIdentity);
m_pD3DDevice->SetTransform(D3DTS_VIEW, &matIdentity);
m_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, false);
m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, false);
VERTICE INITIALIZATION
HRESULT Status;
const int NUMVERTICES = 4;
m_pD3DDevice = pD3DDevice;
if(m_pD3DDevice == NULL)
return E_FAIL;
CUSTOMVERTEX *pVertices = NULL;
Status = m_pD3DDevice->CreateVertexBuffer(NUMVERTICES * sizeof(CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&m_pVBuffer);
if(FAILED(Status))
return E_FAIL;
Status = m_pVBuffer->Lock(0, NUMVERTICES * sizeof(CUSTOMVERTEX), (BYTE**)&pVertices, 0);
if(FAILED(Status))
return E_FAIL;
pVertices[0].Colour = pVertices[1].Colour = pVertices[2].Colour = pVertices[3].Colour = D3DCOLOR_XRGB(0, 200, 0);
pVertices[0].Z = pVertices[1].Z = pVertices[2].Z = pVertices[3].Z = 0.0f;
pVertices[0].X = pVertices[3].X = -(PIXELWIDTH / 2.0f) + 50.0f;
pVertices[1].X = pVertices[2].X = (PIXELWIDTH / 2.0f) + 50.0f;
pVertices[0].Y = pVertices[1].Y = -(PIXELHEIGHT / 2.0f) + 50.0f;
pVertices[2].Y = pVertices[3].Y = (PIXELHEIGHT / 2.0f) + 50.0f;
m_pVBuffer->Unlock();
RENDERING
m_pD3DDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
m_pD3DDevice->SetStreamSource(0, m_pVBuffer, sizeof(CUSTOMVERTEX));
m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
My understanding was that with an Orthogonal Camera Setup, the centre of the screen is the origin (0, 0), and goes from -1/2 of the value to +1/2 of the value passed into the D3DXMatrixOrthoLH() Initialisation.
Note: I'm drawing a Triangle Fan (Hence the funky vertice declarations. Though I'm sure most of you would've picked up on that anyways).
Any thoughts?