diff --git a/src/Camera.c b/src/Camera.c index 659e119a6..967390605 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -21,6 +21,13 @@ static void Camera_OnRawMovement(float deltaX, float deltaY) { cam_deltaX += deltaX; cam_deltaY += deltaY; } +void Camera_KeyLookUpdate(cc_bool up, cc_bool down, cc_bool right, cc_bool left) { + if (up) cam_deltaY -= 10.0; + if (down) cam_deltaY += 10.0; + if (right) cam_deltaX += 10.0; + if (left) cam_deltaX -= 10.0; +} + /*########################################################################################################################* *--------------------------------------------------Perspective camera-----------------------------------------------------* *#########################################################################################################################*/ diff --git a/src/Camera.h b/src/Camera.h index ab981a55d..0235d9ca5 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -80,4 +80,5 @@ CC_API void Camera_Register(struct Camera* camera); void Camera_CheckFocus(void); void Camera_UpdateProjection(void); void Camera_SetFov(int fov); +void Camera_KeyLookUpdate(cc_bool up, cc_bool down, cc_bool right, cc_bool left); #endif diff --git a/src/Input.c b/src/Input.c index 6edbb5dbe..e54b4338b 100644 --- a/src/Input.c +++ b/src/Input.c @@ -325,7 +325,8 @@ const cc_uint8 KeyBind_Defaults[KEYBIND_COUNT] = { KEY_F5, KEY_F1, KEY_F7, 'C', KEY_LCTRL, KEY_LMOUSE, KEY_MMOUSE, KEY_RMOUSE, KEY_F6, KEY_LALT, KEY_F8, - 'G', KEY_F10, 0 + 'G', KEY_F10, 0, + 0, 0, 0, 0 }; static const char* const keybindNames[KEYBIND_COUNT] = { "Forward", "Back", "Left", "Right", @@ -336,7 +337,8 @@ static const char* const keybindNames[KEYBIND_COUNT] = { "ThirdPerson", "HideGUI", "AxisLines", "ZoomScrolling", "HalfSpeed", "DeleteBlock", "PickBlock", "PlaceBlock", "AutoRotate", "HotbarSwitching", "SmoothCamera", - "DropBlock", "IDOverlay", "BreakableLiquids" + "DropBlock", "IDOverlay", "BreakableLiquids", + "LookUp", "LookDown", "LookRight", "LookLeft" }; cc_bool KeyBind_IsPressed(KeyBind binding) { return Input_Pressed[KeyBinds[binding]]; } @@ -770,9 +772,17 @@ void InputHandler_PickBlock(void) { void InputHandler_Tick(void) { cc_bool left, middle, right; + cc_bool look_up, look_down, look_right, look_left; TimeMS now = DateTime_CurrentUTC_MS(); int delta = (int)(now - input_lastClick); + look_up = KeyBind_IsPressed(KEYBIND_LOOK_UP); + look_down = KeyBind_IsPressed(KEYBIND_LOOK_DOWN); + look_right = KeyBind_IsPressed(KEYBIND_LOOK_RIGHT); + look_left = KeyBind_IsPressed(KEYBIND_LOOK_LEFT); + + Camera_KeyLookUpdate(look_up, look_down, look_right, look_left); + if (delta < 250) return; /* 4 times per second */ input_lastClick = now; if (Gui.InputGrab) return; diff --git a/src/Input.h b/src/Input.h index 94493a034..a873b6e34 100644 --- a/src/Input.h +++ b/src/Input.h @@ -132,6 +132,7 @@ enum KeyBind_ { KEYBIND_HALF_SPEED, KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK, KEYBIND_AUTOROTATE, KEYBIND_HOTBAR_SWITCH, KEYBIND_SMOOTH_CAMERA, KEYBIND_DROP_BLOCK, KEYBIND_IDOVERLAY, KEYBIND_BREAK_LIQUIDS, + KEYBIND_LOOK_UP, KEYBIND_LOOK_DOWN, KEYBIND_LOOK_RIGHT, KEYBIND_LOOK_LEFT, KEYBIND_COUNT }; typedef int KeyBind; diff --git a/src/Menus.c b/src/Menus.c index 9d7645096..4600a481a 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -2005,11 +2005,11 @@ void OtherKeyBindingsScreen_Show(void) { *------------------------------------------------MouseKeyBindingsScreen---------------------------------------------------* *#########################################################################################################################*/ void MouseKeyBindingsScreen_Show(void) { - static const cc_uint8 binds[3] = { KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK }; - static const char* const descs[3] = { "Delete block", "Pick block", "Place block" }; + static const cc_uint8 binds[7] = { KEYBIND_DELETE_BLOCK, KEYBIND_PICK_BLOCK, KEYBIND_PLACE_BLOCK, KEYBIND_LOOK_UP, KEYBIND_LOOK_DOWN, KEYBIND_LOOK_RIGHT, KEYBIND_LOOK_LEFT }; + static const char* const descs[7] = { "Delete block", "Pick block", "Place block", "Look Up", "Look Down", "Look Right", "Look Left" }; KeyBindsScreen_Reset(Menu_SwitchKeysOther, NULL, 260); - KeyBindsScreen_SetLayout(-40, 10, -1); + KeyBindsScreen_SetLayout(-140, 10, 5); KeyBindsScreen.msgText = "&ePress escape to reset the binding"; KeyBindsScreen_Show(Array_Elems(binds), binds, descs, "Mouse key bindings"); }