Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
DebugRenderer Class Referenceabstract

#include <DebugRenderer.h>

Inheritance diagram for DebugRenderer:
NonCopyable DebugRendererRecorder DebugRendererSimple

Classes

class  Geometry
 A geometry primitive containing triangle batches for various lods. More...
 
class  LOD
 A single level of detail. More...
 
class  Triangle
 A single triangle. More...
 
class  Vertex
 Vertex format used by the triangle renderer. More...
 

Public Types

enum class  ECastShadow { On , Off }
 Enum that determines if a shadow should be cast or not. More...
 
enum class  EDrawMode { Solid , Wireframe }
 Determines how triangles are drawn. More...
 
enum class  ECullMode { CullBackFace , CullFrontFace , Off }
 Determines which polygons are culled. More...
 
using Batch = Ref< RefTargetVirtual >
 Handle for a batch of triangles.
 
using GeometryRef = Ref< Geometry >
 Handle for a lodded triangle batch.
 
using SupportFunction = function< Vec3(Vec3Arg inDirection)>
 Create a primitive for a convex shape using its support function.
 

Public Member Functions

JPH_OVERRIDE_NEW_DELETE DebugRenderer ()
 Constructor.
 
virtual ~DebugRenderer ()
 
void NextFrame ()
 Call once after frame is complete. Releases unused dynamically generated geometry assets.
 
virtual void DrawLine (RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor)=0
 Draw line.
 
void DrawWireBox (const AABox &inBox, ColorArg inColor)
 Draw wireframe box.
 
void DrawWireBox (const OrientedBox &inBox, ColorArg inColor)
 
void DrawWireBox (RMat44Arg inMatrix, const AABox &inBox, ColorArg inColor)
 
void DrawMarker (RVec3Arg inPosition, ColorArg inColor, float inSize)
 Draw a marker on a position.
 
void DrawArrow (RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor, float inSize)
 Draw an arrow.
 
void DrawCoordinateSystem (RMat44Arg inTransform, float inSize=1.0f)
 Draw coordinate system (3 arrows, x = red, y = green, z = blue)
 
void DrawPlane (RVec3Arg inPoint, Vec3Arg inNormal, ColorArg inColor, float inSize)
 Draw a plane through inPoint with normal inNormal.
 
void DrawWireTriangle (RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor)
 Draw wireframe triangle.
 
template<class VERTEX_ARRAY >
void DrawWirePolygon (RMat44Arg inTransform, const VERTEX_ARRAY &inVertices, ColorArg inColor, float inArrowSize=0.0f)
 Draw a wireframe polygon.
 
void DrawWireSphere (RVec3Arg inCenter, float inRadius, ColorArg inColor, int inLevel=3)
 Draw wireframe sphere.
 
void DrawWireUnitSphere (RMat44Arg inMatrix, ColorArg inColor, int inLevel=3)
 
virtual void DrawTriangle (RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::Off)=0
 Draw a single back face culled triangle.
 
