PDA

View Full Version : Mouse help



marybobary88
12-07-2016, 03:55 PM
Hello. I am making graphics for a connect 4 game. And I need to implement mouse functions, one that is called when the user simply moves the mouse, one when the user drags the mouse, and one when a button is pressed or released.

I need it such that the token ( circle of either color red or blue) follows the mouse until the user presses on the perspective column. I am new to openGl, so I am not entirely sure where to begin.

Dark Photon
12-07-2016, 05:15 PM
Right now your question doesn't appear to have anything to do with OpenGL, except that you mentioned "OpenGL".

Since you're just starting out, I'd suggest you just use GLUT as it'll make getting started easier. It's also cross-platform, and supports mouse button and motion callbacks.

Here's someone's standalone GLUT test program that compiles right out-of-the-box and demonstrates how to use mouse button and motion callbacks alongside OpenGL drawing:

* Sketch Program Issues (https://www.opengl.org/discussion_boards/showthread.php/185002-Sketch-Program-Issues)

marybobary88
12-08-2016, 09:08 AM
Hi, I am trying to figure out how to have a circle token of red or black color for a connect 4 game to be moving with the mouse. When the user presses down and the token is dropped, then it changed right back to the mouse, you never have to pick up the token. I am not sure how I would even start going about doing this?

OceanJeff40
12-14-2016, 09:05 AM
Welcome to the OpenGL world.... I'm a newbie myself.

What have you got so far?

I would start with getting used to mouse input. Draw your object on the screen and apply different mouse input to it and see what happens, then fix it to do what you want.

I know one technique is to save the previous state of the mouse (with each frame), and then calculate the difference in the mouse's position from one frame to the next, this would be your mouse delta (per frame). Then apply your delta, to your object, and it will move with the mouse. If you want to adjust your delta (per frame or whenever....) multiply by a "sensitivity" factor, which could speed up or slow down your mouse movement.

Hope this helps,

Jeff :)