
If (np.square(nx - circle.cx) + np.square(ny - circle.cy)) <= np.square(circle.r * (SCREEN_SIZE / 10)):Īlso, why is my window 300x300 when it should be 250x250? I don't set the window size anywhere but the above init function. Print("Circle center", circle.cx, circle.cy) Ny = float(y * SCREEN_SIZE / SCREEN_SIZE) Nx = float(x * SCREEN_SIZE / SCREEN_SIZE) This is my glutMotionFunc: def click(x, y): If we assume that this is a click on a PictureBox, the pixel coordinates are exactly the same as the coordinates of this control. I know that the glOrtho takes the left, right, bottom, top, near and far values, but when I try to convert to world space coordinates from mouse position(since I only need the x and y so I can calculate distance from the circle's origin) I end up with coordinates in the range 0.0 - 1.25, which makes no sense to me at all, because it should be 0.0 - 1.0. Here is the problem: you mention 'bitmap coordinates', and don't mention what to click on. I also set the initial window position to 100, 100, I don't know if that is relevant to the issue though.įor reference this is my init code: def init(): I have created the circle, but I cannot seem to be able to map my mouse coordinates to the world coordinates using glOrtho. > import pyautogui > pyautogui.
#Python convert mouse coordinates full#
So the full code to execute this is shown below.


And the second value is the y-coordinate of where the mouse cursor is. The first value is the x-coordinate of where the mouse cursor is. Hardware display coordinates Using hardware coordinates makes sense in the case of writing complex UIs meant to run on PC, such as editors, MMOs, tools, etc. I have been trying to learn OpenGL and my current goal is to move a circle on mouse drag. This function returns a tuple of the position of the mouse's cursor. Mouse and input coordinates About The reason for this small tutorial is to clear up many common mistakes about input coordinates, obtaining mouse position and screen resolution, etc. The None value can be passed for a coordinate to mean the.

EDIT: I changed the bottom left to -1,-1 and the top right to 1,1, and while I can draw objects within this range, I cannot map the mouse x,y to the world space. The moveTo() function will move the mouse cursor to the X and Y integer coordinates you pass it.
