Enabling Bullet Debug Draw (Code included)
3 posters
Enabling Bullet Debug Draw (Code included)
Here is the code and information on how to enable wireframe drawing of your world / scene meshes in Bullet and in your iDevice.
Bullet needs an implementation of the btIDebugDraw interface and then you have to register the implementation and instance of the class with bullet.
You then have to tell bullet to debug draw during rendering pass...(before swapbuffers)...
Just add GLDebugDrawer.h and GLDebugDrawer.mm to your "Other Sources" section in XCode for your project and then add the following in your template.mm
Here I'm using Tutorial06_1 as an example:
then in templateLoading() after sio2PhysicPlay() call
then in templateRender() before sio2WindowLeaveLandscape3D() call
I'm pasting the code for GLDebugDrawer.h and GLDebugDrawer.mm as I don't know where to host / attach these files...if anyone knows let me know...
GLDebugDrawer.h
GLDebugDrawer.mm
The end result on the iDevice and hope it is useful for your bullet / OGL debugging purposes:
Thanks to SIO2 (ROm) for telling me Bullet has such debug draw support...
Bullet needs an implementation of the btIDebugDraw interface and then you have to register the implementation and instance of the class with bullet.
You then have to tell bullet to debug draw during rendering pass...(before swapbuffers)...
Just add GLDebugDrawer.h and GLDebugDrawer.mm to your "Other Sources" section in XCode for your project and then add the following in your template.mm
Here I'm using Tutorial06_1 as an example:
- Code:
#include "template.h"
#include "../src/sio2/sio2.h"
/*********************/
#include "GLDebugDrawer.h"
GLDebugDrawer debugDrawer;
/*********************/
then in templateLoading() after sio2PhysicPlay() call
- Code:
// Tell our physic simulation to start.
sio2PhysicPlay( sio2->_SIO2physic );
/*********************/
debugDrawer.setDebugMode(btIDebugDraw::DBG_DrawWireframe);
sio2->_SIO2physic->_btSoftRigidDynamicsWorld->setDebugDrawer(&debugDrawer);
/*********************/
then in templateRender() before sio2WindowLeaveLandscape3D() call
- Code:
// Reset back all OpenGL states required to draw properly
// the previous objects.
sio2ObjectReset();
sio2MaterialReset();
/*********************/
sio2->_SIO2physic->_btSoftRigidDynamicsWorld->debugDrawWorld();
/*********************/
}
sio2WindowLeaveLandscape3D();
I'm pasting the code for GLDebugDrawer.h and GLDebugDrawer.mm as I don't know where to host / attach these files...if anyone knows let me know...
GLDebugDrawer.h
- Code:
#ifndef GL_DEBUG_DRAWER_H
#define GL_DEBUG_DRAWER_H
#include "../src/bullet/btIDebugDraw.h"
extern "C"
{
#include <OpenGLES/EAGL.h>
#include <OpenGLES/ES1/gl.h>
#include <OpenGLES/ES1/glext.h>
}
class GLDebugDrawer : public btIDebugDraw
{
int m_debugMode;
public:
GLDebugDrawer();
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color);
virtual void reportErrorWarning(const char* warningString);
virtual void draw3dText(const btVector3& location,const char* textString);
virtual void setDebugMode(int debugMode);
virtual int getDebugMode() const { return m_debugMode;}
};
#endif
GLDebugDrawer.mm
- Code:
#include "GLDebugDrawer.h"
#include <stdio.h> //printf debugging
GLDebugDrawer::GLDebugDrawer()
:m_debugMode(0)
{
}
void GLDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
// if (m_debugMode > 0)
{
float tmp[ 6 ] = { from.getX(), from.getY(), from.getZ(),
to.getX(), to.getY(), to.getZ() };
glPushMatrix();
{
glColor4f(color.getX(), color.getY(), color.getZ(), 1.0f);
glVertexPointer( 3,
GL_FLOAT,
0,
&tmp );
glPointSize( 5.0f );
glDrawArrays( GL_POINTS, 0, 2 );
glDrawArrays( GL_LINES, 0, 2 );
}
glPopMatrix();
}
}
void GLDebugDrawer::setDebugMode(int debugMode)
{
m_debugMode = debugMode;
}
void GLDebugDrawer::draw3dText(const btVector3& location,const char* textString)
{
//glRasterPos3f(location.x(), location.y(), location.z());
//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),textString);
}
void GLDebugDrawer::reportErrorWarning(const char* warningString)
{
printf(warningString);
}
void GLDebugDrawer::drawContactPoint(const btVector3& pointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
{
{
//btVector3 to=pointOnB+normalOnB*distance;
//const btVector3&from = pointOnB;
//glColor4f(color.getX(), color.getY(), color.getZ(), 1.0f);
//GLDebugDrawer::drawLine(from, to, color);
//glRasterPos3f(from.x(), from.y(), from.z());
//char buf[12];
//sprintf(buf," %d",lifeTime);
//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
}
}
The end result on the iDevice and hope it is useful for your bullet / OGL debugging purposes:
Thanks to SIO2 (ROm) for telling me Bullet has such debug draw support...
Francescu- Posts : 136
Join date : 2009-03-18
Re: Enabling Bullet Debug Draw (Code included)
tks for sharing really helpful for alot of people Im sure!
Re: Enabling Bullet Debug Draw (Code included)
This is very useful, Francescu - thanks for taking the time to create this example.
Would it be worth adding this to the Wiki?
Would it be worth adding this to the Wiki?
ColorDelta- Posts : 16
Join date : 2009-03-25
Location : London, UK
Re: Enabling Bullet Debug Draw (Code included)
Well do you guys want to have this feature included In the next version? I can always hook it up with sio2physic...
Re: Enabling Bullet Debug Draw (Code included)
It would be great to add this to the WIKI - if someone wants to do it, fine - otherwise I'll do it as soon as I have some cycles...
2 other methods need to be implemented - I did comment out the code where some OpenGL calls were not available in GL ES...
For instance, being able to draw the collisions' contact points would be great - method to be implemented is GLDebugDrawer::drawContactPoint()
One just needs to implement 3D text drawing as these calls/libraries below:
are not supported in GL ES...
Cheers
2 other methods need to be implemented - I did comment out the code where some OpenGL calls were not available in GL ES...
For instance, being able to draw the collisions' contact points would be great - method to be implemented is GLDebugDrawer::drawContactPoint()
One just needs to implement 3D text drawing as these calls/libraries below:
- Code:
//glRasterPos3f(location.x(), location.y(), location.z());
//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),textString);
are not supported in GL ES...
Cheers
Francescu- Posts : 136
Join date : 2009-03-18
Similar topics
» Bullet for 2D
» SIO2 Architecture and Bullet Physics integration
» How use SIO2widget draw HP Bar?
» How to draw pictures of some of the region?
» 3d scene draw a 2d image.
» SIO2 Architecture and Bullet Physics integration
» How use SIO2widget draw HP Bar?
» How to draw pictures of some of the region?
» 3d scene draw a 2d image.
Permissions in this forum:
You cannot reply to topics in this forum