This topic is now archived and is closed to further replies.


quake style viewing with glut and mouse??

Recommended Posts

I want to achieve quake-like viewing in my game using the mouse. In other words, move mouse left to turn left, up to look up... Im currently using the following function as my glutPassiveMotionFunc callback function: void myMouseMotion(int x,int y) { static int xlast=-1,ylast=-1; int dx,dy; dx = x - xlast; dy = y - ylast; if (dx < 0) dx = -1; else if (dx > 0) dx = 1; if (dy < 0) dy = -1; else if (dy > 0) dy = 1; if (dy == 1) cam.pitch(.1); if (dy == -1) cam.pitch(-.1); if (dx == 1) cam.yaw(-.1); if (dx == -1) cam.yaw(.1); if (dx != 0 && dy != 0) glutWarpPointer(100,100); xlast = x; ylast = y; } the warpPointer call is especially dumb and I want a better solution. warpPointer is there because if I dont set the pointer back to approximately the middle of my opengl window, turning too much in any direction causes the curser to leave the window completely. I dont want it to be Windows specific, and if there is a way to do this in glut, it would be nice. Also, this method is kind of slow and my crappy computer makes any motion really choppy. Any suggestions are appreciated! thanks! ----- It''''s not my fault I''''m the biggest and the strongest; I don''''t even exercise!

Share this post

Link to post
Share on other sites
Usually, you use some kind of function to move the mouse to the middle of the screen (like you did), or you poll relative coordinates. The latter is not necessary, and a single pointer-move can't seriously slow down your app!

Here's some code of how I do it (with simple mouse filtering):

/* Init */
odx = ndx = dx = centerX;
ody = ndy = dy = centerY;

/* Poll */

ndx = mx - centerX;
ndy = my - centerY;
setPointer(centerX, centerY);
dx = 0.5 * (odx + ndx);
dy = 0.5 * (ody + ndy);
odx = ndx;
ody = ndy;

cam.pitch(dy * ysense);
cam.yaw(dx * xsense);

(dx, dy) is now the average of the last and current mouse deltas. It will prevent some jagging, you could try to average even more POINTS.
ysense controls the vertical mouse sensitivity, negate to inverse mouse. xsense is the horizontal sens.

EDIT: Wrote pixels instead of points, silly me... Also forgot the cam-transform!

[edited by - coelurus on November 2, 2002 10:27:02 AM]

[edited by - coelurus on November 2, 2002 10:29:31 AM]

Share this post

Link to post
Share on other sites