Pointers passed from script?
by Phil Mundy · in Torque Game Engine · 08/13/2006 (6:30 am) · 3 replies
I want to use the GuiTSControl method...
"bool unproject(const Point3F &pt, Point3F *dest); // returns world space point for X, Y and Z"
...by calling it from the script.
Now how do I go about passing in Point3F pointers and addresses from the script which has neither pointers, addresses or Point3Fs?
I think for the "Point3F &" 's you would just type each word of the variable separated by commas like I have done in a .resize(Point2I&, Point2I&) method where I can type
blah.resize( %posx , %posy , %extx , %exty );
or
blah.resize( 102 , 20 , 50 , 50 );
Any suggestions?
By the way, I need this to be able to place a GUI at a screen coord relative to a 3D world coord.
"bool unproject(const Point3F &pt, Point3F *dest); // returns world space point for X, Y and Z"
...by calling it from the script.
Now how do I go about passing in Point3F pointers and addresses from the script which has neither pointers, addresses or Point3Fs?
I think for the "Point3F &" 's you would just type each word of the variable separated by commas like I have done in a .resize(Point2I&, Point2I&) method where I can type
blah.resize( %posx , %posy , %extx , %exty );
or
blah.resize( 102 , 20 , 50 , 50 );
Any suggestions?
By the way, I need this to be able to place a GUI at a screen coord relative to a 3D world coord.
#2
08/13/2006 (7:15 am)
Thats brilliant! ConsoleMethods are now my second favourite thing in the world, behind Gary Preston! :D
#3
08/13/2006 (7:44 am)
In case anyone wants to know, this was the final code I used.ConsoleMethod( GuiTSCtrl, unproject, const char *, 3, 3, "(point x / y / z)")
{
Point3F pt, dest;
dSscanf(argv[2],"%g %g %g", &pt.x,&pt.y,&pt.z);
char *returnBuffer = Con::getReturnBuffer(256);
if (object->unproject(pt, &dest))
dSprintf(returnBuffer,256,"%g %g %g", dest.x,dest.y,dest.z);
else
return ("0 0 0"); // or some more useful default
return returnBuffer;
}
Torque Owner Gary Preston
%dest = %someobj.unproject("x y z");The consoleMethod should return a char * which will really be the three coords x,y,z as a single string space seperated. EG:
ConsoleMethod( SceneObject, unproject, const char *, 3, 3, "(point x / y / z)") { Point3F pt, dest; dSscanf(argv[2],"%g %g %g", &pt.x,&pt.y,&pt.z); char *returnBuffer = Con::getReturnBuffer(256); if (object->unproject(pt, &dest)) dSprintf(returnBuffer,256,"%g %g %g", pos.x,pos.y,pos.z); else return ("0 0 0"); // or some more useful default return returnBuffer; }I've not tested the above, but it should point you in the right direction.