Game Development Community

Get center of screen

by Justin Mosiman · in Torque Game Engine · 06/29/2006 (1:37 pm) · 4 replies

Hello,

How do you get the x,y, and z coordinates of the center of the screen? I tried
Point3F temp = getCameraPosition(); // Returns the x,y,z coordinates of the camera position
mObjBox.getCenter(&temp); // from sceneObject.h, of type Box3F
But that returns a value of 0,0,0 no matter your position/transform. I want to be able to get the center no matter what the position/pitch/yaw is. Is mObjBox the right thing to use?

Thanks,
Justin

#1
06/29/2006 (1:46 pm)
What you are doing with mObjBox is probably setting temp to the center of mObjBox, where 0 is probably the correct value. Throw out that line and see if temp has what you want with just getCameraPosition().
#2
06/29/2006 (1:55 pm)
GetCameraPosition() has the correct values for the position, but I'm trying to figure out the center screen position. So unless the camera is looking straight down, the center screen position would not be the same as the camera position.

Thanks for your help
#3
06/29/2006 (2:56 pm)
Alright, i'll part with some code i wrote.

This works for XYZ - > 2d coords, but if you pay attention, you can probably get it to do 2d->3d by changing some variables and change "project" to "unproject"

//------------------------------------------------------------------------------
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";
}


here's how you'd use this code as provided


add this into your gameTSCtrl.cc file.

to use........ playergui.project("x y z");
i'd return the 2d screen position.

As i said, you can probably figure out how to change it as needed.
#4
06/30/2006 (9:27 am)
Thank you Ramen-sama, the code that you pasted works great. It wasn't exactly what I was looking for, but I should be able to modify it to fit my needs.

Thanks again,
Justin