void DrawBox (const AABox &inBox, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 Draw a box.
 
void DrawBox (RMat44Arg inMatrix, const AABox &inBox, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 
void DrawSphere (RVec3Arg inCenter, float inRadius, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 Draw a sphere.
 
void DrawUnitSphere (RMat44Arg inMatrix, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 
void DrawCapsule (RMat44Arg inMatrix, float inHalfHeightOfCylinder, float inRadius, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 
void DrawCylinder (RMat44Arg inMatrix, float inHalfHeight, float inRadius, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 
void DrawOpenCone (RVec3Arg inTop, Vec3Arg inAxis, Vec3Arg inPerpendicular, float inHalfAngle, float inLength, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 
void DrawSwingConeLimits (RMat44Arg inMatrix, float inSwingYHalfAngle, float inSwingZHalfAngle, float inEdgeLength, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 
void DrawSwingPyramidLimits (RMat44Arg inMatrix, float inMinSwingYAngle, float inMaxSwingYAngle, float inMinSwingZAngle, float inMaxSwingZAngle, float inEdgeLength, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 
void DrawPie (RVec3Arg inCenter, float inRadius, Vec3Arg inNormal, Vec3Arg inAxis, float inMinAngle, float inMaxAngle, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 
virtual Batch CreateTriangleBatch (const Triangle *inTriangles, int inTriangleCount)=0
 Create a batch of triangles that can be drawn efficiently.
 
virtual Batch CreateTriangleBatch (const Vertex *inVertices, int inVertexCount, const uint32 *inIndices, int inIndexCount)=0
 
Batch CreateTriangleBatch (const Array< Triangle > &inTriangles)
 
Batch CreateTriangleBatch (const Array< Vertex > &inVertices, const Array< uint32 > &inIndices)
 
Batch CreateTriangleBatch (const VertexList &inVertices, const IndexedTriangleNoMaterialList &inTriangles)
 
Batch CreateTriangleBatchForConvex (SupportFunction inGetSupport, int inLevel, AABox *outBounds=nullptr)
 
GeometryRef CreateTriangleGeometryForConvex (SupportFunction inGetSupport)
 
virtual void DrawGeometry (RMat44Arg inModelMatrix, const AABox &inWorldSpaceBounds, float inLODScaleSq, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode=ECullMode::CullBackFace, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)=0
 
void DrawGeometry (RMat44Arg inModelMatrix, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode=ECullMode::CullBackFace, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)
 
virtual void DrawText3D (RVec3Arg inPosition, const string_view &inString, ColorArg inColor=Color::sWhite, float inHeight=0.5f)=0
 Draw text.
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Static Public Member Functions

static AABox sCalculateBounds (const Vertex *inVertices, int inVertexCount)
 Calculate bounding box for a batch of triangles.
 

Static Public Attributes

static DebugRenderersInstance = nullptr
 Singleton instance.
 

Protected Member Functions

void Initialize ()
 Initialize the system, must be called from the constructor of the DebugRenderer implementation.
 

Detailed Description

Simple triangle renderer for debugging purposes.

Inherit from this class to provide your own implementation.

Implement the following virtual functions:

  • DrawLine
  • DrawTriangle
  • DrawText3D
  • CreateTriangleBatch
  • DrawGeometry

Make sure you call Initialize() from the constructor of your implementation.

The CreateTriangleBatch is used to prepare a batch of triangles to be drawn by a single DrawGeometry call, which means that Jolt can render a complex scene much more efficiently than when each triangle in that scene would have been drawn through DrawTriangle.

Note that an implementation that implements CreateTriangleBatch and DrawGeometry is provided by DebugRendererSimple which can be used to start quickly.

Member Typedef Documentation

◆ Batch

Handle for a batch of triangles.

◆ GeometryRef

Handle for a lodded triangle batch.

◆ SupportFunction

using DebugRenderer::SupportFunction = function<Vec3 (Vec3Arg inDirection)>

Create a primitive for a convex shape using its support function.

Member Enumeration Documentation

◆ ECastShadow

enum class DebugRenderer::ECastShadow
strong

Enum that determines if a shadow should be cast or not.

Enumerator
On 
Off 

◆ ECullMode

enum class DebugRenderer::ECullMode
strong

Determines which polygons are culled.

Enumerator
CullBackFace 

Don't draw backfacing polygons.

CullFrontFace 

Don't draw front facing polygons.

Off 

Don't do culling and draw both sides.

◆ EDrawMode

enum class DebugRenderer::EDrawMode
strong

Determines how triangles are drawn.

Enumerator
Solid 

Draw as a solid shape.

Wireframe 

Draw as wireframe.

Constructor & Destructor Documentation

◆ DebugRenderer()

DebugRenderer::DebugRenderer ( )

Constructor.

◆ ~DebugRenderer()

DebugRenderer::~DebugRenderer ( )
virtual

Member Function Documentation

◆ CreateTriangleBatch() [1/5]

Batch DebugRenderer::CreateTriangleBatch ( const Array< Triangle > &  inTriangles)
inline

◆ CreateTriangleBatch() [2/5]

Batch DebugRenderer::CreateTriangleBatch ( const Array< Vertex > &  inVertices,
const Array< uint32 > &  inIndices 
)
inline

◆ CreateTriangleBatch() [3/5]

virtual Batch DebugRenderer::CreateTriangleBatch ( const Triangle inTriangles,
int  inTriangleCount 
)
pure virtual

Create a batch of triangles that can be drawn efficiently.

Implemented in DebugRendererRecorder, and DebugRendererSimple.

◆ CreateTriangleBatch() [4/5]

virtual Batch DebugRenderer::CreateTriangleBatch ( const Vertex inVertices,
int  inVertexCount,
const uint32 inIndices,
int  inIndexCount 
)
pure virtual

◆ CreateTriangleBatch() [5/5]

DebugRenderer::Batch DebugRenderer::CreateTriangleBatch ( const VertexList inVertices,
const IndexedTriangleNoMaterialList inTriangles 
)

◆ CreateTriangleBatchForConvex()

DebugRenderer::Batch DebugRenderer::CreateTriangleBatchForConvex ( SupportFunction  inGetSupport,
int  inLevel,
AABox outBounds = nullptr 
)

◆ CreateTriangleGeometryForConvex()

DebugRenderer::GeometryRef DebugRenderer::CreateTriangleGeometryForConvex ( SupportFunction  inGetSupport)

◆ DrawArrow()

void DebugRenderer::DrawArrow ( RVec3Arg  inFrom,
RVec3Arg  inTo,
ColorArg  inColor,
float  inSize 
)

Draw an arrow.

◆ DrawBox() [1/2]

void DebugRenderer::DrawBox ( const AABox inBox,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

Draw a box.

◆ DrawBox() [2/2]

void DebugRenderer::DrawBox ( RMat44Arg  inMatrix,
const AABox inBox,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

◆ DrawCapsule()

void DebugRenderer::DrawCapsule ( RMat44Arg  inMatrix,
float  inHalfHeightOfCylinder,
float  inRadius,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

Draw a capsule with one half sphere at (0, -inHalfHeightOfCylinder, 0) and the other half sphere at (0, inHalfHeightOfCylinder, 0) and radius inRadius. The capsule will be transformed by inMatrix.

◆ DrawCoordinateSystem()

void DebugRenderer::DrawCoordinateSystem ( RMat44Arg  inTransform,
float  inSize = 1.0f 
)

Draw coordinate system (3 arrows, x = red, y = green, z = blue)

◆ DrawCylinder()

void DebugRenderer::DrawCylinder ( RMat44Arg  inMatrix,
float  inHalfHeight,
float  inRadius,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

Draw a cylinder with top (0, inHalfHeight, 0) and bottom (0, -inHalfHeight, 0) and radius inRadius. The cylinder will be transformed by inMatrix

◆ DrawGeometry() [1/2]

void DebugRenderer::DrawGeometry ( RMat44Arg  inModelMatrix,
ColorArg  inModelColor,
const GeometryRef inGeometry,
ECullMode  inCullMode = ECullMode::CullBackFace,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)
inline

◆ DrawGeometry() [2/2]

virtual void DebugRenderer::DrawGeometry ( RMat44Arg  inModelMatrix,
const AABox inWorldSpaceBounds,
float  inLODScaleSq,
ColorArg  inModelColor,
const GeometryRef inGeometry,
ECullMode  inCullMode = ECullMode::CullBackFace,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)
pure virtual

Draw some geometry

Parameters
inModelMatrixis the matrix that transforms the geometry to world space.
inWorldSpaceBoundsis the bounding box of the geometry after transforming it into world space.
inLODScaleSqis the squared scale of the model matrix, it is multiplied with the LOD distances in inGeometry to calculate the real LOD distance (so a number > 1 will force a higher LOD).
inModelColoris the color with which to multiply the vertex colors in inGeometry.
inGeometryThe geometry to draw.
inCullModedetermines which polygons are culled.
inCastShadowdetermines if this geometry should cast a shadow or not.
inDrawModedetermines if we draw the geometry solid or in wireframe.

Implemented in DebugRendererRecorder, and DebugRendererSimple.

◆ DrawLine()

virtual void DebugRenderer::DrawLine ( RVec3Arg  inFrom,
RVec3Arg  inTo,
ColorArg  inColor 
)
pure virtual

Draw line.

Implemented in DebugRendererRecorder.

◆ DrawMarker()

void DebugRenderer::DrawMarker ( RVec3Arg  inPosition,
ColorArg  inColor,
float  inSize 
)

Draw a marker on a position.

◆ DrawOpenCone()

void DebugRenderer::DrawOpenCone ( RVec3Arg  inTop,
Vec3Arg  inAxis,
Vec3Arg  inPerpendicular,
float  inHalfAngle,
float  inLength,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

Draw a bottomless cone.

Parameters
inTopTop of cone, center of base is at inTop + inAxis.
inAxisHeight and direction of cone
inPerpendicularPerpendicular vector to inAxis.
inHalfAngleSpecifies the cone angle in radians (angle measured between inAxis and cone surface).
inLengthThe length of the cone.
inColorColor to use for drawing the cone.
inCastShadowdetermines if this geometry should cast a shadow or not.
inDrawModedetermines if we draw the geometry solid or in wireframe.

◆ DrawPie()

void DebugRenderer::DrawPie ( RVec3Arg  inCenter,
float  inRadius,
Vec3Arg  inNormal,
Vec3Arg  inAxis,
float  inMinAngle,
float  inMaxAngle,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

Draw a pie (part of a circle).

Parameters
inCenterThe center of the circle.
inRadiusRadius of the circle.
inNormalThe plane normal in which the pie resides.
inAxisThe axis that defines an angle of 0 radians.
inMinAngleThe pie will be drawn between [inMinAngle, inMaxAngle] (in radians).
inMaxAngleThe pie will be drawn between [inMinAngle, inMaxAngle] (in radians).
inColorColor to use for drawing the pie.
inCastShadowdetermines if this geometry should cast a shadow or not.
inDrawModedetermines if we draw the geometry solid or in wireframe.

◆ DrawPlane()

void DebugRenderer::DrawPlane ( RVec3Arg  inPoint,
Vec3Arg  inNormal,
ColorArg  inColor,
float  inSize 
)

Draw a plane through inPoint with normal inNormal.

◆ DrawSphere()

void DebugRenderer::DrawSphere ( RVec3Arg  inCenter,
float  inRadius,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

Draw a sphere.

◆ DrawSwingConeLimits()

void DebugRenderer::DrawSwingConeLimits ( RMat44Arg  inMatrix,
float  inSwingYHalfAngle,
float  inSwingZHalfAngle,
float  inEdgeLength,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

Draws cone rotation limits as used by the SwingTwistConstraintPart.

Parameters
inMatrixMatrix that transforms from constraint space to world space
inSwingYHalfAngleSee SwingTwistConstraintPart
inSwingZHalfAngleSee SwingTwistConstraintPart
inEdgeLengthSize of the edge of the cone shape
inColorColor to use for drawing the cone.
inCastShadowdetermines if this geometry should cast a shadow or not.
inDrawModedetermines if we draw the geometry solid or in wireframe.

◆ DrawSwingPyramidLimits()

void DebugRenderer::DrawSwingPyramidLimits ( RMat44Arg  inMatrix,
float  inMinSwingYAngle,
float  inMaxSwingYAngle,
float  inMinSwingZAngle,
float  inMaxSwingZAngle,
float  inEdgeLength,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

Draws rotation limits as used by the SwingTwistConstraintPart.

Parameters
inMatrixMatrix that transforms from constraint space to world space
inMinSwingYAngleSee SwingTwistConstraintPart
inMaxSwingYAngleSee SwingTwistConstraintPart
inMinSwingZAngleSee SwingTwistConstraintPart
inMaxSwingZAngleSee SwingTwistConstraintPart
inEdgeLengthSize of the edge of the cone shape
inColorColor to use for drawing the cone.
inCastShadowdetermines if this geometry should cast a shadow or not.
inDrawModedetermines if we draw the geometry solid or in wireframe.

◆ DrawText3D()

virtual void DebugRenderer::DrawText3D ( RVec3Arg  inPosition,
const string_view &  inString,
ColorArg  inColor = Color::sWhite,
float  inHeight = 0.5f 
)
pure virtual

Draw text.

Implemented in DebugRendererRecorder.

◆ DrawTriangle()

virtual void DebugRenderer::DrawTriangle ( RVec3Arg  inV1,
RVec3Arg  inV2,
RVec3Arg  inV3,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::Off 
)
pure virtual

Draw a single back face culled triangle.

Implemented in DebugRendererRecorder, and DebugRendererSimple.

◆ DrawUnitSphere()

void DebugRenderer::DrawUnitSphere ( RMat44Arg  inMatrix,
ColorArg  inColor,
ECastShadow  inCastShadow = ECastShadow::On,
EDrawMode  inDrawMode = EDrawMode::Solid 
)

◆ DrawWireBox() [1/3]

void DebugRenderer::DrawWireBox ( const AABox inBox,
ColorArg  inColor 
)

Draw wireframe box.

◆ DrawWireBox() [2/3]

void DebugRenderer::DrawWireBox ( const OrientedBox inBox,
ColorArg  inColor 
)

◆ DrawWireBox() [3/3]

void DebugRenderer::DrawWireBox ( RMat44Arg  inMatrix,
const AABox inBox,
ColorArg  inColor 
)

◆ DrawWirePolygon()

template<class VERTEX_ARRAY >
void DebugRenderer::DrawWirePolygon ( RMat44Arg  inTransform,
const VERTEX_ARRAY &  inVertices,
ColorArg  inColor,
float  inArrowSize = 0.0f 
)
inline

Draw a wireframe polygon.

◆ DrawWireSphere()

void DebugRenderer::DrawWireSphere ( RVec3Arg  inCenter,
float  inRadius,
ColorArg  inColor,
int  inLevel = 3 
)

Draw wireframe sphere.

◆ DrawWireTriangle()

void DebugRenderer::DrawWireTriangle ( RVec3Arg  inV1,
RVec3Arg  inV2,
RVec3Arg  inV3,
ColorArg  inColor 
)

Draw wireframe triangle.

◆ DrawWireUnitSphere()

void DebugRenderer::DrawWireUnitSphere ( RMat44Arg  inMatrix,
ColorArg  inColor,
int  inLevel = 3 
)

◆ Initialize()

void DebugRenderer::Initialize ( )
protected

Initialize the system, must be called from the constructor of the DebugRenderer implementation.

◆ NextFrame()

void DebugRenderer::NextFrame ( )

Call once after frame is complete. Releases unused dynamically generated geometry assets.

◆ sCalculateBounds()

AABox DebugRenderer::sCalculateBounds ( const Vertex inVertices,
int  inVertexCount 
)
static

Calculate bounding box for a batch of triangles.

Member Data Documentation

◆ sInstance

JPH_NAMESPACE_BEGIN DebugRenderer * DebugRenderer::sInstance = nullptr
static

Singleton instance.


The documentation for this class was generated from the following files: