I'm trying to render custom objects (so far only a simple triangle) in wow's game world, but I can't get anything to show up. I suspect it's because either my view or projection matrices are messed up, but I can't figure out how all the matrix math works. And I'm not skilled enough to reverse wow to find out how blizzard does it. All my d3d code is derived from msdn documentation and guesswork.
Here's the relevant parts of what I'm doing currently, which doesn't work. Nothing gets rendered at all.
Code:
struct CUSTOMVERTEX
{
float x, y, z;
DWORD color;
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE)
D3DXVECTOR3 pos(targetPos); // location in the game world where object should appear
D3DXMATRIX world, view, proj;
D3DXMatrixTranslation(&world, pos.x, pos.y, pos.z);
D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(cameraPos), // eye position, read from [CGWorldFrame::GetActiveCamera() + 8] (cameraPos = pointer to an array of 3 floats)
&D3DXVECTOR3(playerPos), // look-at point (should this be the player's position?) (playerPos = pointer to an array of 3 floats)
&D3DXVECTOR3(0.0f, 1.0f, 0.0f)); // up vector (should this always be 0,1,0?)
D3DXMatrixPerspectiveFovLH(&proj, fov, 1.333f, 0.1f, 1000000.0f); // fov is read from [active camera + 0x40], aspect ratio is 1024/768
pDevice->SetTransform(D3DTS_WORLD, &world);
pDevice->SetTransform(D3DTS_VIEW, &view);
pDevice->SetTransform(D3DTS_PROJECTION, &proj);
pDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
pDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
pDevice->SetStreamSource(0, vb, 0, sizeof(CUSTOMVERTEX)); // vertex buffer vb contains 3 vertices for a simple triangle
pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
Looking at the debug output from the directx debug runtime doesn't show any errors.
What am I doing wrong? I 'm not asking for any copy-and-paste code, just some pointers on what I should be doing instead.
Thanks,
Mike