PDA

View Full Version : Mouse move in OpenGL



Ehsan Nekooee
08-26-2009, 01:05 PM
Hi

How can I handle moving mouse in OpenGL program without having the mouse clicked?
When I move the mouse cursor to left I want the camera go left and when the cursor moved to right the camera go right.
I wrote a little function but I know It is not the possible solution. It only works when I click the mouse button.

Here is my code:


void mousefunc(int state, int x, int y, int z)
{
if ( y > 400 ) cam.MoveRight(2);
glutPostRedisplay();
}


P.S: I code in Visual c++ and in console environment.

Ehsan Nekooee
08-26-2009, 02:12 PM
OK, I have some Improvements. I know that I have to use glutPassiveMotionFunc.

I want move the mouse left the cam goes left and so on ...
I have an interesting theory, I think it have to work but it doesn't.



void pmotion ( int x , int y )
{
int pre_x = 0;
//pre_x = 0;
if ( x > pre_x )
{
cam.MoveRight(1);
pre_x = x;
}
else if ( x < pre_x )
{
cam.MoveRight(-1);
pre_x = x;
}
}


each time x value goes to pre_x it meant to mean that everywhere the cursor goes is assumed to be the orientation, and then It compares the condition to decide the cam to ge to the left or right. but It always moves along one direction actually to the left.(It's because the pre_x is valued 0, but I think It just have to be set the pre_x once).

ZbuffeR
08-27-2009, 05:16 AM
You defined pre_x as local variable. So each time pmotion is executed, pre_x is set back to 0.
Try with a global variable.

Ehsan Nekooee
08-27-2009, 09:52 AM
It works now. There are some issues left but I think I can Handle them. It's about defining limitation for the cursor in the window.

Thanx anyway