Mouse Position Problem
by Viktor Rumanuk · in Torque X 2D · 08/12/2008 (10:18 pm) · 2 replies
I am snapping an object to the mouse position and find that as I move my mouse lower down the screen my object's Y position becomes off. Everything is fine at the top of the screen and the X position is always correct. The object's Y position gradually moves upwards away from the mouse pointer as I move it down. I'm pretty sure that I'm converting between screen and world coordinates correctly, but that could be the problem. Any suggestions?
Thanks, Viktor
Thanks, Viktor
#2
Thanks
By the way, great work on the Builder, will definitely make things a lot easier if I ever decide to move into 3D.
08/13/2008 (9:57 am)
Here is my conversion code, stolen off of some other thread. public Vector2 GetWorldCoordinates(Vector2 screenPosition)
{
T2DSceneCamera camera = TorqueObjectDatabase.Instance.FindObject<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;
}All I'm doing is getting the mouse position every tick, converting it, and setting my object's position.Thanks
By the way, great work on the Builder, will definitely make things a lot easier if I ever decide to move into 3D.
Associate John Kanalakis
EnvyGames
John K.