View Full Version : Synthetic vision: Using mouse input

02-22-2011, 12:21 AM
I am doing a project on synthetic vision system in windows..In which 3d map of the room will be already created using the opengl. A remote controlled car is actually kept in the room. And as the car moves ahead, the map should also be moved according to the car movement. For detecting the movement of the car i am using a bluetooth mouse attatched to the car. So my problem is now that as i move the mouse, the "virtual camera" should move accordingly in the opengl. For that i am using glpassivemotion() function. But the problem is that on the screen the mouse stops at the bounds and further motion outside the bound is not detected as the mouse pointer gets stuck at the end( last pixel) of the screen. How can i solve this problem. Is there any other alternative for mouse?

carsten neumann
02-22-2011, 02:02 PM
You can use glutWarpPointer to move the cursor to the center (provided you have a glut implementation that has that function, freeglut does for example).
Also see this thread (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=291557).

02-22-2011, 10:02 PM
you are very lucky and i have my controls file open
this code should give you enuf info
note that the mouse never leaves the center with this cool trick

/* MOUSE */
glutWarpPointer(mid_x, mid_y);


glutPassiveMotionFunc(mouseMove); //check for mouse movement

void mouseMove(int x, int y) {

// If our cursor is still in the middle, we never moved... so don't update the screen
if( (x == mid_x) && (y == mid_y) ) return;

// Set the mouse position to the middle of our window
glutWarpPointer(mid_x, mid_y);

float angle_y = 0.0f;
float angle_x = 0.0f;

/* LEFT & RIGHT */
angle_y = (float)(mid_x - x) / MOUSE_SPEED;
angle.y = angle_y;

/* UP & DOWN */
angle_x = (float)(mid_y - y) / MOUSE_SPEED * 2;
angle.x = angle_x;

mView.z -= angle_x * 90;

//if ((mView.y - mPos.y) > n) mView.y = mPos.y + n;
//if ((mView.y - mPos.y) < -n) mView.y = mPos.y - n;

//debug = -angle_y;


mouse_x = x;
mouse_y = y;