commit b59078bcc297c7f29267e907aaeb51853f91a68a parent 279fa02ea2533e86e732d7e960e4a83f1133c76d Author: Michael Savage <mikejsavage@gmail.com> Date: Sun Jul 9 11:22:46 +0300 Better camera controls Diffstat:
hm.cc | | | 14 | +++++++------- |
diff --git a/hm.cc b/hm.cc @@ -162,17 +162,17 @@ GAME_FRAME( game_frame ) { float lr = float( input->keys[ KEY_D ] - input->keys[ KEY_A ] ); float dz = float( input->keys[ KEY_SPACE ] - input->keys[ KEY_LEFTSHIFT ] ); - int dpitch = input->keys[ KEY_DOWNARROW ] - input->keys[ KEY_UPARROW ]; - int dyaw = input->keys[ KEY_LEFTARROW ] - input->keys[ KEY_RIGHTARROW ]; + float dpitch = input->keys[ KEY_DOWNARROW ] - input->keys[ KEY_UPARROW ]; + float dyaw = input->keys[ KEY_LEFTARROW ] - input->keys[ KEY_RIGHTARROW ]; - dpitch += input->keys[ KEY_K ] - input->keys[ KEY_I ]; + dpitch = input->keys[ KEY_K ] - input->keys[ KEY_I ]; dyaw += input->keys[ KEY_J ] - input->keys[ KEY_L ]; - game->pitch += dpitch * dt * 100; - game->yaw += dyaw * dt * 100; + dpitch -= float( input->mouse_dy * 0.25 ); + dyaw -= float( input->mouse_dx * 0.25 ); - game->pitch -= float( input->mouse_dy * 0.1 ); - game->yaw -= float( input->mouse_dx * 0.1 ); + game->pitch = clamp( game->pitch + dpitch * dt * 100, -89.9f, 89.9f ); + game->yaw += dyaw * dt * 100; const float dsun = ( input->keys[ KEY_EQUALS ] - input->keys[ KEY_MINUS ] ) * dt; game->test_sun += dsun;