Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 基于OpenGL的Bullet调试抽屉_C++_Visual Studio_Debugging_Opengl_Bullet - Fatal编程技术网

C++ 基于OpenGL的Bullet调试抽屉

C++ 基于OpenGL的Bullet调试抽屉,c++,visual-studio,debugging,opengl,bullet,C++,Visual Studio,Debugging,Opengl,Bullet,我一直在摆弄bullet,现在我想画debug。 我有一个opengl的世界,里面有子弹物理和所有东西 我尝试的是: 我创建了一个类,如下所示: #include "LinearMath/btIDebugDraw.h" class GLDebugDrawer : public btIDebugDraw { int m_debugMode; public: GLDebugDrawer(); virtual ~GLDebugDrawer(); virtual void

我一直在摆弄bullet,现在我想画debug。 我有一个opengl的世界,里面有子弹物理和所有东西

我尝试的是: 我创建了一个类,如下所示:

#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; }

};
debugDraw->DBG_DrawWireframe; // this breaks when I run the app
debugDraw->setDebugMode(btIDebugDraw::DBG_DrawWireframe); // so does this
debugDraw->setDebugMode(1); // this doesn't
bt_dynamicsWorld->setDebugDrawer(debugDraw);
bt_dynamicsWorld->debugDrawWorld();
GLDebugDrawer MyDrawer;
...
bt_dynamicsWorld->setDebugDrawer(&MyDrawer);
然后在游戏中,我加入这个标题并创建一个实例

在初始化bt world时,我将调试绘图类型设置为:

#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; }

};
debugDraw->DBG_DrawWireframe; // this breaks when I run the app
debugDraw->setDebugMode(btIDebugDraw::DBG_DrawWireframe); // so does this
debugDraw->setDebugMode(1); // this doesn't
bt_dynamicsWorld->setDebugDrawer(debugDraw);
bt_dynamicsWorld->debugDrawWorld();
GLDebugDrawer MyDrawer;
...
bt_dynamicsWorld->setDebugDrawer(&MyDrawer);
然后,我将调试设置为bullet世界,如下所示:

#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; }

};
debugDraw->DBG_DrawWireframe; // this breaks when I run the app
debugDraw->setDebugMode(btIDebugDraw::DBG_DrawWireframe); // so does this
debugDraw->setDebugMode(1); // this doesn't
bt_dynamicsWorld->setDebugDrawer(debugDraw);
bt_dynamicsWorld->debugDrawWorld();
GLDebugDrawer MyDrawer;
...
bt_dynamicsWorld->setDebugDrawer(&MyDrawer);
最后,我在渲染子弹体后渲染调试图,如下所示:

#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; }

};
debugDraw->DBG_DrawWireframe; // this breaks when I run the app
debugDraw->setDebugMode(btIDebugDraw::DBG_DrawWireframe); // so does this
debugDraw->setDebugMode(1); // this doesn't
bt_dynamicsWorld->setDebugDrawer(debugDraw);
bt_dynamicsWorld->debugDrawWorld();
GLDebugDrawer MyDrawer;
...
bt_dynamicsWorld->setDebugDrawer(&MyDrawer);

在运行时,我没有得到任何线框或任何东西,因此我一定缺少了一些东西。

有一组简单的代码,可以相对简单地用来修改代码,看起来您可能需要更改
bt\u dynamicsWorld->setDebugDrawer(debugDraw)
bt_dynamicsWorld->setDebugDrawer(&debugDraw)(不确定,因为我不知道框架是如何设置的。

首先,必须将实例化类的引用传递给
setDebugDrawer
函数,如下所示:

#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; }

};
debugDraw->DBG_DrawWireframe; // this breaks when I run the app
debugDraw->setDebugMode(btIDebugDraw::DBG_DrawWireframe); // so does this
debugDraw->setDebugMode(1); // this doesn't
bt_dynamicsWorld->setDebugDrawer(debugDraw);
bt_dynamicsWorld->debugDrawWorld();
GLDebugDrawer MyDrawer;
...
bt_dynamicsWorld->setDebugDrawer(&MyDrawer);

其次,同样重要的是,您必须定义
GLDebugDrawer
类中列出的虚拟函数,这样当bullet调用其中一个函数来绘制调试信息时,您的调试抽屉实际上可以在屏幕上绘制一些内容。

嘿,谢谢您的回复。我已经阅读了那篇文章,并随后阅读了,b但是我仍然没有通过任何程序。如果我通过
bt\u dynamicsWorld->setDebugDrawer(&debugDraw)
我得到了这样的信息:
无法将参数1从“GLDebugDrawer**”转换为“btIDebugDraw*”
。我知道这是一条旧消息,但在我搜索时它突然出现在顶部。您是否在GLDebugDrawer类中实现了这些方法中的任何一个?