1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 03:32:36 +00:00
OpenMW/apps/openmw/mwrender/bulletdebugdraw.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.6 KiB
C++
Raw Normal View History

2015-05-03 00:39:01 +02:00
#ifndef OPENMW_MWRENDER_BULLETDEBUGDRAW_H
#define OPENMW_MWRENDER_BULLETDEBUGDRAW_H
#include <chrono>
#include <vector>
2015-05-03 00:39:01 +02:00
#include <osg/Array>
#include <osg/PrimitiveSet>
#include <osg/ref_ptr>
2015-05-27 22:32:11 +02:00
#include <LinearMath/btIDebugDraw.h>
class btCollisionWorld;
2015-05-27 22:32:11 +02:00
2015-05-03 00:39:01 +02:00
namespace osg
{
class Group;
class Geometry;
}
namespace MWRender
{
class DebugDrawer : public btIDebugDraw
{
2022-09-22 21:26:05 +03:00
private:
struct CollisionView
2022-09-22 21:26:05 +03:00
{
btVector3 mOrig;
btVector3 mEnd;
std::chrono::time_point<std::chrono::steady_clock> mCreated;
CollisionView(btVector3 orig, btVector3 normal)
: mOrig(orig)
, mEnd(orig + normal * 20)
2022-10-05 23:45:17 +02:00
, mCreated(std::chrono::steady_clock::now())
{
}
};
std::vector<CollisionView> mCollisionViews;
osg::ref_ptr<osg::Group> mShapesRoot;
2015-05-03 00:39:01 +02:00
protected:
osg::ref_ptr<osg::Group> mParentNode;
btCollisionWorld* mWorld;
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;
2015-05-03 00:39:01 +02:00
bool mDebugOn;
2015-05-24 04:28:34 +02:00
void createGeometry();
void destroyGeometry();
2015-05-03 00:39:01 +02:00
public:
DebugDrawer(osg::ref_ptr<osg::Group> parentNode, btCollisionWorld* world, int debugMode = 1);
2015-05-03 00:39:01 +02:00
~DebugDrawer();
void step();
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;
2015-05-03 00:39:01 +02:00
void addCollision(const btVector3& orig, const btVector3& normal);
void showCollisions();
void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime,
2022-10-05 23:45:17 +02:00
const btVector3& color) override
{
}
void drawSphere(btScalar radius, const btTransform& transform, const btVector3& color) override;
void reportErrorWarning(const char* warningString) override;
2015-05-03 00:39:01 +02:00
void draw3dText(const btVector3& location, const char* textString) override {}
2015-05-03 00:39:01 +02:00
// 0 for off, anything else for on.
void setDebugMode(int isOn) override;
2015-05-03 00:39:01 +02:00
// 0 for off, anything else for on.
int getDebugMode() const override;
2022-09-22 21:26:05 +03:00
};
2015-05-03 00:39:01 +02:00
}
#endif