PhysicsSystem took the scene root only to build MWRender::DebugDrawer itself, which pulled osg and the renderer into mwphysics. World now builds the drawer and passes it in as a plain btIDebugDraw; the per-frame redraw goes through Bullet's own clearLines/debugDrawWorld/flushLines, and collision markers through drawContactPoint, so mwphysics no longer includes anything from mwrender and the drawer no longer needs the collision world. clearLines arrived in Bullet 2.87, so the system Bullet minimum moves from 2.86 to 2.87, and the dead Travis/AppVeyor 2.83 override goes with it.
91 lines
2.5 KiB
C++
91 lines
2.5 KiB
C++
#ifndef OPENMW_MWRENDER_BULLETDEBUGDRAW_H
|
|
#define OPENMW_MWRENDER_BULLETDEBUGDRAW_H
|
|
|
|
#include <chrono>
|
|
#include <vector>
|
|
|
|
#include <osg/Array>
|
|
#include <osg/PrimitiveSet>
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <LinearMath/btIDebugDraw.h>
|
|
|
|
namespace osg
|
|
{
|
|
class Group;
|
|
class Geometry;
|
|
}
|
|
|
|
namespace MWRender
|
|
{
|
|
|
|
class DebugDrawer : public btIDebugDraw
|
|
{
|
|
private:
|
|
struct CollisionView
|
|
{
|
|
btVector3 mOrig;
|
|
btVector3 mEnd;
|
|
std::chrono::time_point<std::chrono::steady_clock> mCreated;
|
|
CollisionView(btVector3 orig, btVector3 normal)
|
|
: mOrig(orig)
|
|
, mEnd(orig + normal * 20)
|
|
, mCreated(std::chrono::steady_clock::now())
|
|
{
|
|
}
|
|
};
|
|
std::vector<CollisionView> mCollisionViews;
|
|
osg::ref_ptr<osg::Group> mShapesRoot;
|
|
|
|
protected:
|
|
osg::ref_ptr<osg::Group> mParentNode;
|
|
osg::ref_ptr<osg::Geometry> mLinesGeometry;
|
|
osg::ref_ptr<osg::Geometry> mTrisGeometry;
|
|
osg::ref_ptr<osg::Vec3Array> mLinesVertices;
|
|
osg::ref_ptr<osg::Vec3Array> mTrisVertices;
|
|
osg::ref_ptr<osg::Vec4Array> mLinesColors;
|
|
osg::ref_ptr<osg::DrawArrays> mLinesDrawArrays;
|
|
osg::ref_ptr<osg::DrawArrays> mTrisDrawArrays;
|
|
|
|
bool mDebugOn;
|
|
|
|
void createGeometry();
|
|
void destroyGeometry();
|
|
|
|
public:
|
|
explicit DebugDrawer(osg::ref_ptr<osg::Group> parentNode);
|
|
~DebugDrawer();
|
|
|
|
void clearLines() override;
|
|
|
|
void flushLines() override;
|
|
|
|
void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override;
|
|
|
|
void drawTriangle(
|
|
const btVector3& v0, const btVector3& v1, const btVector3& v2, const btVector3& color, btScalar) override;
|
|
|
|
void showCollisions();
|
|
|
|
void drawContactPoint(const btVector3& pointOnB, const btVector3& normalOnB, btScalar /*distance*/,
|
|
int /*lifeTime*/, const btVector3& /*color*/) override
|
|
{
|
|
mCollisionViews.emplace_back(pointOnB, normalOnB);
|
|
}
|
|
void drawSphere(btScalar radius, const btTransform& transform, const btVector3& color) override;
|
|
|
|
void reportErrorWarning(const char* warningString) override;
|
|
|
|
void draw3dText(const btVector3& location, const char* textString) override {}
|
|
|
|
// 0 for off, anything else for on.
|
|
void setDebugMode(int isOn) override;
|
|
|
|
// 0 for off, anything else for on.
|
|
int getDebugMode() const override;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|