From: Tim Pickering <tdp198@so...> - 2001-05-06 17:56:51
I've been writing a 3d world in Linux recently as a univeristy project,
and have just ported to windows. I have never been able to look around with
the mouse and move at the same time in windows. Not only that, but the when
the mouse is moved in windows, the screen is updated only when the
mousebutton is released.
How do I resolve this issue?
I know this is possible because I have seen it done in Nate Millers
terrianR4 demo, but Nate's code seems no different to mine when looking at
tdemo source code - glutPostRedisplays all in the same place..
Source Code Below......
void keyboard(unsigned char key, int x, int y)
double strafe_temp =0;
void mouse(int btn, int state, int x, int y)
if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN)// If the left mouse is
oldmouse.x=x; //Store the mouse position in oldmouse
glutSetCursor(GLUT_CURSOR_NONE); // Hide the cursor
glutWarpPointer(window.x/2,window.y/2); //Return to the cursor to the
//Inform MouseMotion that the left button is depressed for moving.
if(btn==GLUT_LEFT_BUTTON && state == GLUT_UP) //If the left button has
mousebutton=0; //No longer move around
glutSetCursor(GLUT_CURSOR_INHERIT); // Reshow the cursor
glutWarpPointer(oldmouse.x,oldmouse.y); //Return to center
if(btn==GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)
void mousemotion(int x, int y)
if (mousebutton==1) //If left button is depressed,
//Move the mouse back to the centre,
//Convert the difference into a up/down rotation
camera.theta -=(y-window.y/2) * (DegRad / 2);
//Convert the difference into a left/right rotation
camera.thi -=(x-window.x/2) * (DegRad / 2);
//Stops going above Vertical
if (camera.thi > pi ) camera.thi -=2*pi;
if (camera.thi <= -pi ) camera.thi +=2*pi;
//Stops going below Vertical
if (camera.theta > pi/2.1) camera.theta =pi/2.1;
if (camera.theta <= -pi/2.1) camera.theta =-pi/2.1;
// Inform GLUT that the a refresh is needed.