Game Development Community

Functions for Drawing Primitives

by Leo Gura · in Torque Game Builder · 03/11/2007 (1:14 pm) · 5 replies

How would one go about drawing vector objects in Torque? I need to be able to draw a colored line, circle, rectangle, and polygon. Also, is there a way to fill a rectangle with a gradient, as one might do in Photoshop? I need these to be procedural, not sprites. Thanks.

#1
03/11/2007 (2:45 pm)
I do not believe that there are any primitive functions 'out of the box', at least not without some work and added C++ code.

The engine has the ability to draw primitives, but you'd have to create new objects in the engines C++ (pretty sure anyhow, haven't really looked too much to be honest, but there might be a simple 'quad' primitive already)
#2
03/11/2007 (11:48 pm)
That's a shame. I would think that any decently robust game making application would have these features; they're pretty much the bread and butter of 2D games. Regardless, thanks for replying.
#3
03/12/2007 (2:21 am)
T2dShapeVector object is what you're looking for. I don't think it is documented in TDN however. Here's a quick rundown though, from the C source for 1.1.3:

%myVectorShape.setPolyPrimitive();
%myVectorShape.setPolyCustom(, );
%myVectorShape.setFillColor();
%myVectorShape.setFillMode(true/false);
%myVectorShape.setLineColor();

So after creating a new t2dShapeVector() and adding it to your scene, you can create a quick n-sided polygon with the first call and it should show up unfilled using a white line.

The second function, setPolyCustom, lets you draw an arbitrary vector shape. The list of vertices is a single string, with x/y coords separated by spaces (e.g. "-1 -1 0 0 1 -1" is a triangle with points at -1,-1 and 0,0 and 1,-1). The values for coords need to be between -1 and 1 (but you can use the regular setSize to scale it to any size). The first parameter is the total number of vertices (coordinate pairs) in the string that follows. Not sure why it has this, other than validation reasons (which could be nice if you've got dozens of vertices I guess).

The shapes default to not-filled, but you can turn on color-fill with setFillMode(true); and the fill and line colors are set independently with one-string color values (e.g. "1 1 1 1" = white, no alpha). You can't fill with anything other than a solid color either.

That's about it. There's no way to manipulate vertices other than re-call setPolyCustom, in fact there's a bunch of simpler functions calls missing like getLineColor/getFillColor. I'm guessing this is a half-finished (or abandoned) feature.
#4
03/12/2007 (9:23 am)
T2dShapeVector is very cool. You can also look for the resource submitted by a community member that gives you a number of other primitives. You will need to recompile the engine to include that though.

I would also like to disagree on the point that vector graphics and primitive shapes are the bread and butter of 2d games. I can't even remember that last 2d game I saw that used them. I'm sure they're out there, I just haven't played them. Oh yeah, I remember now, it was the original Battlezone arcade game...

:)
#5
03/12/2007 (10:07 am)
@Ben:

Funny you mention Battlezone, I have one in my house 8). Yes classic arcades are "another" one of my (as my wife says) "too many hobbies". I just love dem games.

I have to agree vector graphics are not necessarily the "bread and butter of 2D games". Vector graphics in the original arcades were used because the processing power of the day didn't have enough power to rasterize vector graphics and the monitor resolution was too low so they created specialized vector monitors and some really inovative dedicated math engines to handle it. It allowed some pretty cool 3D stuff on low end hardware. The bulk of the '80s arcade games were 2D sprite/tile based. Oh ya and no collision/physics
engines

8)