Created
November 13, 2024 19:32
-
-
Save 8Observer8/fb209d34105f9bba403d5b77eb8b008f to your computer and use it in GitHub Desktop.
The debug drawer for Bullet Physics using the line drawer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line drawer: https://gist.github.com/8Observer8/96f061b23f4b874e91e2c0a4042f127e