Skip to main content

Drawing Helper Examples

Drawing Arrows

Drawing arrows with configurable lifetime.

void LDrawArrowComponent::DrawLifeTimeArrow()
{
CXMVECTOR vPos = GetPosition();
CXMVECTOR vStart = vPos + m_sArrowStartLocal.GetVector();
CXMVECTOR vEnd = vPos + m_sArrowEndLocal.GetVector();

DebugDrawHelper::DrawDebugDirectionalArrow(GetScene(), DESIGN_LINE::DEFAULT,
vStart, vEnd, m_fArrowSize,
m_nArrowColor, m_fArrowLifeTime);
}

Drawing Boxes

Drawing boxes with configurable lifetime.

void LDrawBoxComponent::DrawLifeTimeBox()
{
if (!m_bDrawPerFrame)
{
CXMVECTOR vPos = GetPosition() + m_sBoxPositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sBoxAngleLocal.GetAngle();
CXMVECTOR vQuat = FXMath::AngleToQuat(vAngle);
CXMVECTOR vExtent = m_vBoxExtent.GetVector();

DebugDrawHelper::DrawDebugBox(GetScene(), DESIGN_LINE::DEFAULT,
vPos, vExtent, vQuat, m_nBoxColor, m_fBoxLifeTime);
}
}

Drawing boxes per frame.

LDrawBoxComponent::LDrawBoxComponent()
{
//////////////////////////////////////////////////////////////////////////
m_ComponentUpdate.bAllowUpdate = true;
m_ComponentUpdate.InitUpdateGroup(UPDATE_GROUP_ENUM::PrePhysics);

m_bAutoActivate = true;
//////////////////////////////////////////////////////////////////////////

m_bDrawPerFrame = true;
m_vBoxExtent = custom_vector3_t(0.5F, 0.5F, 0.5F);
m_nBoxColor = COLOR_ARGB(255, 0, 0, 255);
m_fBoxLifeTime = 5.0F;
}

void LDrawBoxComponent::DrawWireBoxPerFrame()
{
if (m_bDrawPerFrame)
{
CXMVECTOR vPos = GetPosition() + m_sBoxPositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sBoxAngleLocal.GetAngle();
CXMMATRIX vRotationMT = XMMatrixRotationRollPitchYawFromVector(vAngle);
CXMVECTOR vX = vRotationMT.r[0];
CXMVECTOR vY = vRotationMT.r[1];
CXMVECTOR vZ = vRotationMT.r[2];
CXMVECTOR vExtent = m_vBoxExtent.GetVector();

DebugDrawHelper::DrawOrientedWireBoxPerFrame(GetScene(),
DESIGN_LINE::DEFAULT, vPos, vX, vY, vZ, vExtent, m_nBoxColor,
m_DefaultDynamicColorPickID.GetColor());
}
}

void LDrawBoxComponent::UpdateComponent(float fDeltaTime,
LEVEL_UPDATE_ENUM nUpdateType,
CComponentUpdateFunction* pThisUpdateFunction)
{
LPrimitiveComponent::UpdateComponent(fDeltaTime, nUpdateType,
pThisUpdateFunction);

if (ShouldRender())
{
DrawWireBoxPerFrame();
}
}

Drawing Capsules

Drawing capsules with configurable lifetime.

void LDrawCapsuleComponent::DrawLifeTimeCapsule()
{
if (!m_bDrawPerFrame)
{
CXMVECTOR vPos = GetPosition() + m_sCapsulePositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sCapsuleAngleLocal.GetAngle();
CXMVECTOR vQuat = FXMath::AngleToQuat(vAngle);

DebugDrawHelper::DrawDebugCapsule(GetScene(),
DESIGN_LINE::DEFAULT, vPos,
m_fCapsuleHalfHeight, m_fCapsuleRadius,
vQuat, m_nCapsuleColor, m_fCapsuleLifeTime);
}
}

Drawing capsules per frame.

