PDA

View Full Version : mouse function



Raiden
04-04-2005, 04:49 AM
Greetings,

In my program, i've coded the mouse function, but it works after a while. I've coded that the left mouse button zoom in the screen, but it wait the redisplay to zoom in. Thats not what i want to do, i want that as soon as the user click the left button it zooms in.

In the idle function i read a matrix on a socket but need the socket to be non-blocking, so i loop in there until i get a valid matrix on the socket. but it waits until i get a valid matrix to zoom in.

so what do i have to do to make sure it performs the mouse function as soon as the user clicks the mouse button?

T101
04-04-2005, 05:08 AM
I've coded that the left mouse button zoom in the screen, but it wait the redisplay to zoom in. Thats not what i want to do, i want that as soon as the user click the left button it zooms in.
Either you're not triggering a redisplay when the mouse button is clicked, or you're waiting for the mouse button release and want to start zooming as soon as the button is pressed.
I can't say anything more, since your description is not very clear. Are you using GLUT? Windows? X-Windows?



In the idle function i read a matrix on a socket but need the socket to be non-blocking, so i loop in there until i get a valid matrix on the socket. but it waits until i get a valid matrix to zoom in.
I have no idea what socket communications have to do with mouse input. But if you want communications to be asynchronous with the user interface and possibly other logic, you could always use a separate thread, that can block to its heart's delight.

Raiden
04-04-2005, 05:13 AM
i am using Glut.

i am not waiting the button to be released.

to make things clearer:
in my idle function:
i loop until the matrix i receive on a socket is valid. so it seems it blocks there.

in this loop is there a GL call i can use to check if there was a mouse or a keyboard entry?

RigidBody
04-04-2005, 05:45 AM
i don't think so.

but you could set flags (global variables) in your mouse/keyboard functions and check them in your idle func.

Raiden
04-04-2005, 06:01 AM
Originally posted by RigidBody:
i don't think so.

but you could set flags (global variables) in your mouse/keyboard functions and check them in your idle func.i've tried that, doesn't seem to work :(

RigidBody
04-04-2005, 07:55 AM
where do you clear the flag?

for example, you should set a flag to show that mouse button one is pressed in the button func and clear the flag in your idle func. if you clear the flag in a separate button release func, it may be unnoticed by the idle func.

jide
04-04-2005, 07:57 AM
maybe like that:

have a matrix M (representing the default view).
make your view regarding M, always.
look periodically (with glutTimerFunc) if you got a new matrix threw your socket, if so affect it to M.
idle function can do the calculations, essentially for the zoom and the animation.

Your socket must be non-blocking I guess because glut doesn't know parallelism.

Hope this helps.

Raiden
04-04-2005, 09:35 AM
Thanks, the glutTimerFunc is really helpful! :D