Ver Fonte

Merge pull request #1381 from Azaezel/debugdraw

From Dušan Jocić: additional debugdraw entries.
Anis há 9 anos atrás
pai
commit
92e5cb3528
2 ficheiros alterados com 118 adições e 4 exclusões
  1. 108 2
      Engine/source/gfx/sim/debugDraw.cpp
  2. 10 2
      Engine/source/gfx/sim/debugDraw.h

+ 108 - 2
Engine/source/gfx/sim/debugDraw.cpp

@@ -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)

+ 10 - 2
Engine/source/gfx/sim/debugDraw.h

@@ -124,7 +124,10 @@ public:
    void drawLine(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f,1.0f,1.0f));	
    void drawLine(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f,1.0f,1.0f));	
    void drawTri(const Point3F &a, const Point3F &b, const Point3F &c, const ColorF &color = ColorF(1.0f,1.0f,1.0f));
    void drawTri(const Point3F &a, const Point3F &b, const Point3F &c, const ColorF &color = ColorF(1.0f,1.0f,1.0f));
    void drawText(const Point3F& pos, const String& text, const ColorF &color = ColorF(1.0f,1.0f,1.0f));
    void drawText(const Point3F& pos, const String& text, const ColorF &color = ColorF(1.0f,1.0f,1.0f));
-
+   void drawCapsule(const Point3F &a, const F32 &radius, const F32 &height, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f));
+   void drawDirectionLine(const Point3F &a, const Point3F &b, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f));
+   void drawOutlinedText(const Point3F& pos, const String& text, const ColorF &color = ColorF(1.0f, 1.0f, 1.0f), const ColorF &colorOutline = ColorF(0.0f, 0.0f, 0.0f));
+   
    /// Render a wireframe view of the given polyhedron.
    /// Render a wireframe view of the given polyhedron.
    void drawPolyhedron( const AnyPolyhedron& polyhedron, const ColorF& color = ColorF( 1.f, 1.f, 1.f ) );
    void drawPolyhedron( const AnyPolyhedron& polyhedron, const ColorF& color = ColorF( 1.f, 1.f, 1.f ) );
 
 
@@ -161,6 +164,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 +172,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 +195,7 @@ private:
 
 
    GFXStateBlockRef mRenderZOffSB;
    GFXStateBlockRef mRenderZOffSB;
    GFXStateBlockRef mRenderZOnSB;
    GFXStateBlockRef mRenderZOnSB;
+   GFXStateBlockRef mRenderAlpha;
 
 
    Resource<GFont> mFont;
    Resource<GFont> mFont;