How to get screen coordinates
by Dieter Eichert · in Torque X 2D · 05/24/2007 (9:16 am) · 5 replies
Hallo dear community.
how can i calculate the pixel/screen coordinates of an 2D sceneObject? I would be very pleased if someone can tell me that.
thanks,
dieter.
how can i calculate the pixel/screen coordinates of an 2D sceneObject? I would be very pleased if someone can tell me that.
thanks,
dieter.
About the author
#2
05/30/2007 (6:19 am)
Thank you!
#3
I noticed that the codes are for converting the torque x world coordinates to xna screen coordinates. How do we go about doing the reverse??
01/03/2008 (10:51 pm)
Hi.I noticed that the codes are for converting the torque x world coordinates to xna screen coordinates. How do we go about doing the reverse??
#4
I want to add that this was for 1.0.5.1, not the beta, since a lot of people seem to be using the beta.
01/04/2008 (1:09 pm)
www.garagegames.com/mg/forums/result.thread.php?qt=70161I want to add that this was for 1.0.5.1, not the beta, since a lot of people seem to be using the beta.
#5
I managed to figure it out myself by reversing the formula given by Buscaglia:
T2DSceneCamera camera = T2DSceneGraph.Instance.Camera as T2DSceneCamera;
Vector2 vect1 = new Vector2(GUICanvas.Instance.Size.X, GUICanvas.Instance.Size.Y);
Vector2 vect2 = screenPosition / vect1;
Vector2 vect3 = Vector2.Multiply(vect2, (camera.SceneMax - camera.SceneMin));
Vector2 vect4 = vect3 + camera.SceneMin;
return vect4;
So far it has given me accurate values. Hope this will help others who need it...
Thanks
01/07/2008 (11:13 pm)
Hi.I managed to figure it out myself by reversing the formula given by Buscaglia:
T2DSceneCamera camera = T2DSceneGraph.Instance.Camera as T2DSceneCamera;
Vector2 vect1 = new Vector2(GUICanvas.Instance.Size.X, GUICanvas.Instance.Size.Y);
Vector2 vect2 = screenPosition / vect1;
Vector2 vect3 = Vector2.Multiply(vect2, (camera.SceneMax - camera.SceneMin));
Vector2 vect4 = vect3 + camera.SceneMin;
return vect4;
So far it has given me accurate values. Hope this will help others who need it...
Thanks
Torque Owner Thomas Buscaglia
public Vector2 GetScreenCoordinates(Vector2 worldPosition) { T2DSceneCamera camera = T2DSceneGraph.Instance.Camera as T2DSceneCamera; return Vector2.Multiply((worldPosition - camera.SceneMin) / (camera.SceneMax - camera.SceneMin), new Vector2(GUICanvas.Instance.Size.X, GUICanvas.Instance.Size.Y)); }