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.
I have been trying to learn OpenGL and my current goal is to move a circle on mouse drag. I have created the circle, but I cannot seem to be able to map my mouse coordinates to the world coordinates using glOrtho. I also set the initial window position to 100, 100, I don't know if that is relevant to the issue though.
For reference this is my init code:
def init(): # select clearing color glClearColor(0.0, 0.0, 0.0, 0.0) # initialize viewing values glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0)
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.
This is my glutMotionFunc:
def click(x, y): global current_circle nx = float(x * SCREEN_SIZE / SCREEN_SIZE) ny = float(y * SCREEN_SIZE / SCREEN_SIZE) print("Mouse click", nx, ny) for circle in circles: print("Circle center", circle.cx, circle.cy) if (np.square(nx - circle.cx) + np.square(ny - circle.cy)) <= np.square(circle.r * (SCREEN_SIZE / 10)): current_circle = circle current_circle.set_position(nx, ny) glutPostRedisplay()
Also, why is my window 300x300 when it should be 250x250? I don't set the window size anywhere but the above init function.