Game Development Community

Point To Screen, Just about got it! But... WTF

by Cinder Games · in Torque Game Engine · 07/25/2005 (8:58 am) · 5 replies

Here's a console method i wrote. I can feed it some numbers.. but it returns them right back to me.
anyclue what i'm doing wrong?
==>dgl(1468.getposition());
printing out
Loc :-6.24 -6.08 -0.14993
XY :-6.240000 -6.080000 0.149930

//------------------------------------------------------------------------------
ConsoleFunction(dglPointToScreen, const char*, 2, 2, "dglPointToScreen(x y z)" )
{

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

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

	if (dglPointToScreen(ObjPoint, pos)){

     dSprintf(returnBuffer,256,"%f %f %f",pos.x,pos.y,pos.z);
	 Con::printf("printing out");
	 return returnBuffer;

	}
    else 
      return "failed";
}

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


www.garagegames.com/mg/forums/result.thread.php?qt=17301
i seem to be having the same issue as this person. Perhaps someon can clear this up?

#1
07/25/2005 (10:40 am)
I believe the problem with dglPointToScreen is that it uses the current opengl projection and modelview matrices, which I think are being cleared between renders. IIRC a "blank" opengl projection matrix has a positive x, positive y, and negative z axis; which would explain the results you're seeing.

Instead, what I believe you're going to need is the "project" function of your GameTSCtrl. If you're working off of the starter.fps (for example), you should have a GameTSCtrl instance called "PlayGui". This would be defined in "starter.fps/client/ui/playGui.gui". PlayGui is an instance of GameTSCtrl which is derived from GuiTSCtrl which has a "project" function which should do what you need.

GuiTSCtrl::project is defined in engine/gui/guiTSControl.cc. You'll see that it uses its own stored version of the projection and modelview matrices. I believe this will do what you need it to, however it is not available to script. I suggest adding a ConsoleMethod to the GuiTSCtrl class to expose this function to script.

(edit: minor typos)
#2
07/25/2005 (12:28 pm)
Scott,

Good call.

You might be able to get similar functionality by just casting a ray using the forward vector of the relevant object...
#3
07/25/2005 (6:27 pm)
I played around with project a little bit as well during this. I'll try adding a method and post back here with it :)
#4
07/25/2005 (7:50 pm)
This code works well.... CEPT for if i look up and down or down or basically not strait on

//------------------------------------------------------------------------------
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);
	 Con::printf("printing out");
	 return returnBuffer;

	}
    else 
      return "failed";
}

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

here's how i'm calling it

[code]
function ProjectIt(%loc){
%temp = overlay.Project(%loc);
error("Loc :"@%loc);
error("XY :"@%temp);

%x = getword(%temp, 0);
%y = getword(%temp, 1);


Pointer.position=%x SPC %y;
schedule(5,0,ProjectIt,$temp.getposition());
}
[\code]

img327.imageshack.us/img327/218/torquedemo20050725214905402nq.jpg
#5
07/25/2005 (7:59 pm)
FIXED ok it was my dumb fault :)

function ProjectIt(%loc){
	%temp = overlay.Project(%loc);
	//error("Loc :"@%loc);
	error("XY :"@%temp);

	%x = mfloor(getword(%temp, 0));
	%y = mfloor(getword(%temp, 1));


Pointer.position=%x SPC %y;
echo(Pointer.position);

schedule(5,0,ProjectIt,1469.getposition());
}



you must round them numbers down! doing that and it works perfect!