mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
From Dušan Jocić: additional debugdraw entries. DirectionLine, OutlinedText, Capsule
This commit is contained in:
parent
b24bdfbc8b
commit
005c3c4b36
2 changed files with 114 additions and 3 deletions
|
|
@ -132,6 +132,11 @@ void DebugDrawer::setupStateBlocks()
|
||||||
|
|
||||||
d.setZReadWrite(false);
|
d.setZReadWrite(false);
|
||||||
mRenderZOffSB = GFX->createStateBlock(d);
|
mRenderZOffSB = GFX->createStateBlock(d);
|
||||||
|
|
||||||
|
d.setCullMode(GFXCullCCW);
|
||||||
|
d.setZReadWrite(true, false);
|
||||||
|
d.setBlend(true);
|
||||||
|
mRenderAlpha = GFX->createStateBlock(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugDrawer::render()
|
void DebugDrawer::render()
|
||||||
|
|
@ -158,10 +163,13 @@ void DebugDrawer::render()
|
||||||
|
|
||||||
// Set up the state block...
|
// Set up the state block...
|
||||||
GFXStateBlockRef currSB;
|
GFXStateBlockRef currSB;
|
||||||
if(p->useZ)
|
if(p->type==DebugPrim::Capsule){
|
||||||
|
currSB = mRenderAlpha;
|
||||||
|
}else if(p->useZ){
|
||||||
currSB = mRenderZOnSB;
|
currSB = mRenderZOnSB;
|
||||||
else
|
}else{
|
||||||
currSB = mRenderZOffSB;
|
currSB = mRenderZOffSB;
|
||||||
|
}
|
||||||
GFX->setStateBlock( currSB );
|
GFX->setStateBlock( currSB );
|
||||||
|
|
||||||
Point3F d;
|
Point3F d;
|
||||||
|
|
@ -180,6 +188,47 @@ void DebugDrawer::render()
|
||||||
|
|
||||||
PrimBuild::end();
|
PrimBuild::end();
|
||||||
break;
|
break;
|
||||||
|
case DebugPrim::DirectionLine:
|
||||||
|
{
|
||||||
|
const static F32 ARROW_LENGTH = 0.2f, ARROW_RADIUS = 0.035f, CYLINDER_RADIUS = 0.008f;
|
||||||
|
Point3F &start = p->a, &end = p->b;
|
||||||
|
Point3F direction = end - start;
|
||||||
|
F32 length = direction.len();
|
||||||
|
if( length>ARROW_LENGTH ){
|
||||||
|
//cylinder with arrow on end
|
||||||
|
direction *= (1.0f/length);
|
||||||
|
Point3F baseArrow = end - (direction*ARROW_LENGTH);
|
||||||
|
GFX->getDrawUtil()->drawCone(currSB->getDesc(), baseArrow, end, ARROW_RADIUS, p->color);
|
||||||
|
GFX->getDrawUtil()->drawCylinder(currSB->getDesc(), start, baseArrow, CYLINDER_RADIUS, p->color);
|
||||||
|
}else if( length>0 ){
|
||||||
|
//short, so just draw arrow
|
||||||
|
GFX->getDrawUtil()->drawCone(currSB->getDesc(), start, end, ARROW_RADIUS, p->color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case DebugPrim::Capsule:
|
||||||
|
GFX->getDrawUtil()->drawCapsule(currSB->getDesc(), p->a, p->b.x, p->b.y, p->color);
|
||||||
|
break;
|
||||||
|
case DebugPrim::OutlinedText:
|
||||||
|
{
|
||||||
|
GFXTransformSaver saver;
|
||||||
|
Point3F result;
|
||||||
|
if (MathUtils::mProjectWorldToScreen(p->a, &result, GFX->getViewport(), GFX->getWorldMatrix(), GFX->getProjectionMatrix()))
|
||||||
|
{
|
||||||
|
GFX->setClipRect(GFX->getViewport());
|
||||||
|
Point2I where = Point2I(result.x, result.y);
|
||||||
|
|
||||||
|
GFX->getDrawUtil()->setBitmapModulation(p->color2);
|
||||||
|
GFX->getDrawUtil()->drawText(mFont, Point2I(where.x-1, where.y), p->mText);
|
||||||
|
GFX->getDrawUtil()->drawText(mFont, Point2I(where.x+1, where.y), p->mText);
|
||||||
|
GFX->getDrawUtil()->drawText(mFont, Point2I(where.x, where.y-1), p->mText);
|
||||||
|
GFX->getDrawUtil()->drawText(mFont, Point2I(where.x, where.y+1), p->mText);
|
||||||
|
|
||||||
|
GFX->getDrawUtil()->setBitmapModulation(p->color);
|
||||||
|
GFX->getDrawUtil()->drawText(mFont, where, p->mText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case DebugPrim::Box:
|
case DebugPrim::Box:
|
||||||
d = p->a - p->b;
|
d = p->a - p->b;
|
||||||
GFX->getDrawUtil()->drawCube(currSB->getDesc(), d * 0.5, (p->a + p->b) * 0.5, p->color);
|
GFX->getDrawUtil()->drawCube(currSB->getDesc(), d * 0.5, (p->a + p->b) * 0.5, p->color);
|
||||||
|
|
@ -262,6 +311,63 @@ void DebugDrawer::drawLine(const Point3F &a, const Point3F &b, const ColorF &col
|
||||||
mHead = n;
|
mHead = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DebugDrawer::drawCapsule(const Point3F &a, const F32 &radius, const F32 &height, const ColorF &color)
|
||||||
|
{
|
||||||
|
if(isFrozen || !isDrawing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DebugPrim *n = mPrimChunker.alloc();
|
||||||
|
|
||||||
|
n->useZ = true;
|
||||||
|
n->dieTime = 0;
|
||||||
|
n->a = a;
|
||||||
|
n->b.x = radius;
|
||||||
|
n->b.y = height;
|
||||||
|
n->color = color;
|
||||||
|
n->type = DebugPrim::Capsule;
|
||||||
|
|
||||||
|
n->next = mHead;
|
||||||
|
mHead = n;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugDrawer::drawDirectionLine(const Point3F &a, const Point3F &b, const ColorF &color)
|
||||||
|
{
|
||||||
|
if(isFrozen || !isDrawing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DebugPrim *n = mPrimChunker.alloc();
|
||||||
|
|
||||||
|
n->useZ = true;
|
||||||
|
n->dieTime = 0;
|
||||||
|
n->a = a;
|
||||||
|
n->b = b;
|
||||||
|
n->color = color;
|
||||||
|
n->type = DebugPrim::DirectionLine;
|
||||||
|
|
||||||
|
n->next = mHead;
|
||||||
|
mHead = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugDrawer::drawOutlinedText(const Point3F& pos, const String& text, const ColorF &color, const ColorF &colorOutline)
|
||||||
|
{
|
||||||
|
if(isFrozen || !isDrawing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DebugPrim *n = mPrimChunker.alloc();
|
||||||
|
|
||||||
|
n->useZ = false;
|
||||||
|
n->dieTime = 0;
|
||||||
|
n->a = pos;
|
||||||
|
n->color = color;
|
||||||
|
n->color2 = colorOutline;
|
||||||
|
dStrncpy(n->mText, text.c_str(), 256);
|
||||||
|
n->type = DebugPrim::OutlinedText;
|
||||||
|
|
||||||
|
n->next = mHead;
|
||||||
|
mHead = n;
|
||||||
|
}
|
||||||
|
|
||||||
void DebugDrawer::drawTri(const Point3F &a, const Point3F &b, const Point3F &c, const ColorF &color)
|
void DebugDrawer::drawTri(const Point3F &a, const Point3F &b, const Point3F &c, const ColorF &color)
|
||||||
{
|
{
|
||||||
if(isFrozen || !isDrawing)
|
if(isFrozen || !isDrawing)
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,7 @@ private:
|
||||||
{
|
{
|
||||||
/// Color used for this primitive.
|
/// Color used for this primitive.
|
||||||
ColorF color;
|
ColorF color;
|
||||||
|
ColorF color2;
|
||||||
|
|
||||||
/// Points used to store positional data. Exact semantics determined by type.
|
/// Points used to store positional data. Exact semantics determined by type.
|
||||||
Point3F a, b, c;
|
Point3F a, b, c;
|
||||||
|
|
@ -168,7 +169,10 @@ private:
|
||||||
Tri,
|
Tri,
|
||||||
Box,
|
Box,
|
||||||
Line,
|
Line,
|
||||||
Text
|
Text,
|
||||||
|
DirectionLine,
|
||||||
|
OutlinedText,
|
||||||
|
Capsule,
|
||||||
} type; ///< Type of the primitive. The meanings of a,b,c are determined by this.
|
} type; ///< Type of the primitive. The meanings of a,b,c are determined by this.
|
||||||
|
|
||||||
SimTime dieTime; ///< Time at which we should remove this from the list.
|
SimTime dieTime; ///< Time at which we should remove this from the list.
|
||||||
|
|
@ -188,6 +192,7 @@ private:
|
||||||
|
|
||||||
GFXStateBlockRef mRenderZOffSB;
|
GFXStateBlockRef mRenderZOffSB;
|
||||||
GFXStateBlockRef mRenderZOnSB;
|
GFXStateBlockRef mRenderZOnSB;
|
||||||
|
GFXStateBlockRef mRenderAlpha;
|
||||||
|
|
||||||
Resource<GFont> mFont;
|
Resource<GFont> mFont;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue