Game Development Community

Rendering Lines in the editor

by Mark Miley · in Torque Game Engine · 05/18/2004 (6:21 am) · 5 replies

I'm trying to setup an AI node path view for the editor. I figured out how to draw a line using %editor.rendLine() in the editorrender.cs for my path nodes, but when I do this everything slows to a crawl. My lines show up and connect my path nodes and it looks pretty neat, but like I said I can barely move under the strain of all the lines. I'm not sure what I'm doing wrong exactly to cause such a lag.

#1
05/18/2004 (10:43 am)
That method of drawing lines is just very slow. :)

You should really write your own rendering code in C++; it will be dramatically faster especially if you use vertex arrays.
#2
05/19/2004 (12:17 am)
Thanks Ben...guess I'll add that to my to-do list. Right up there with my relative particles. :)
#3
05/19/2004 (4:58 am)
Rendering lines using GL_LINE or GL_LINE_LOOP is okay, it does cause a crawl if there's too much to be drawn. I'd also suggest looking into some sort of distance culling routine. Either try something like the quadtree approach (you can find that in any of Melv May's replicators) or do something simple that just tosses out lines based on absolute distance from camera. Do a simple check for which point of the line is closer and then compare to the camera position...

pseudo code:
Point3F camPos = getCameraPos();
   F32 nearDist = gClientSceneGraph.getVisibleDistance();

   nearDist = (lineStart - camPos).len();
   nearDist = getMin(nearDist, (lineEnd - camPos).len());

   if (nearDist < SOME_MINIMUM_DISTANCE)
      renderLine();

- Brett
#4
05/19/2004 (8:53 am)
Brett,

The reason it's so slow is because he's calling a script function for each line to be drawn. Script is fast, but it's not fast enough for rendering code.

I'm sure even a naive line rendering implementation done in C++ would run acceptably. If you did something like have the nodes draw their connecting lines and then cull nodes that would work pretty well too.
#5
05/19/2004 (10:01 am)
I'm still a little new to graphics programming, so I have another question. I'm using the renderline function from the editTSCtrl.cc which is a console method. So if I basically did the same gl commands, but in a new class definition that did the basically the same thing as my script it would be faster? Is that the way to do it?