LDrawCapsuleComponent::LDrawCapsuleComponent()
{
//////////////////////////////////////////////////////////////////////////
m_ComponentUpdate.bAllowUpdate = true;
m_ComponentUpdate.InitUpdateGroup(UPDATE_GROUP_ENUM::PrePhysics);

m_bAutoActivate = true;
//////////////////////////////////////////////////////////////////////////

m_bDrawPerFrame = true;
m_fCapsuleRadius = 0.5F;
m_fCapsuleHalfHeight = 1.0F;
m_nCapsuleNumSides = 16;
m_nCapsuleColor = COLOR_ARGB(255, 0, 255, 255);
m_fCapsuleLifeTime = 5.0F;
}

void LDrawCapsuleComponent::DrawWireCapsulePerFrame()
{
if (m_bDrawPerFrame)
{
CXMVECTOR vPos = GetPosition() + m_sCapsulePositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sCapsuleAngleLocal.GetAngle();
CXMMATRIX vRotationMT = XMMatrixRotationRollPitchYawFromVector(vAngle);
CXMVECTOR vX = vRotationMT.r[0];
CXMVECTOR vY = vRotationMT.r[1];
CXMVECTOR vZ = vRotationMT.r[2];

DebugDrawHelper::DrawWireCapsulePerFrame(GetScene(),
DESIGN_LINE::DEFAULT, vPos, vX, vY, vZ,
m_nCapsuleColor, m_DefaultDynamicColorPickID.GetColor(),
m_fCapsuleRadius, m_fCapsuleHalfHeight, m_nCapsuleNumSides);
}
}

void LDrawCapsuleComponent::UpdateComponent(float fDeltaTime,
LEVEL_UPDATE_ENUM nUpdateType,
CComponentUpdateFunction* pThisUpdateFunction)
{
LPrimitiveComponent::UpdateComponent(fDeltaTime, nUpdateType,
pThisUpdateFunction);

if (ShouldRender())
{
DrawWireCapsulePerFrame();
}
}

Drawing Circles

Drawing circles with configurable lifetime.

void LDrawCircleComponent::DrawLifeTimeCircle()
{
if (!m_bDrawPerFrame)
{
CXMVECTOR vPos = GetPosition() + m_sCirclePositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sCircleAngleLocal.GetAngle();
CXMMATRIX vRotationMT = XMMatrixRotationRollPitchYawFromVector(vAngle);
CXMVECTOR vX = vRotationMT.r[0];
CXMVECTOR vZ = vRotationMT.r[2];

DebugDrawHelper::DrawDebugCircle(GetScene(),
DESIGN_LINE::DEFAULT, vPos, vX, vZ,
m_nCircleColor, m_fCircleRadius, m_nCircleNumSides,
m_fCircleLifeTime);
}
}

Drawing circles per frame.

LDrawCircleComponent::LDrawCircleComponent()
{
//////////////////////////////////////////////////////////////////////////
m_ComponentUpdate.bAllowUpdate = true;
m_ComponentUpdate.InitUpdateGroup(UPDATE_GROUP_ENUM::PrePhysics);

m_bAutoActivate = true;
//////////////////////////////////////////////////////////////////////////

m_bDrawPerFrame = true;
m_fCircleRadius = 0.5F;
m_nCircleNumSides = 32;
m_nCircleColor = COLOR_ARGB(255, 255, 255, 0);
m_fCircleLifeTime = 5.0F;
}

void LDrawCircleComponent::DrawCirclePerFrame()
{
if (m_bDrawPerFrame)
{
CXMVECTOR vPos = GetPosition() + m_sCirclePositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sCircleAngleLocal.GetAngle();
CXMMATRIX vRotationMT = XMMatrixRotationRollPitchYawFromVector(vAngle);
CXMVECTOR vX = vRotationMT.r[0];
CXMVECTOR vZ = vRotationMT.r[2];

DebugDrawHelper::DrawCirclePerFrame(GetScene(),
DESIGN_LINE::DEFAULT, vPos, vX, vZ,
m_nCircleColor, m_DefaultDynamicColorPickID.GetColor(),
m_fCircleRadius, m_nCircleNumSides);
}
}

