Code:
typedef float idVec3[3];
typedef float idMat3[3][3];
#pragma pack(1)
typedef struct _CSimpleCamera
{
public:
// 0x0 -- vftable
virtual float GetFov( );
virtual idVec3& Forward( idVec3& vecOut );
virtual idVec3& Right( idVec3& vecOut );
virtual idVec3& Up( idVec3& vecOut );
/* 0x04 */ char unknown4[4];
/* 0x08 */ idVec3 vecPosition;
/* 0x14 */ float matFacing[3][3];
/* 0x18 */ float Fov;
} CSimpleCamera, *PCSimpleCamera;
struct CUSTOMVERTEX
{
float x, y, z;
DWORD color;
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE)
LPDIRECT3DVERTEXBUFFER9 vb = 0;
IDirect3DIndexBuffer9* ib = 0;
#define TRIANGLE_SIZE 1.0f
void DrawCrap(IDirect3DDevice9* pDevice, float posX, float posY, float posZ)
{
CSimpleCamera *cam = GetCamera();
if (cam)
{
// Capture the current state before we mess with it
if (!stateBlock)
{
pDevice->CreateStateBlock(D3DSBT_ALL, &stateBlock);
stateBlock->Capture();
}
D3DXVECTOR3 pos(posX, posY, posZ); // location in the game world where object should appear
D3DXMATRIX world, view, proj;
D3DXVECTOR3 vEyePt( cam->vecPosition[0], cam->vecPosition[1], cam->vecPosition[2] );
D3DXVECTOR3 vLookatPt( cam->vecPosition[0]+cam->matFacing[0][0], cam->vecPosition[1]+cam->matFacing[0][1], cam->vecPosition[2]+cam->matFacing[0][2] );
D3DXVECTOR3 vUpVec( 0.0f, 0.0f, 1.0f );
D3DXMatrixLookAtRH(&view,
&vEyePt,
&vLookatPt,
&vUpVec);
D3DXMatrixPerspectiveFovRH(&proj, cam->Fov*0.6f, 1920.0f/1200.0f, 0.1f, 1000000.0f/* 0.92f */);
// needed to render at all
pDevice->SetVertexShader(NULL);
pDevice->SetPixelShader(NULL);
pDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
// Prevent Blizzard from setting the alpha of our polygons on mouseover
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
if (!vb)
{
HRESULT hr = pDevice->CreateVertexBuffer(5 * sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &vb, NULL);
CUSTOMVERTEX* pVertices;
vb->Lock( 0, 0, (void**)&pVertices, 0 );
pVertices[0].x=-TRIANGLE_SIZE;
pVertices[0].y=-TRIANGLE_SIZE;
pVertices[0].z=TRIANGLE_SIZE;
pVertices[0].color = D3DCOLOR_ARGB(255, 255, 0, 0);
pVertices[1].x=0.0f;
pVertices[1].y=0.0f;
pVertices[1].z=-TRIANGLE_SIZE;
pVertices[1].color = D3DCOLOR_ARGB(255, 0, 255, 0);
pVertices[2].x=TRIANGLE_SIZE;
pVertices[2].y=-TRIANGLE_SIZE;
pVertices[2].z=TRIANGLE_SIZE;
pVertices[2].color = D3DCOLOR_ARGB(255, 0, 0, 255);
pVertices[3].x=TRIANGLE_SIZE;
pVertices[3].y=TRIANGLE_SIZE;
pVertices[3].z=TRIANGLE_SIZE;
pVertices[3].color = D3DCOLOR_ARGB(255, 0, 255, 0);
pVertices[4].x=-TRIANGLE_SIZE;
pVertices[4].y=TRIANGLE_SIZE;
pVertices[4].z=TRIANGLE_SIZE;
pVertices[4].color = D3DCOLOR_ARGB(255, 255, 0, 0);
vb->Unlock();
hr = pDevice->CreateIndexBuffer(6*3*2, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &ib, NULL);
WORD *indices=NULL;
ib->Lock( 0, 0, (void**)&indices, 0 );
indices[0]=0;
indices[1]=1;
indices[2]=2;
indices[3]=2;
indices[4]=1;
indices[5]=3;
indices[6]=3;
indices[7]=1;
indices[8]=4;
indices[9]=4;
indices[10]=1;
indices[11]=0;
indices[12]=0;
indices[13]=2;
indices[14]=4;
indices[15]=4;
indices[16]=2;
indices[17]=3;
ib->Unlock();
}
D3DXMatrixTranslation(&world, pos.x, pos.y, pos.z);
pDevice->SetTransform(D3DTS_WORLD, &world);
pDevice->SetTransform(D3DTS_VIEW, &view);
pDevice->SetTransform(D3DTS_PROJECTION, &proj);
pDevice->SetTexture(0, NULL);
pDevice->SetStreamSource(0, vb, 0, sizeof(CUSTOMVERTEX));
pDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
pDevice->SetIndices(ib);
pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,5,0,6);
if (stateBlock)
stateBlock->Apply();
}
}
I just need to solve the "sliding solid" issue, and I'm good to go... Now if only I could get the zbuffer stuff working so I could draw primitives at the right LEVEL... but when I tried adding in the zbuffer stuff, all KINDS of weird things started happening.