Game Development Community

Solution for 3d Coords to screen position.

by Cinder Games · in Torque Game Engine · 11/24/2005 (7:56 pm) · 1 replies

Here's a consoleMethod for those who want to turn 3d coords to screen coords.
I've had it lying around for awhile, figured i'd post it.

at the bottom of gameTSCtrl.cc add:


//------------------------------------------------------------------------------
ConsoleMethod(GuiTSCtrl, Project, const char*, 3, 3, "dglPointToScreen(x y z)" )
{

   char *returnBuffer = Con::getReturnBuffer(256);
	
   Point3F ObjPoint;
   Point3F pos;

   dSscanf(argv[2],"%f %f %f",&ObjPoint.x,&ObjPoint.y,&ObjPoint.z);

	if (object->project(ObjPoint, &pos)){

     dSprintf(returnBuffer,256,"%f %f %f",pos.x,pos.y,pos.z);
	 return returnBuffer;

	}
    else 
      return "failed";
}

//------------------------------------------------------------------------------


to use it in script...

%xyz=%target.getpositiont();
	%loc = %mycurrentGUI.Project(%loc);

easy as pie. mycurrentgui needs to be your currently set GUI. I believe playgui is the default gui.