void LDrawCircleComponent::UpdateComponent(float fDeltaTime,
LEVEL_UPDATE_ENUM nUpdateType,
CComponentUpdateFunction* pThisUpdateFunction)
{
LPrimitiveComponent::UpdateComponent(fDeltaTime, nUpdateType,
pThisUpdateFunction);

if (ShouldRender())
{
DrawCirclePerFrame();
}
}

Drawing Half Circles

Drawing half circles with configurable lifetime.

void LDrawHalfCircleComponent::DrawLifeTimeHalfCircle()
{
if (!m_bDrawPerFrame)
{
CXMVECTOR vPos = GetPosition() + m_sHalfCirclePositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sHalfCircleAngleLocal.GetAngle();
CXMMATRIX vRotationMT = XMMatrixRotationRollPitchYawFromVector(vAngle);
CXMVECTOR vX = vRotationMT.r[0];
CXMVECTOR vZ = vRotationMT.r[2];

DebugDrawHelper::DrawDebugHalfCircle(GetScene(),
DESIGN_LINE::DEFAULT, vPos, vX, vZ,
m_nHalfCircleColor, m_fHalfCircleRadius,
m_nHalfCircleNumSides, m_fHalfCircleLifeTime);
}
}

Drawing half circles per frame.

LDrawHalfCircleComponent::LDrawHalfCircleComponent()
{
//////////////////////////////////////////////////////////////////////////
m_ComponentUpdate.bAllowUpdate = true;
m_ComponentUpdate.InitUpdateGroup(UPDATE_GROUP_ENUM::PrePhysics);

m_bAutoActivate = true;
//////////////////////////////////////////////////////////////////////////

m_bDrawPerFrame = true;
m_fHalfCircleRadius = 0.5F;
m_nHalfCircleNumSides = 16;
m_nHalfCircleColor = COLOR_ARGB(255, 255, 0, 255);
m_fHalfCircleLifeTime = 5.0F;
}

void LDrawHalfCircleComponent::DrawHalfCirclePerFrame()
{
if (m_bDrawPerFrame)
{
CXMVECTOR vPos = GetPosition() + m_sHalfCirclePositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sHalfCircleAngleLocal.GetAngle();
CXMMATRIX vRotationMT = XMMatrixRotationRollPitchYawFromVector(vAngle);
CXMVECTOR vX = vRotationMT.r[0];
CXMVECTOR vZ = vRotationMT.r[2];

DebugDrawHelper::DrawHalfCirclePerFrame(GetScene(),
DESIGN_LINE::DEFAULT, vPos, vX, vZ,
m_nHalfCircleColor, m_DefaultDynamicColorPickID.GetColor(),
m_fHalfCircleRadius, m_nHalfCircleNumSides);
}
}

void LDrawHalfCircleComponent::UpdateComponent(float fDeltaTime,
LEVEL_UPDATE_ENUM nUpdateType,
CComponentUpdateFunction* pThisUpdateFunction)
{
LPrimitiveComponent::UpdateComponent(fDeltaTime, nUpdateType,
pThisUpdateFunction);

if (ShouldRender())
{
DrawHalfCirclePerFrame();
}
}

Drawing Lines

Drawing lines with configurable lifetime.

void LDrawLineComponent::DrawLifeTimeLine()
{
if (!m_bDrawPerFrame)
{
CXMVECTOR vPos = GetPosition();
CXMVECTOR vStart = vPos + m_sLineStartLocal.GetVector();
CXMVECTOR vEnd = vPos + m_sLineEndLocal.GetVector();

DebugDrawHelper::DrawDebugLine(GetScene(), DESIGN_LINE::DEFAULT,
vStart, vEnd, m_nLineColor, m_fLineLifeTime);
}
}

Drawing lines per frame.

