File size: 2,634 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
class ComponentEntityDebug extends Component
{
protected Shape m_DebugShapeBBox;
protected Shape m_DebugShapeDirection;
protected float m_DebugShapeDirectionDist;
// -------------------------------------------------------------------------
override Shape DebugBBoxDraw()
{
#ifndef DEVELOPER
return null;
#endif
if ( m_DebugShapeBBox )
m_DebugShapeBBox.Destroy();
vector min_max[2];
if (!m_ThisEntityAI.GetCollisionBox(min_max))
return null;
m_DebugShapeBBox = Debug.DrawBox(min_max[0], min_max[1]);
GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(OnDrawing, 0, true);
m_ThisEntityAI.SetEventMask(EntityEvent.FRAME);
return null;
}
// -------------------------------------------------------------------------
override void DebugBBoxSetColor(int color)
{
if ( m_DebugShapeBBox )
{
m_DebugShapeBBox.SetColor(color);
}
}
// -------------------------------------------------------------------------
override void DebugBBoxDelete()
{
#ifndef DEVELOPER
return;
#endif
if ( m_DebugShapeBBox )
{
m_DebugShapeBBox.Destroy();
m_DebugShapeBBox = null;
}
if ( !m_DebugShapeDirection && !m_DebugShapeBBox )
{
GetGame().GetCallQueue(CALL_CATEGORY_GUI).Remove(OnDrawing);
}
}
// -------------------------------------------------------------------------
override Shape DebugDirectionDraw(float distance = 1)
{
#ifndef DEVELOPER
return null;
#endif
if ( m_DebugShapeDirection )
{
m_DebugShapeDirection.Destroy();
}
vector p1 = "0 0 0";
vector p2 = m_ThisEntityAI.GetDirection() * m_DebugShapeDirectionDist;
m_DebugShapeDirectionDist = distance;
m_DebugShapeDirection = Debug.DrawArrow(p1, p2);
GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(OnDrawing, 0, true);
m_ThisEntityAI.SetEventMask(EntityEvent.FRAME);
return null;
}
// -------------------------------------------------------------------------
override void DebugDirectionDelete()
{
#ifndef DEVELOPER
return;
#endif
if ( m_DebugShapeDirection )
{
m_DebugShapeDirection.Destroy();
m_DebugShapeDirection = null;
}
if ( !m_DebugShapeDirection && !m_DebugShapeBBox )
{
GetGame().GetCallQueue(CALL_CATEGORY_GUI).Remove(OnDrawing);
}
}
void OnDrawing()
{
#ifndef DEVELOPER
return;
#endif
if ( m_DebugShapeBBox || m_DebugShapeDirection )
{
vector mat[4];
m_ThisEntityAI.GetTransform(mat);
if ( m_DebugShapeBBox )
{
m_DebugShapeBBox.SetMatrix(mat);
}
if ( m_DebugShapeDirection )
{
m_DebugShapeDirection.SetMatrix(mat);
}
}
}
} |