Created
December 30, 2013 09:42
-
-
Save tuttlem/8179902 to your computer and use it in GitHub Desktop.
Camera mouse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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