LDrawLineComponent::LDrawLineComponent()
{
//////////////////////////////////////////////////////////////////////////
m_ComponentUpdate.bAllowUpdate = true;
m_ComponentUpdate.InitUpdateGroup(UPDATE_GROUP_ENUM::PrePhysics);

m_bAutoActivate = true;
//////////////////////////////////////////////////////////////////////////

m_bDrawPerFrame = true;
m_sLineStartLocal = custom_vector3_t(0.0F, 0.0F, -0.5F);
m_sLineEndLocal = custom_vector3_t(0.0F, 0.0F, 0.5F);
m_nLineColor = COLOR_ARGB(255, 255, 0, 0);
m_fLineLifeTime = 5.0F;
}

void LDrawLineComponent::DrawLinePerFrame()
{
if (m_bDrawPerFrame)
{
XMVECTOR vPos = GetPosition();

DebugDrawHelper::DrawLinePerFrame(GetScene(), DESIGN_LINE::DEFAULT,
vPos + m_sLineStartLocal.GetVector(),
vPos + m_sLineEndLocal.GetVector(),
m_nLineColor, m_DefaultDynamicColorPickID.GetColor());
}
}

void LDrawLineComponent::UpdateComponent(float fDeltaTime,
LEVEL_UPDATE_ENUM nUpdateType,
CComponentUpdateFunction* pThisUpdateFunction)
{
LPrimitiveComponent::UpdateComponent(fDeltaTime, nUpdateType,
pThisUpdateFunction);

if (ShouldRender())
{
DrawLinePerFrame();
}
}

Drawing Polygons

Drawing polygons per frame by line lists.

LDrawPolygonComponent::LDrawPolygonComponent()
{
//////////////////////////////////////////////////////////////////////////
m_ComponentUpdate.bAllowUpdate = true;
m_ComponentUpdate.InitUpdateGroup(UPDATE_GROUP_ENUM::PrePhysics);

m_bAutoActivate = true;
//////////////////////////////////////////////////////////////////////////

m_bWiredPolygon = true;
m_nPolygonEdges = 32;
m_fPolygonRadius = 0.5F;
m_nPolygonColor = COLOR_ARGB(255, 0, 128, 128);
m_bPolygonCacheDirty = true;
}

void LDrawPolygonComponent::DrawWiredPolygonPerFrame()
{
CXMVECTOR vPos = GetPosition() + m_sPolygonPositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sPolygonAngleLocal.GetAngle();
CXMVECTOR vQuat = FXMath::AngleToQuat(vAngle);

FTransform mtx;
mtx.SetLocation(vPos);
mtx.SetQuat(vQuat);

if (m_bPolygonCacheDirty)
{
RefreshWiredPolygonCache();
}

// Draw wired polygon with line list
DebugDrawHelper::DrawLineListPerFrame(GetScene(),
DESIGN_LINE::DEFAULT, mtx, m_WiredPolygonVertsCache,
m_WiredPolygonIndicesCache, m_DefaultDynamicColorPickID.GetColor());
}

void LDrawPolygonComponent::UpdateComponent(float fDeltaTime,
LEVEL_UPDATE_ENUM nUpdateType,
CComponentUpdateFunction* pThisUpdateFunction)
{
LPrimitiveComponent::UpdateComponent(fDeltaTime, nUpdateType,
pThisUpdateFunction);

if (ShouldRender())
{
if (m_bWiredPolygon)
{
DrawWiredPolygonPerFrame();
}
else
{
DrawPolygonPerFrame();
}
}
}

Drawing polygons per frame by triangle lists.

LDrawPolygonComponent::LDrawPolygonComponent()
{
//////////////////////////////////////////////////////////////////////////
m_ComponentUpdate.bAllowUpdate = true;
m_ComponentUpdate.InitUpdateGroup(UPDATE_GROUP_ENUM::PrePhysics);

m_bAutoActivate = true;
//////////////////////////////////////////////////////////////////////////

m_bWiredPolygon = true;
m_nPolygonEdges = 32;
m_fPolygonRadius = 0.5F;
m_nPolygonColor = COLOR_ARGB(255, 0, 128, 128);
m_bPolygonCacheDirty = true;
}

