View Full Version : The Mouse
02-05-2003, 05:12 PM
I just started using the mouse in OpenGL, and there's one thing that stumps me: How can one tell if the cursor is going off the screen (so I can stop it)? I'm using gluPerspective. Should I not be? I just never was able to decipher glFrustrum.
02-05-2003, 06:33 PM
gluPerspective() essentially calls glFrustum() for you anyways, so it doesn't matter which one you want to use. With glFrustum, you can have some non-symmetric frustums, but usually that is not needed. You don't even need OpenGL for what you are saying. Just keep the mouse inside the boundries using procedures that the OS gives you. Say that the window starting point is (x,y) and the width is w and height is h. Then starting from the upper left and going counter-clockwise, the boundries are: (x,y), (x, y+h), (x+w, y+h), (x+h, y).
02-05-2003, 06:52 PM
That's the problem; I don't KNOW w and h. The cursor is a texture-mapped quad.
02-05-2003, 07:12 PM
w and h are the screen dimensions (ie 640x480 or 800x600).
w = width
h = height
02-05-2003, 07:49 PM
If your viewport takes up the whole window, then you have to know it. But if you are using teh quad like you set, then use glFrustum(...) to define your perspective projection. That way, you will know the boundaries of your view frustum. If you know the math, then you can apply it to find the width and the height. I think it is the farplane distance * tan(fovy) to get the width. Since the frustum is symmetric, you should have width = height.
This is where all the arguments are in the gluPerspective:
gluPerspective(fovy, aspect ratio, near plane distance, far plane distance)
again w = h = (far plane distance) * tan(fovy);
I'm not 100% sure about that formula though.
02-06-2003, 06:09 AM
Well it does depend on the z-position of the quad... I'm using a quad instead of the just drawing it directly so I can have part of the cursor be transparent.
02-06-2003, 07:54 AM
I figured it out. That formula was almost correct; you forgot to include the width of the far plane. I got it now.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.