Hi,
Im trying to right a function that will allow me to render out the lines used
to create a bounding box but im having a few problems with getting it to build
a box shape.
For this function ive been trying to convert an a peice of XNA code over to Direct3D
The original can be seen here:
http://www.xnawiki.com/index.php?title=Rendering_Bounding_Boxes
This is the code i have at the moment :
LPDIRECT3DVERTEXBUFFER9 m_VertexBuffer;
LPDIRECT3DINDEXBUFFER9 m_IndexBuffer;
D3DXVECTOR3* m_vertices;
int *m_indices;
void SetUp()
{
//Create the vertex buffer
m_Direct3DDevice->CreateVertexBuffer(8*sizeof(D3DXVECTOR3), D3DUSAGE_WRITEONLY, 0,
D3DPOOL_MANAGED, &m_VertexBuffer, NULL );
//Create the index buffer
m_Direct3DDevice->CreateIndexBuffer(12*3*2,D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_IndexBuffer, NULL);
m_IndexBuffer->Lock(0, 0, (void**)&m_indices, 0);
m_indices[0] = 0; m_indices[1] = 1; m_indices[2] = 1; m_indices[3] = 2;
m_indices[4] = 2; m_indices[5] = 3; m_indices[6] = 3; m_indices[7] = 0;
m_indices[8] = 0; m_indices[9] = 4; m_indices[10] = 1; m_indices[11] = 5;
m_indices[12] = 2; m_indices[13] = 6; m_indices[14] = 3; m_indices[15] = 7;
m_indices[16] = 4; m_indices[17] = 5; m_indices[18] = 5; m_indices[19] = 6;
m_indices[20] = 6; m_indices[21] = 7; m_indices[22] = 7; m_indices[23] = 4;
m_IndexBuffer->Unlock();
}
void RenderBoundingBox(CBoundingBox BoundingBox, D3DXMATRIX WorldMatrix)
{
m_Direct3DDevice->SetMaterial( &m_BoundingBoxMaterial );
m_Direct3DDevice->SetTexture(0,NULL);
m_VertexBuffer->Lock(0, 0, (void**)&m_vertices, 0);
m_vertices[0] = BoundingBox.GetCorner(0);
m_vertices[1] = BoundingBox.GetCorner(1);
m_vertices[2] = BoundingBox.GetCorner(2);
m_vertices[3] = BoundingBox.GetCorner(3);
m_vertices[4] = BoundingBox.GetCorner(4);
m_vertices[5] = BoundingBox.GetCorner(5);
m_vertices[6] = BoundingBox.GetCorner(6);
m_vertices[7] = BoundingBox.GetCorner(7);
m_VertexBuffer->Unlock();
m_Direct3DDevice->SetTransform( D3DTS_WORLD, &WorldMatrix );
m_Direct3DDevice->SetTransform(D3DTS_VIEW, &CAMERA.GetViewMatrix());
m_Direct3DDevice->SetStreamSource( 0, m_VertexBuffer,0, sizeof(D3DXVECTOR3) );
m_Direct3DDevice->SetFVF( D3DFVF_XYZ );
m_Direct3DDevice->SetIndices( m_IndexBuffer);
m_Direct3DDevice->DrawIndexedPrimitive(D3DPT_LINELIST,0,0,8,0,12);
}
Here is a Screenshot of the result that is being produced :
http://img683.imageshack.us/img683/2509/bbrenderproblem.png
Ive been going over the code for a while now and i cant work out what is going wrong, The only difference i can see from my code and the original XNA example linked above is that it uses
DrawUserIndexedPrimitives
however there is no such function in Direct3D so i am using DrawIndexedPrimitives, im not sure if there is any different with these functions but it appears that XNA has both of them.
I expect the problem is something quite simple but i cant see if right now, if anyone could help me out here it would be great.
Thanks,
Magnumwolf