Game Development Community

Primitives (quads, elipse, line, etc)

by Alex Parker · in Torque Game Builder · 04/03/2005 (9:52 pm) · 8 replies

I assume that somewhere in the code is a place for creating vertex lists that can be used to construct primitives, because you can set debug mode to display the collision poly's right? Is there any way to access this via script? If not, where should I look at the engine source to gain access to these functions, if possible?

Cheers

#1
04/04/2005 (3:25 am)
I found these functions in dgl.h in the dgl folder:
/// draws a line from x1,y1 to x2,y2 in the specified color
void dglDrawLine(S32 x1, S32 y1, S32 x2, S32 y2, const ColorI &color);
/// draws a line from startPt to endPt in specified color
void dglDrawLine(const Point2I &startPt, const Point2I &endPt, const ColorI &color);
/// draws a wireframe rectangle from upperL to lowerR in specified color
void dglDrawRect(const Point2I &upperL, const Point2I &lowerR, const ColorI &color);
/// draws a wireframe rectangle in "rect" in specified color
void dglDrawRect(const RectI &rect, const ColorI &color);
/// draws an UNTEXTURED filled rectangle from upperL to lowerR in specified color
void dglDrawRectFill(const Point2I &upperL, const Point2I &lowerR, const ColorI &color);
/// draws an UNTEXTURED filled rectangle in "rect" in specified color
void dglDrawRectFill(const RectI &rect, const ColorI &color);
/// draws a square, with center point "screenPoint", width of "width" on an angle of "spinAngle" in 2d
void dglDraw2DSquare( const Point2F &screenPoint, F32 width, F32 spinAngle );
/// draws a square, with center point "position", width of "width" on an angle of "spinAngle" in 3d
void dglDrawBillboard( const Point3F &position, F32 width, F32 spinAngle );

Are these accessible from script? Where would I go to enable scripting of these functions? Or am I barking up the wrong tree here?

I'll continue to chip away at this, since primitives are extremely useful. If I crack it, I'll let you all know.
#2
04/04/2005 (3:48 am)
Oh yeah, would be very useful. Just the 2D lines would be great, for debugging information and such.

Hope you find a way to use them.
#3
04/04/2005 (5:42 am)
You should be able to use the consoleFunction() macro to expose these to script.

[url=http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2982][/url]
#4
04/04/2005 (5:47 am)
In the file dgl.cc at the bottom of the file, try adding
ConsoleFunction(dglDrawLine,void,5,5,"(S32 x1, S32 y1, S32 x2, S32 y2, const ColorI &color)")
{
    if(argc == 5)
    {
        <do something?>
    }
    else
    {
        Con::printf("dglDrawLine() - Invalid number of parameters!\n");    }
}


So basically, the bit should parse the arguments and call the dglDrawLine function, but I'm not quite sure how to do this.
#5
04/04/2005 (11:17 am)
There would be no point in doing this as the line wouldn't be persistent. These calls are for objects that want to draw to the framebuffer, they don't create persistent primitives.

We'll be creating T2D objects to do just that.

- Melv.
#6
04/04/2005 (12:25 pm)
I figured as much, around about the time when I'd written the function declaration, compiled it and saw that nothing happened :) oh well.

How soon before this functionality is added? If its going to take a while, I might as well impliment something to get me by. Probably involving a new datablock of some kind.
#7
04/05/2005 (2:33 am)
It will take a while before we get to it but I'd like to "fit it in" between some bigger features. It won't be something at the end of the project, more near the beginning.

I will try to fit this in literally as soon as possible. Oh hell, I'll try to get something together after the next update.

- Melv.
#8
04/05/2005 (3:00 am)
Or you could wait longer and enjoy laughing at my feeble hacked attempts :)