2022-08-30 20:45:04 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_DEBUG_DEBUGDRAW_H
|
2022-08-28 14:26:11 +00:00
|
|
|
#define OPENMW_COMPONENTS_DEBUG_DEBUGDRAW_H
|
|
|
|
|
2022-08-30 20:45:04 +00:00
|
|
|
#include <osg/Drawable>
|
|
|
|
#include <osg/Vec3>
|
2022-08-26 16:31:01 +00:00
|
|
|
#include <osg/ref_ptr>
|
2022-09-11 17:55:53 +00:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
2022-08-26 16:31:01 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Group;
|
|
|
|
class Geometry;
|
2022-08-30 20:45:04 +00:00
|
|
|
class Geometry;
|
|
|
|
class RenderInfo;
|
2022-08-26 16:31:01 +00:00
|
|
|
}
|
2022-08-28 14:26:11 +00:00
|
|
|
namespace Shader
|
|
|
|
{
|
|
|
|
class ShaderManager;
|
|
|
|
}
|
2022-08-26 16:31:01 +00:00
|
|
|
|
2022-09-02 11:40:41 +00:00
|
|
|
namespace Debug
|
2022-08-26 16:31:01 +00:00
|
|
|
{
|
|
|
|
static const osg::Vec3f colorWhite = osg::Vec3(1., 1., 1.);
|
|
|
|
static const osg::Vec3f colorRed = osg::Vec3(1., 0., 0.);
|
|
|
|
static const osg::Vec3f colorBlue = osg::Vec3(0., 0., 1.);
|
|
|
|
static const osg::Vec3f colorGreen = osg::Vec3(0., 1., 0.);
|
2022-09-02 11:40:41 +00:00
|
|
|
static const osg::Vec3f colorMagenta = osg::Vec3(1., 0., 1.);
|
|
|
|
static const osg::Vec3f colorYellow = osg::Vec3(1., 1., 0.);
|
|
|
|
static const osg::Vec3f colorCyan = osg::Vec3(0., 1., 1.);
|
2022-08-26 16:31:01 +00:00
|
|
|
static const osg::Vec3f colorBlack = osg::Vec3(0., 0., 0.);
|
2022-08-30 20:45:04 +00:00
|
|
|
static const osg::Vec3f colorDarkGrey = osg::Vec3(0.25, 0.25, 0.25);
|
|
|
|
|
|
|
|
class DebugDrawCallback;
|
2022-08-26 16:31:01 +00:00
|
|
|
|
2022-08-27 14:14:03 +00:00
|
|
|
enum class DrawShape
|
|
|
|
{
|
|
|
|
Cube,
|
|
|
|
Cylinder,
|
|
|
|
WireCube,
|
|
|
|
};
|
2022-08-26 16:31:01 +00:00
|
|
|
|
2022-08-27 14:14:03 +00:00
|
|
|
struct DrawCall
|
2022-08-26 16:31:01 +00:00
|
|
|
{
|
2022-08-27 14:14:03 +00:00
|
|
|
osg::Vec3f mPosition;
|
2022-08-26 16:31:01 +00:00
|
|
|
osg::Vec3f mDims;
|
|
|
|
osg::Vec3f mColor;
|
|
|
|
|
2022-08-27 14:14:03 +00:00
|
|
|
DrawShape mDrawShape;
|
|
|
|
|
2022-08-30 20:45:04 +00:00
|
|
|
static DrawCall cube(osg::Vec3f pos, osg::Vec3 dims = osg::Vec3(50., 50., 50.), osg::Vec3 color = colorWhite)
|
|
|
|
{
|
|
|
|
return { pos, dims, color, DrawShape::Cube };
|
|
|
|
}
|
|
|
|
static DrawCall wireCube(
|
|
|
|
osg::Vec3f pos, osg::Vec3 dims = osg::Vec3(50., 50., 50.), osg::Vec3 color = colorWhite)
|
|
|
|
{
|
|
|
|
return { pos, dims, color, DrawShape::WireCube };
|
|
|
|
}
|
|
|
|
static DrawCall cylinder(
|
|
|
|
osg::Vec3f pos, osg::Vec3 dims = osg::Vec3(50., 50., 50.), osg::Vec3 color = colorWhite)
|
|
|
|
{
|
|
|
|
return { pos, dims, color, DrawShape::Cylinder };
|
|
|
|
}
|
2022-08-26 16:31:01 +00:00
|
|
|
};
|
|
|
|
|
2022-08-28 14:26:11 +00:00
|
|
|
class DebugCustomDraw : public osg::Drawable
|
2022-08-26 16:31:01 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-09-13 16:20:32 +00:00
|
|
|
DebugCustomDraw();
|
2024-02-07 04:06:24 +00:00
|
|
|
DebugCustomDraw(const DebugCustomDraw& copy, const osg::CopyOp& copyop);
|
|
|
|
|
2024-02-09 22:25:15 +00:00
|
|
|
META_Node(Debug, DebugCustomDraw)
|
2022-08-26 16:31:01 +00:00
|
|
|
|
2022-09-13 16:20:32 +00:00
|
|
|
mutable std::vector<DrawCall> mShapesToDraw;
|
2022-09-12 17:13:02 +00:00
|
|
|
osg::ref_ptr<osg::Geometry> mLinesToDraw;
|
2022-08-26 16:31:01 +00:00
|
|
|
|
2022-08-30 20:45:04 +00:00
|
|
|
osg::ref_ptr<osg::Geometry> mCubeGeometry;
|
|
|
|
osg::ref_ptr<osg::Geometry> mCylinderGeometry;
|
|
|
|
osg::ref_ptr<osg::Geometry> mWireCubeGeometry;
|
2022-08-26 16:31:01 +00:00
|
|
|
|
2022-09-14 11:20:35 +00:00
|
|
|
virtual void drawImplementation(osg::RenderInfo&) const override;
|
2022-08-26 16:31:01 +00:00
|
|
|
};
|
|
|
|
|
2024-02-09 18:51:58 +00:00
|
|
|
struct DebugDrawer : public osg::Node
|
2022-08-26 16:31:01 +00:00
|
|
|
{
|
2024-02-07 04:06:24 +00:00
|
|
|
DebugDrawer() = default;
|
|
|
|
DebugDrawer(const DebugDrawer& copy, const osg::CopyOp& copyop);
|
|
|
|
DebugDrawer(Shader::ShaderManager& shaderManager);
|
|
|
|
|
2024-02-09 18:51:58 +00:00
|
|
|
META_Node(Debug, DebugDrawer)
|
2022-08-30 20:45:04 +00:00
|
|
|
|
2024-02-09 18:51:58 +00:00
|
|
|
void traverse(osg::NodeVisitor& nv) override;
|
2022-08-26 16:31:01 +00:00
|
|
|
|
2022-08-30 20:45:04 +00:00
|
|
|
void drawCube(
|
|
|
|
osg::Vec3f mPosition, osg::Vec3f mDims = osg::Vec3(50., 50., 50.), osg::Vec3f mColor = colorWhite);
|
2022-08-28 12:52:21 +00:00
|
|
|
void drawCubeMinMax(osg::Vec3f min, osg::Vec3f max, osg::Vec3f mColor = colorWhite);
|
2022-08-27 14:14:03 +00:00
|
|
|
void addDrawCall(const DrawCall& draw);
|
2022-08-28 12:52:21 +00:00
|
|
|
void addLine(const osg::Vec3& start, const osg::Vec3& end, const osg::Vec3 color = colorWhite);
|
2022-08-26 16:31:01 +00:00
|
|
|
|
2022-08-30 20:45:04 +00:00
|
|
|
private:
|
2024-02-23 13:01:59 +00:00
|
|
|
unsigned int mCurrentFrame = 0;
|
2022-08-26 16:31:01 +00:00
|
|
|
|
2022-08-30 20:45:04 +00:00
|
|
|
std::array<osg::ref_ptr<DebugCustomDraw>, 2> mCustomDebugDrawer;
|
2022-08-26 16:31:01 +00:00
|
|
|
};
|
|
|
|
}
|
2022-08-30 20:45:04 +00:00
|
|
|
#endif // !
|