Drawing a Line with T3D (debugDraw.cpp)
by Jacob S. · in Torque 3D Professional · 05/04/2010 (7:14 am) · 6 replies
debugDraw.cpp - Works after commenting out all the #ifdef TORQUE_DEBUG (in debugDraw.h) and uncommenting "#define TORQUE_BYTE_ALIGNMENT 4" & "#define TORQUE_FRAME_SIZE 16 << 20" in torqueConfig.h
ConsoleFunction(createDebugLine, void, 3, 3, "createDebugLine( %start, %end )") {
Point3F start;
dSscanf(argv[1], "%g %g %g", &start.x, &start.y, &start.z);
Point3F end;
dSscanf(argv[2], "%g %g %g", &end.x, &end.y, &end.z);
ColorI color;
color.red = 255;
color.green = 0;
color.blue = 0;
color.alpha = 255;
DebugDrawer::get()->drawLine( start, end, color );
DebugDrawer::get()->setLastTTL(U32_MAX);
Con::printf("I am being called Wewt!");
}
#2
Any chance we can see some tools like this in the next version? I only found one resource that showed how to get this class working to some extent. Still no way to clear the lines you have defined.
05/04/2010 (9:29 am)
Yes, it would be nice to be able to easily draw lines, primitives and maybe even text in the 3D environment. I noticed that the debugDraw class has a few other types that aren't exposed via script. It also seems that the rendering engine has changed- the _drawWireCube declaration differs from what was trying to be called (and is now commented out).Any chance we can see some tools like this in the next version? I only found one resource that showed how to get this class working to some extent. Still no way to clear the lines you have defined.
#3
add this
and these to debugDraw.cpp
If you read through the debugDraw.h they mention TSE... which was an early name for TGEA as far as I can tell. So it's natural a few things like _drawWireCube would have changed.
05/04/2010 (9:36 am)
Easy enough to add.add this
static void reset(); //Addedin the public section of debugDraw.h
and these to debugDraw.cpp
void DebugDrawer::reset() {
if (sgDebugDrawer) {
sgDebugDrawer = NULL;
} else {
DebugDrawer::init();
}
}
ConsoleFunction( clearDebugLine, void, 1, 1, "clearDebugLine()") {
DebugDrawer::reset();
}If you read through the debugDraw.h they mention TSE... which was an early name for TGEA as far as I can tell. So it's natural a few things like _drawWireCube would have changed.
#4
The correct way would be:
05/04/2010 (9:50 am)
@Jacob: be aware that You're not really deleting the old debug drawer, causing a memory leak every time you call reset.The correct way would be:
void DebugDrawer::reset() {
if (sgDebugDrawer) {
//DebugDrawer automatically clears sgDebugDrawer when deleted
sgDebugDrawer->deleteObject();
} else {
DebugDrawer::init();
}
}
ConsoleFunction( clearDebugLine, void, 1, 1, "clearDebugLine()") {
DebugDrawer::reset();
}
#5
05/04/2010 (9:57 am)
@Manoel - You can't actually delete sgDebugDrawer, if you do it causes Torque to crash instantly.
#6
05/04/2010 (11:21 am)
Based on the code that was already there for dieTime, I came up with this:void DebugDrawer::clear()
{
for(DebugPrim **walk = &mHead; *walk; )
{
DebugPrim *p = *walk;
*walk = p->next;
mPrimChunker.free(p);
}
}
Torque 3D Owner Jacob S.
ADMCMA
Although if someone has a decal/sprite toturial/info that would look loads better than the current primative line.