Skip to content

Instantly share code, notes, and snippets.

@8Observer8
Created November 13, 2024 19:32
Show Gist options
  • Save 8Observer8/fb209d34105f9bba403d5b77eb8b008f to your computer and use it in GitHub Desktop.
Save 8Observer8/fb209d34105f9bba403d5b77eb8b008f to your computer and use it in GitHub Desktop.
The debug drawer for Bullet Physics using the line drawer
#include "debug_drawer.h"
DebugDrawer::DebugDrawer(GLuint program, btDynamicsWorld *world,
const glm::mat4 &projViewMatrix, float thickness)
: m_world(world)
, m_thickness(thickness)
{
m_lineDrawer = new LineDrawer(program, projViewMatrix);
}
DebugDrawer::~DebugDrawer()
{
delete m_lineDrawer;
}
void DebugDrawer::setProjViewMatrix(const glm::mat4 &projViewMatrix)
{
m_lineDrawer->setProjViewMatrix(projViewMatrix);
}
void DebugDrawer::setDebugMode(int debugMode)
{
m_debugMode = debugMode;
}
int DebugDrawer::getDebugMode() const
{
return m_debugMode;
}
void DebugDrawer::drawContactPoint(const btVector3 &pointOnB, const btVector3 &normalOnB,
btScalar distance, int lifeTime, const btVector3 &color)
{
}
void DebugDrawer::drawLine(const btVector3 &from, const btVector3 &to,
const btVector3 &color)
{
m_lineDrawer->draw(
glm::vec3(from.x(), from.y(), from.z()),
glm::vec3(to.x(), to.y(), to.z()),
glm::vec3(color.x(), color.y(), color.z()), m_thickness);
}
void DebugDrawer::draw3dText(const btVector3 &location, const char *textString)
{
}
void DebugDrawer::reportErrorWarning(const char *warningString)
{
}
#ifndef DEBUG_DRAWER_H
#define DEBUG_DRAWER_H
#define GLM_FORCE_PURE
#include "glm/glm.hpp"
#include <btBulletDynamicsCommon.h>
#include "line_drawer.h"
class DebugDrawer : public btIDebugDraw
{
public:
DebugDrawer(GLuint program, btDynamicsWorld *world,
const glm::mat4 &projViewMatrix, float thickness = 0.05f);
~DebugDrawer();
void setProjViewMatrix(const glm::mat4 &projViewMatrix);
// Debug mode methods
virtual void setDebugMode(int debugMode) override;
virtual int getDebugMode() const override;
// Drawing methods
virtual void drawContactPoint(const btVector3 &pointOnB, const btVector3 &normalOnB,
btScalar distance, int lifeTime, const btVector3 &color) override;
virtual void drawLine(const btVector3 &from, const btVector3 &to,
const btVector3 &color) override;
// Unused
virtual void draw3dText(const btVector3 &location, const char *textString) override;
virtual void reportErrorWarning(const char *warningString) override;
private:
int m_debugMode = 1;
btDynamicsWorld *m_world;
LineDrawer *m_lineDrawer;
float m_thickness;
};
#endif // DEBUG_DRAWER_H
@8Observer8
Copy link
Author

8Observer8 commented Nov 13, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment