Game Development Community

Line Drawing

by Cameron Owen · in Torque Game Builder · 09/24/2006 (8:01 pm) · 3 replies

Are there are procedural drawing commands in TGB say for drawing lines and such? I've tried searching but so far have found nothing. I guess i could write a simple wrapper to simulate them by rotating and stretching imageMaps, but, was hoping there was something avaliable already.

#1
09/25/2006 (12:08 am)
There is a resource, but you need to recompile the engine source, so it's only good if you're a Pro license owner: www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9414
#2
09/25/2006 (7:01 am)
That's looks like the ticket! Quads would have next on my list of questions too. Thanks Philip.

Sadly I don't have TGB Pro. I purchased TGB 5 days ago and this is the second shortcomming I've hit whilst shifting through my design requirements. I've emailed GG, hoping they'll do me a "trade-in" so I won't have to shell out $300 (100 for TGB + and extra 195 for the Pro upgrade), which is a tad much for me in under a week. That and I fail to see where that extra $45 is going, surely not on accounting charges or merchant gateway overheads... We'll see.

Thanks again though.
#3
09/25/2006 (12:55 pm)
Here is something I whipped up for drawing debug lines while working on an IK solver in TGB using the little-known t2dShapeVector class. It works well for lines, but t2dShapeVector can make polys of pretty much any shapes. The downside is, that if it's non-convex the fill color will spill over the edge, plus you only get thin lines to draw with.

If all you need is simple colored lines, this should do you fine:

// return a zero length vertical line of the specified color
function DebugLine::createLine(%color)
{
   %line = new t2dShapeVector()
   {
      scenegraph = sceneWindow2D.getSceneGraph();
      class = "DebugLine";
      size = "200 200";
   };
   
   %line.setPolyCustom(2, "0 0 0 0");
   %line.setLineColor(%color);
   
   return %line;
}

// draw this line frop startPoint to endPoint
function DebugLine::draw(%this, %startPoint, %endPoint)
{
   %this.setPosition(%startPoint);
   %this.setPolyCustom(2, "0 0" SPC %this.getLocalPoint(%endPoint));
}

Note: this will only reliably draw lines up to 100 units long (center to closest edge). Increase the size field in the creation of the line if you need longer lines. If you do, make sure the size in both X and Y is twice the length of the longest line you think you'll need.

And usage..

...
// create a green debug line
%this.targetLine = DebugLine::createLine("0 1 0");  // color = "R G B [A]" (alpha is optional, 1 is assumed)

// have the line draw from this position to some target object's position
%this.targetLine.draw( %this.getPosition(), %this.target.getPosition() );
...

Edit: SP