Skip to content

Instantly share code, notes, and snippets.

@tuttlem
Created December 30, 2013 09:42
Show Gist options
  • Save tuttlem/8179902 to your computer and use it in GitHub Desktop.
Save tuttlem/8179902 to your computer and use it in GitHub Desktop.
Camera mouse
void mouseMotion(int x, int y) {
// calculate the origin point (shifting right divides by two, remember!)
int halfWidth = windowWidth >> 1;
int halfHeight = windowHeight >> 1;
// calculate how far we deviated from the origin point and deaden this
// by a factor of 20
float deltaX = (halfWidth - x) / 20.0f;
float deltaY = (halfHeight - y) / 20.0f;
// don't do anything if there wasn't any movement to report
if ((deltaX == 0.0f) && (deltaY == 0.0f)) {
return ;
}
// set the camera's orientation
cam.yaw(deltaX);
cam.pitch(deltaY);
// reset the mouse pointer back to the origin point
glutWarpPointer(halfWidth, halfHeight);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment