Skip to content

Instantly share code, notes, and snippets.

@david-sabata
Created September 27, 2010 13:10
Show Gist options
  • Save david-sabata/598986 to your computer and use it in GitHub Desktop.
Save david-sabata/598986 to your computer and use it in GitHub Desktop.
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, &center); // 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