我已经摆弄了一段时间的子弹,现在我想画调试。我有一个opengl世界,里面有子弹物理和所有的东西。
我尝试的是:我已经创建了一个类GLDebugDrawer,如下所示:
#include "LinearMath/btIDebugDraw.h"
class GLDebugDrawer : public btIDebugDraw
{
int m_debugMode;
public:
GLDebugDrawer();
virtual ~GLDebugDrawer();
virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& fromColor, const btVector3& toColor);
virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color);
virtual void drawSphere(const btVector3& p, btScalar radius, const btVector3& color);
virtual void drawTriangle(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& color, btScalar alpha);
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; }
};然后在游戏中,我包含这个头文件,并创建它的一个实例。
在初始化bt世界的地方,我像这样设置debug绘图类型:
debugDraw->DBG_DrawWireframe; // this breaks when I run the app
debugDraw->setDebugMode(btIDebugDraw::DBG_DrawWireframe); // so does this
debugDraw->setDebugMode(1); // this doesn't然后,我将调试设置为bullet world,如下所示:
bt_dynamicsWorld->setDebugDrawer(debugDraw);最后,在我像这样渲染子弹体之后,我渲染了调试绘图:
bt_dynamicsWorld->debugDrawWorld();一定有什么东西我遗漏了,因为我在运行时没有得到任何线框或任何东西。
发布于 2013-11-14 23:07:41
在http://sio2interactive.forumotion.net/t599-enabling-bullet-debug-draw-code-included上有一组简单的代码,用来修改代码应该相对简单,看起来你可能需要将bt_dynamicsWorld->setDebugDrawer(debugDraw);改为bt_dynamicsWorld->setDebugDrawer(&debugDraw); (虽然不确定,因为不知道你是如何设置框架的。
发布于 2019-11-27 20:24:02
首先,您必须将实例化的类的引用传递给setDebugDrawer函数,如下所示:
GLDebugDrawer MyDrawer;
...
bt_dynamicsWorld->setDebugDrawer(&MyDrawer);其次,同样重要的是,您必须定义在GLDebugDrawer类中布局的虚拟函数,以便当bullet调用其中一个函数来绘制调试信息时,您的调试抽屉可以在屏幕上实际绘制一些内容。
https://stackoverflow.com/questions/19976935
复制相似问题