Has anyone implemented the drawLine function in btIDebugDraw using directx9.
I see how convenient it is using OpenGL but in directx it seems that I would have to constantly lock and unlock vertex buffers and indices. I may be wrong but it seems that the drawLine function would be called several times which means the vertex and indices buffer must be dynamic. Also at the end of rendering, I'd have to zero the buffers out. Am I on the right track?
Any help will be appreciated
Thanks
Implement btIDebugDraw using directx9
-
- Posts: 3
- Joined: Mon Jul 14, 2008 3:40 pm
Re: Implement btIDebugDraw using directx9
I do the following for directx line drawing:
struct CUSTOMVERTEX_VC
{
FLOAT x, y, z; //Position
DWORD color; //Colour
};
#define D3DFVF_CUSTOMVERTEX_VC (D3DFVF_XYZ|D3DFVF_DIFFUSE)
//Globals
const int numLinesVertsMax = 1024;
CUSTOMVERTEX_VC gLines[numLinesVertsMax];
int numLinesVerts = 0;
int numLines = 0;
void drawLineBuffers()
{
D3DXMATRIXA16 matWorld;
D3DXMatrixIdentity( &matWorld );
m_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld );
m_pD3DDevice->SetVertexShader( NULL );
m_pD3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX_VC );
if( numLines>0 )
m_pD3DDevice->DrawPrimitiveUP( D3DPT_LINELIST, numLines, gLines, sizeof(CUSTOMVERTEX_VC) );
numLinesVerts=0;
numLines=0;
}
void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
//Too many verts for temp buffer
if( numLinesVerts>=numLinesVertsMax )
{
//Flush the buffer and continue
drawLineBuffers();
}
int colour = 0xff000000 | ((int)color[0]<<16) | ((int)color[1]<<8) | ((int)color[2]);
gLines[numLinesVerts].x = from[0];
gLines[numLinesVerts].y = from[1];
gLines[numLinesVerts].z = from[2];
gLines[numLinesVerts++].color = colour;
gLines[numLinesVerts].x = to[0];
gLines[numLinesVerts].y = to[1];
gLines[numLinesVerts].z = to[2];
gLines[numLinesVerts++].color = colour;
numLines++;
}
I call drawLineBuffers() at the end of my render loop to draw the lines I have buffered up, it will also draw the lines part way through if my buffer gets full.
Hope this helps
-flyingHaggis
struct CUSTOMVERTEX_VC
{
FLOAT x, y, z; //Position
DWORD color; //Colour
};
#define D3DFVF_CUSTOMVERTEX_VC (D3DFVF_XYZ|D3DFVF_DIFFUSE)
//Globals
const int numLinesVertsMax = 1024;
CUSTOMVERTEX_VC gLines[numLinesVertsMax];
int numLinesVerts = 0;
int numLines = 0;
void drawLineBuffers()
{
D3DXMATRIXA16 matWorld;
D3DXMatrixIdentity( &matWorld );
m_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld );
m_pD3DDevice->SetVertexShader( NULL );
m_pD3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX_VC );
if( numLines>0 )
m_pD3DDevice->DrawPrimitiveUP( D3DPT_LINELIST, numLines, gLines, sizeof(CUSTOMVERTEX_VC) );
numLinesVerts=0;
numLines=0;
}
void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
//Too many verts for temp buffer
if( numLinesVerts>=numLinesVertsMax )
{
//Flush the buffer and continue
drawLineBuffers();
}
int colour = 0xff000000 | ((int)color[0]<<16) | ((int)color[1]<<8) | ((int)color[2]);
gLines[numLinesVerts].x = from[0];
gLines[numLinesVerts].y = from[1];
gLines[numLinesVerts].z = from[2];
gLines[numLinesVerts++].color = colour;
gLines[numLinesVerts].x = to[0];
gLines[numLinesVerts].y = to[1];
gLines[numLinesVerts].z = to[2];
gLines[numLinesVerts++].color = colour;
numLines++;
}
I call drawLineBuffers() at the end of my render loop to draw the lines I have buffered up, it will also draw the lines part way through if my buffer gets full.
Hope this helps
-flyingHaggis
-
- Posts: 2
- Joined: Tue Apr 21, 2009 12:50 pm
Re: Implement btIDebugDraw using directx9
Thanks flyingHaggis
That was exactly what I needed and more.
BTW how did you handle the opengl call glRasterPos3f(from.x(), from.y(), from.z()) in the drawContactPoint function.
Did you implement Billboarding to project 2d text into 3d space?
That was exactly what I needed and more.
BTW how did you handle the opengl call glRasterPos3f(from.x(), from.y(), from.z()) in the drawContactPoint function.
Did you implement Billboarding to project 2d text into 3d space?