So originally I had in a function that handled rotation:
void rotateCamera(int x, int y) {
mouseDeltaX = mouseDeltaX - x; //Get the change.
mouseDeltaY = mouseDeltaY - y;
rotx = (float)mouseDeltaX; //Assign it to a global variable value that would actually rotate everything.
roty = (float)mouseDeltaY;
mouseDeltaX = x; //Change mouseDeltaX and mouseDeltaY to the current x
mouseDeltaY = y;
}
It was passed to the glutPassiveMotionFunc(rotateCamera). My game is being constantly updated and near the top of the display function I would have:
And to make sure everything wasn't being constant rotated I would use a function I passed to glutIdleFunc:
void isIdle() {
rotx = 0;
roty = 0;
}
This would cause the thing to stop when I was done. I got it to work, but the only problem is I need to keep the mouse in the center of the window or else it would hit the corners of the screen and prevent further rotation.
Which is passed to a glutTimerFunc initially. First off: no movement of the scene occurs except for the very begging when the mouse is warped. Second: The mouse for some reason isn't in the center of the window.
Will you please help me with these problems?
Thanks in advanced.
Note: Oops, wrong place, this should probably in "For Beginners" sorry. Can someone switch it? I can't seem to find out how.
mouseDeltaX = mouseDeltaX - x; //Get the change.
mouseDeltaY = mouseDeltaY - y;
rotx = (float)mouseDeltaX; //Assign it to a global variable value that would actually rotate everything.
roty = (float)mouseDeltaY;
mouseDeltaX = x; //Change mouseDeltaX and mouseDeltaY to the current x
mouseDeltaY = y;
}
If you want to create FPS camera with glutWarpPointer you need to that values "rotx" and "roty" must be calculated by this way:
I have tried your suggestions, but your glutWarpPointer parameters look identical to mine (with different spacing) and it still isn't working. (Oops, nvm. I forgot to divide by 2, but it still isn't in the center for some odd reason using your code).
Also, I have tried changing my rotateCamera function to:
NAME
glutWarpPointer warps the pointer's location.
SYNTAX
void glutWarpPointer(int x, int y);
ARGUMENTS
x X offset relative to the current window's origin
(upper left).
y Y offset relative to the current window's origin
(upper left).
DESCRIPTION
glutWarpPointer warps the window system's pointer to a new
location relative to the origin of the current window.
The new location will be offset x pixels on the X axis and
y pixels on the Y axis. These parameters may be negative.
The warp is done immediately.
If the pointer would be warped outside the screen's frame
buffer region, the location will be clamped to the nearest
screen edge. The window system is allowed to further con
strain the pointer's location in window system dependent
ways.
The following is good advice that applies to glutWarp
Pointer: ``There is seldom any reason for calling this
function. The pointer should normally be left to the
user.'' (from Xlib's XWarpPointer man page.)
[/quote]
Have you tried:
glutWarpPointer(glutGet(GLUT_WINDOW_WIDTH) / 2, glutGet(GLUT_WINDOW_HEIGHT) / 2);
Sorry, I forgot that glutWarpPointer sets cursor in glut window's area. (for example, on windows, it calls SetCursorPos(glut_window_pos_x+glut_warp_pointer_x, glut_window_pos_y+glut_warp_pointer_y))
Thanks for the help it is in the center now, but the thing doesn't move correct still: It is really choppy unlike before when I didn't warp the pointer. I have changed my rotateCamera function to this, it doesn't update when I add the glutWarpPointer:
Thanks for the help it is in the center now, but the thing doesn't move correct still: It is really choppy unlike before when I didn't warp the pointer. I have changed my rotateCamera function to this, it doesn't update when I add the glutWarpPointer:
If "rotx" and "roty" are your relative rotations (of objects, view,...) use this:
float rotx=0.0f, roty=0.0f;// initialization
void rotateCamera(int x, int y) {
rotx += (float)(x - glutGet(GLUT_WINDOW_WIDTH)/2); // do an additive operation because with "=" your object view, etc... would always set to default
roty += (float)(y - glutGet(GLUT_WINDOW_HEIGHT)/2);
glutWarpPointer(glutGet(GLUT_WINDOW_WIDTH) / 2, glutGet(GLUT_WINDOW_HEIGHT) / 2);
}