commit cdd516cee038074a846c2b9c52ff9c12f8009b5f parent 43668d1da8b20d86589d2898e17cab0d9cc1965f Author: Michael Savage <mikejsavage@gmail.com> Date: Wed Dec 28 00:25:01 +0200 Dumpy mouse input Diffstat:
game.h | | | 2 | ++ |
hm.cc | | | 3 | +++ |
main.cc | | | 12 | ++++++++++++ |
diff --git a/game.h b/game.h @@ -59,6 +59,8 @@ struct GameMemory { struct GameInput { bool keys[ KEY_COUNT ]; + double mouse_dx; + double mouse_dy; }; #define GAME_INIT( name ) void name( GameState * game, GameMemory * mem ) diff --git a/hm.cc b/hm.cc @@ -198,6 +198,9 @@ extern "C" GAME_FRAME( game_frame ) { game->angles.x += pitch * dt * 2; game->angles.y += yaw * dt * 2; + game->angles.x += input->mouse_dy * 0.01; + game->angles.y += input->mouse_dx * 0.01; + const float dsun = ( input->keys[ KEY_EQUALS ] - input->keys[ KEY_MINUS ] ) * dt; game->test_sun += dsun; if( dsun != 0 ) printf( "sun: %.4f\n", game->test_sun ); diff --git a/main.cc b/main.cc @@ -120,6 +120,8 @@ int main( int argc, char ** argv ) { game.init( &state, &mem ); #endif + glfwSetInputMode( window, GLFW_CURSOR, GLFW_CURSOR_DISABLED ); + const float program_start_time = glfwGetTime(); float last_frame_time = program_start_time; u64 total_frames = 0; @@ -127,6 +129,9 @@ int main( int argc, char ** argv ) { _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON ); _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON ); + double last_xpos = 0.0; + double last_ypos = 0.0; + while( !glfwWindowShouldClose( window ) ) { const float current_frame_time = glfwGetTime(); const float dt = current_frame_time - last_frame_time; @@ -163,6 +168,13 @@ int main( int argc, char ** argv ) { input.keys[ KEY_MINUS ] = glfwGetKey( window, GLFW_KEY_MINUS ) == GLFW_PRESS; input.keys[ KEY_EQUALS ] = glfwGetKey( window, GLFW_KEY_EQUAL ) == GLFW_PRESS; + double xpos, ypos; + glfwGetCursorPos( window, &xpos, &ypos ); + input.mouse_dx = xpos - last_xpos; + input.mouse_dy = ypos - last_ypos; + last_xpos = xpos; + last_ypos = ypos; + #if STATIC_GAME game_frame( &state, &mem, &input, current_frame_time, dt ); #else