void LDrawPolygonComponent::DrawPolygonPerFrame()
{
CXMVECTOR vPos = GetPosition() + m_sPolygonPositionLocal.GetVector();
CXMVECTOR vAngle = GetAngle() + m_sPolygonAngleLocal.GetAngle();
CXMVECTOR vQuat = FXMath::AngleToQuat(vAngle);

FTransform mtx;
mtx.SetLocation(vPos);
mtx.SetQuat(vQuat);

if (m_bPolygonCacheDirty)
{
RefreshPolygonCache();
}

// Draw polygon with triangle list
DebugDrawHelper::DrawTriangleListPerFrame(GetScene(),
DESIGN_LINE::DEFAULT, mtx, m_PolygonVertsCache,
m_PolygonIndicesCache, m_DefaultDynamicColorPickID.GetColor());
}

void LDrawPolygonComponent::UpdateComponent(float fDeltaTime,
LEVEL_UPDATE_ENUM nUpdateType,
CComponentUpdateFunction* pThisUpdateFunction)
{
LPrimitiveComponent::UpdateComponent(fDeltaTime, nUpdateType,
pThisUpdateFunction);

if (ShouldRender())
{
if (m_bWiredPolygon)
{
DrawWiredPolygonPerFrame();
}
else
{
DrawPolygonPerFrame();
}
}
}

Drawing Spheres

Drawing spheres with configurable lifetime.

void LDrawSphereComponent::DrawLifeTimeSphere()
{
CXMVECTOR vPos = GetPosition() + m_sSpherePositionLocal.GetVector();

DebugDrawHelper::DrawDebugSphere(GetScene(), DESIGN_LINE::DEFAULT,
vPos, m_fSphereRadius, m_nSphereSegments,
m_nSphereColor, m_fSphereLifeTime);
}

Drawing Triangles

Drawing triangles per frame.

LDrawTriangleComponent::LDrawTriangleComponent()
{
//////////////////////////////////////////////////////////////////////////
m_ComponentUpdate.bAllowUpdate = true;
m_ComponentUpdate.InitUpdateGroup(UPDATE_GROUP_ENUM::PrePhysics);

m_bAutoActivate = true;
//////////////////////////////////////////////////////////////////////////

m_sTriangleV1Local = custom_vector3_t(0.0F, 0.0F, 0.5F);
m_sTriangleV2Local = custom_vector3_t(-0.5F, 0.0F, 0.0F);
m_sTriangleV3Local = custom_vector3_t(0.5F, 0.0F, 0.0F);
m_nTriangleV1Color = COLOR_ARGB(255, 255, 0, 0);
m_nTriangleV2Color = COLOR_ARGB(255, 0, 255, 0);
m_nTriangleV3Color = COLOR_ARGB(255, 0, 0, 255);
}

void LDrawTriangleComponent::DrawTrianglePerFrame()
{
XMVECTOR vPos = GetPosition();

DebugDrawHelper::DrawTrianglePerFrame(GetScene(), DESIGN_LINE::DEFAULT,
vPos + m_sTriangleV1Local.GetVector(), m_nTriangleV1Color,
vPos + m_sTriangleV2Local.GetVector(), m_nTriangleV2Color,
vPos + m_sTriangleV3Local.GetVector(), m_nTriangleV3Color,
m_DefaultDynamicColorPickID.GetColor());
}

void LDrawTriangleComponent::UpdateComponent(float fDeltaTime,
LEVEL_UPDATE_ENUM nUpdateType,
CComponentUpdateFunction* pThisUpdateFunction)
{
LPrimitiveComponent::UpdateComponent(fDeltaTime, nUpdateType,
pThisUpdateFunction);

if (ShouldRender())
{
DrawTrianglePerFrame();
}
}