Created
September 27, 2010 13:10
-
-
Save david-sabata/598986 to your computer and use it in GitHub Desktop.
This file contains 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
bool b_mouse_controlled = false; | |
float mouse_sensitivity = 0.001f; | |
Vector3f camera_target; | |
... | |
case WM_MOUSEMOVE: | |
// ignorovat eventy pokud je zdrojem posunu SetCursorPos | |
if (!b_mouse_controlled) { | |
GLint viewport[4]; | |
glGetIntegerv(GL_VIEWPORT, viewport); // x, y, w, h okna | |
// stred okna | |
POINT center; | |
center.x = viewport[2] / 2; | |
center.y = viewport[3] / 2; | |
// odchyleni od stredu okna | |
int dx = LOWORD(n_l_param) - center.x; | |
int dy = HIWORD(n_l_param) - center.y; | |
if(dx || dy) { | |
// zmenit pohled kamery; souradnice Y musi byt invertovana | |
camera_target += Vector3f(dx * mouse_sensitivity, -dy * mouse_sensitivity, 0); | |
b_mouse_controlled = true; // pristi event chceme ignorovat | |
ClientToScreen(h_wnd, ¢er); // chceme nastavit pozici relativne k oknu | |
SetCursorPos(center.x, center.y); | |
} | |
} else { | |
b_mouse_controlled = false; | |
} | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment