Drawing Nodes on the Terrain
by Arjan Gelderblom · in Torque Game Engine · 03/20/2007 (4:42 am) · 6 replies
Hello all,
I've been working/playing around with TGE for a few months now and I'm currently trying to implement a A* algorithm for pathfinding in it.
I found this resource which is a really great starting point for me:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10603
But for easier debugging I would like to have the pathNodes 'created' by this code displayed on screen so that I can see where they are and if the code works like I want it to. (Which would become really handy when I change the code :P).
I would for starters have something like Guy Allard shows in his post in this thread:
http://www.garagegames.com/mg/forums/result.thread.php?qt=55939
First I started with OpenGL code but I understood after much searching the forums that that only draws on the first frame, which is pretty hard to see ;) and that it was better to use fxRenderObject. But when trying to use that I can't seem to get the object to be rendered!
The code I'm using:
Summary what I've done so far:
I've merged the RTS starter Kit into TGE 1.5. Then I modified the resource function PathFinder::Initialize() so that it won't check for previously created NavMap but always creates a new NavMap. And was trying to render the pathNodes using the code above inside the PathFinder::createMap() function of the resource. When that failed I tried to render a object on the 0.00 0.00 and the height of that position, but even that failed!
So my question is how to render those nodes so I can see them inside my game?!
Thanks for your help in advance,
Arjan
I've been working/playing around with TGE for a few months now and I'm currently trying to implement a A* algorithm for pathfinding in it.
I found this resource which is a really great starting point for me:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10603
But for easier debugging I would like to have the pathNodes 'created' by this code displayed on screen so that I can see where they are and if the code works like I want it to. (Which would become really handy when I change the code :P).
I would for starters have something like Guy Allard shows in his post in this thread:
http://www.garagegames.com/mg/forums/result.thread.php?qt=55939
First I started with OpenGL code but I understood after much searching the forums that that only draws on the first frame, which is pretty hard to see ;) and that it was better to use fxRenderObject. But when trying to use that I can't seem to get the object to be rendered!
The code I'm using:
F32 renderHeight; terrain->getHeight(Point2F(0.00, 0.00), &renderHeight); Point3F renderLoc = Point3F(0.00, 0.00, renderHeight); fxRenderObject *myPathNode = new fxRenderObject(); myPathNode->setPosition(renderLoc); myPathNode->registerObject;This compiles OK (VS C++ 2005 Express Ed.) but when I run it it won't show up, so I probably forgot something, but what? :P
Summary what I've done so far:
I've merged the RTS starter Kit into TGE 1.5. Then I modified the resource function PathFinder::Initialize() so that it won't check for previously created NavMap but always creates a new NavMap. And was trying to render the pathNodes using the code above inside the PathFinder::createMap() function of the resource. When that failed I tried to render a object on the 0.00 0.00 and the height of that position, but even that failed!
So my question is how to render those nodes so I can see them inside my game?!
Thanks for your help in advance,
Arjan
About the author
#2
If it were me, I'd just render staticShapes in the positions you provide. Might be a lot simpler, and last time I remember working on something similar it worked for me.
Thanks for your fast reply, but if I read correctly staticShape can't be created in C++ files only in the scripts. What I found to create a staticShape is this (from The Game Programmers Guide To Torque):
Thanks in advance,
Arjan
03/20/2007 (7:53 am)
@Michael Perry:If it were me, I'd just render staticShapes in the positions you provide. Might be a lot simpler, and last time I remember working on something similar it worked for me.
Thanks for your fast reply, but if I read correctly staticShape can't be created in C++ files only in the scripts. What I found to create a staticShape is this (from The Game Programmers Guide To Torque):
datablock StaticShapeData (FadeEgg)
{
category = "LessonShapes";
shapeFile = "~/data/Shapes/Lessons/GeneralLessonShapes/egg.dts";
};
%theEgg = new StaticShape {
datablock = FadeEgg;
};But this is TorqueScript... And i want it to do in C++, is it possible with StaticShape and did I just miss something? Or should I look for another solution to my problem?!Thanks in advance,
Arjan
#3
The tricky part is getting the datablock from C++. Your code might look similar to this:
Script version of staticShape creation:
C++ Version of same code:
*EDIT*-This is untested code, based on my working with creating a projectile from C++, and discussion with Zepp. I haven't tried creating a staticShape from C++, but it should be a lot easier than a projectile =)
03/20/2007 (8:14 am)
Anything can be created in C++, you just have to include it in your source file. In other words, StaticShapeData was coded in C++ first, and exposed to script via the console.The tricky part is getting the datablock from C++. Your code might look similar to this:
Script version of staticShape creation:
datablock StaticShapeData (nodeDatablock)
{
category = "AI";
shapeFile = "~/data/Shapes/misc/quare.dts";
};
%theNode= new StaticShape {
datablock = nodeDatablock;
};C++ Version of same code:
F32 renderHeight;
terrain->getHeight(Point2F(0.00, 0.00), &renderHeight);
Point3F renderLoc = Point3F(0.00, 0.00, renderHeight);
StaticShapeData* nodeData = new StaticShapeData();
nodeData = dynamic_cast<StaticShapeData*>(Sim::findObject("FadeEgg"));
SimObjectPtr<StaticShape> node = new StaticShape();
node ->setDataBlock(nodeData );
node->setPosition(renderLoc);
node->registerObject();*EDIT*-This is untested code, based on my working with creating a projectile from C++, and discussion with Zepp. I haven't tried creating a staticShape from C++, but it should be a lot easier than a projectile =)
#4
Thanks for another fast reaction! This code compiles but still won't show, but I will look into that myself :P! Thanks again, when I need more help with this I'll post it!
Grtz,
Arjan
03/20/2007 (9:04 am)
@Michael PerryThanks for another fast reaction! This code compiles but still won't show, but I will look into that myself :P! Thanks again, when I need more help with this I'll post it!
Grtz,
Arjan
#5
What does it do exactly? As far as I know it cast a TorqueScript Pointer into a C++ pointer... but the nodeData isn't generated in the TorqueScript, is it?
Thanks for any help in advance!
Grtz,
Arjan
03/21/2007 (5:11 am)
I have another question about this line of code, from the code of Michael Perry:nodeData = dynamic_cast<StaticShapeData*>(Sim::findObject("nodeData"));What does it do exactly? As far as I know it cast a TorqueScript Pointer into a C++ pointer... but the nodeData isn't generated in the TorqueScript, is it?
Thanks for any help in advance!
Grtz,
Arjan
#6
Sim::findObject returns a SimObject, and this code converts it to a StaticShapeData object using dynamic_cast
03/21/2007 (5:30 am)
Actually, it is. You can't create a StaticShape in script without first making a datablock, right? The same rule applies in engine creation of an object. "nodeData" is a datablock declared in script, and my code is assumed to have been called after the datablock has been loaded.Sim::findObject returns a SimObject, and this code converts it to a StaticShapeData object using dynamic_cast
Employee Michael Perry
ZombieShortbus