From 9e5eced8dfbda2861bf2c6fdf2f6d1ce82ac4ac5 Mon Sep 17 00:00:00 2001 From: Flakebi Date: Thu, 20 Nov 2014 15:01:47 +0100 Subject: [PATCH 1/2] Improve smooth camera movement and move settings to user config --- src/config/user_config.hpp | 28 ++++++++++++++++++++++++++++ src/graphics/camera.cpp | 23 ++++++++++++++++------- src/graphics/camera.hpp | 3 +++ src/input/input_manager.cpp | 13 ++++++++----- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 4114de187..d0f5fb630 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -652,11 +652,38 @@ namespace UserConfigParams PARAM_DEFAULT( BoolUserConfigParam( CONSOLE_DEFAULT, "log_errors", "Enable logging to console.") ); + // ---- Camera + PARAM_PREFIX GroupUserConfigParam m_camera + PARAM_DEFAULT( GroupUserConfigParam("camera", + "(Debug) camera settings.") ); + PARAM_PREFIX IntUserConfigParam m_reverse_look_threshold PARAM_DEFAULT( IntUserConfigParam(0, "reverse_look_threshold", + &m_camera, "If the kart is driving backwards faster than this value,\n" "switch automatically to reverse camera (set to 0 to disable).") ); + PARAM_PREFIX FloatUserConfigParam m_camera_direction_speed + PARAM_DEFAULT( FloatUserConfigParam(0.003f, "rotation_speed", + &m_camera, + "How fast the first person camera's direction speed changes when\n" + "moving the mouse (means acceleration).") ); + + PARAM_PREFIX FloatUserConfigParam m_camera_smooth_direction_max_speed + PARAM_DEFAULT( FloatUserConfigParam(0.04f, "smooth_rotation_max_speed", + &m_camera, + "How fast the first person camera's direction can change.") ); + + PARAM_PREFIX FloatUserConfigParam m_camera_angular_velocity + PARAM_DEFAULT( FloatUserConfigParam(0.02f, "angular_velocity", + &m_camera, + "How fast the first person camera's rotation speed changes.") ); + + PARAM_PREFIX FloatUserConfigParam m_camera_max_angular_velocity + PARAM_DEFAULT( FloatUserConfigParam(1.0f, "max_angular_velocity", + &m_camera, + "How fast the first person camera can rotate.") ); + PARAM_PREFIX StringUserConfigParam m_item_style PARAM_DEFAULT( StringUserConfigParam("items", "item_style", "Name of the .items file to use.") ); @@ -672,6 +699,7 @@ namespace UserConfigParams PARAM_DEFAULT( StringUserConfigParam("Peach.stkskin", "skin_file", "Name of the skin to use") ); + // ---- Handicap PARAM_PREFIX GroupUserConfigParam m_handicap PARAM_DEFAULT( GroupUserConfigParam("Handicap", "Everything related to handicaps.") ); diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index db7d8f58f..674f8500e 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -90,6 +90,7 @@ Camera::Camera(int camera_index, AbstractKart* kart) : m_kart(NULL) m_target_velocity = core::vector3df(0, 0, 0); m_target_direction = core::vector3df(0, 0, 1); m_target_up_vector = core::vector3df(0, 1, 0); + m_direction_velocity = core::vector3df(0, 0, 0); m_angular_velocity = 0; m_target_angular_velocity = 0; m_max_velocity = 15; @@ -500,13 +501,13 @@ void Camera::update(float dt) // Angular velocity if (m_angular_velocity < m_target_angular_velocity) { - m_angular_velocity += 0.02f; + m_angular_velocity += UserConfigParams::m_camera_angular_velocity; if (m_angular_velocity > m_target_angular_velocity) m_angular_velocity = m_target_angular_velocity; } else if (m_angular_velocity > m_target_angular_velocity) { - m_angular_velocity -= 0.02f; + m_angular_velocity -= UserConfigParams::m_camera_angular_velocity; if (m_angular_velocity < m_target_angular_velocity) m_angular_velocity = m_target_angular_velocity; } @@ -524,17 +525,25 @@ void Camera::update(float dt) diff = m_target_direction - direction; if (diff.X != 0 || diff.Y != 0 || diff.Z != 0) { - if (diff.getLengthSQ() > 0.02f * 0.02f) - diff.setLength(0.02f); - direction += diff; + diff.setLength(UserConfigParams::m_camera_direction_speed); + m_direction_velocity += diff; + if (m_direction_velocity.getLengthSQ() > + UserConfigParams::m_camera_smooth_direction_max_speed * + UserConfigParams::m_camera_smooth_direction_max_speed) + m_direction_velocity.setLength( + UserConfigParams::m_camera_smooth_direction_max_speed); + direction += m_direction_velocity; + m_target_direction = direction; } // Camera rotation diff = m_target_up_vector - up; if (diff.X != 0 || diff.Y != 0 || diff.Z != 0) { - if (diff.getLengthSQ() > 0.02f * 0.02f) - diff.setLength(0.02f); + if (diff.getLengthSQ() > + UserConfigParams::m_camera_angular_velocity * + UserConfigParams::m_camera_angular_velocity) + diff.setLength(UserConfigParams::m_camera_angular_velocity); up += diff; } } diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index a7c8057dd..56c9ab48f 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -132,6 +132,9 @@ private: /** The target direction for the camera, only used for the first person camera. */ core::vector3df m_target_direction; + /** The speed at which the direction changes, only used for the first person camera. */ + core::vector3df m_direction_velocity; + /** The up vector the camera should have, only used for the first person camera. */ core::vector3df m_target_up_vector; diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index 07328a724..511dcd04b 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -214,7 +214,8 @@ void InputManager::handleStaticAction(int key, int value) UserConfigParams::m_camera_debug != 3) break; Camera *active_cam = Camera::getActiveCamera(); - active_cam->setAngularVelocity(value ? 1 : 0); + active_cam->setAngularVelocity(value ? + UserConfigParams::m_camera_max_angular_velocity : 0); break; } case KEY_KEY_E: @@ -223,7 +224,8 @@ void InputManager::handleStaticAction(int key, int value) UserConfigParams::m_camera_debug != 3) break; Camera *active_cam = Camera::getActiveCamera(); - active_cam->setAngularVelocity(value ? -1 : 0); + active_cam->setAngularVelocity(value ? + -UserConfigParams::m_camera_max_angular_velocity : 0); break; } @@ -965,12 +967,13 @@ EventPropagation InputManager::input(const SEvent& event) core::vector2df screen_size = irr_driver->getCurrentScreenSize(); int mid_x = (int) screen_size.X / 2; int mid_y = (int) screen_size.Y / 2; - //const int wheel = event.MouseInput.Wheel; // Relative mouse movement int diff_x = event.MouseInput.X - m_mouse_val_x; int diff_y = event.MouseInput.Y - m_mouse_val_y; - float mouse_x = ((float) diff_x) / 150; - float mouse_y = ((float) diff_y) / -150; + float mouse_x = ((float) diff_x) * + UserConfigParams::m_camera_direction_speed; + float mouse_y = ((float) diff_y) * + -UserConfigParams::m_camera_direction_speed; // No movement the first time it's used // At the moment there's also a hard limit because the mouse // gets reset to the middle of the screen and sometimes there From c7b43b49e71b0d13554419a40023095ebfa886c0 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Fri, 21 Nov 2014 18:25:50 -0500 Subject: [PATCH 2/2] Tweak variable names --- src/config/user_config.hpp | 16 ++++++++-------- src/graphics/camera.cpp | 18 +++++++++--------- src/input/input_manager.cpp | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index d0f5fb630..97df2f5e5 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -663,24 +663,24 @@ namespace UserConfigParams "If the kart is driving backwards faster than this value,\n" "switch automatically to reverse camera (set to 0 to disable).") ); - PARAM_PREFIX FloatUserConfigParam m_camera_direction_speed - PARAM_DEFAULT( FloatUserConfigParam(0.003f, "rotation_speed", + PARAM_PREFIX FloatUserConfigParam m_fspcam_direction_speed + PARAM_DEFAULT( FloatUserConfigParam(0.003f, "fspcam_rotation_speed", &m_camera, "How fast the first person camera's direction speed changes when\n" "moving the mouse (means acceleration).") ); - PARAM_PREFIX FloatUserConfigParam m_camera_smooth_direction_max_speed - PARAM_DEFAULT( FloatUserConfigParam(0.04f, "smooth_rotation_max_speed", + PARAM_PREFIX FloatUserConfigParam m_fspcam_smooth_direction_max_speed + PARAM_DEFAULT( FloatUserConfigParam(0.04f, "fspcam_smooth_rotation_max_speed", &m_camera, "How fast the first person camera's direction can change.") ); - PARAM_PREFIX FloatUserConfigParam m_camera_angular_velocity - PARAM_DEFAULT( FloatUserConfigParam(0.02f, "angular_velocity", + PARAM_PREFIX FloatUserConfigParam m_fspcam_angular_velocity + PARAM_DEFAULT( FloatUserConfigParam(0.02f, "fspcam_angular_velocity", &m_camera, "How fast the first person camera's rotation speed changes.") ); - PARAM_PREFIX FloatUserConfigParam m_camera_max_angular_velocity - PARAM_DEFAULT( FloatUserConfigParam(1.0f, "max_angular_velocity", + PARAM_PREFIX FloatUserConfigParam m_fspcam_max_angular_velocity + PARAM_DEFAULT( FloatUserConfigParam(1.0f, "fspcam_max_angular_velocity", &m_camera, "How fast the first person camera can rotate.") ); diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 674f8500e..9b362bbb0 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -501,13 +501,13 @@ void Camera::update(float dt) // Angular velocity if (m_angular_velocity < m_target_angular_velocity) { - m_angular_velocity += UserConfigParams::m_camera_angular_velocity; + m_angular_velocity += UserConfigParams::m_fspcam_angular_velocity; if (m_angular_velocity > m_target_angular_velocity) m_angular_velocity = m_target_angular_velocity; } else if (m_angular_velocity > m_target_angular_velocity) { - m_angular_velocity -= UserConfigParams::m_camera_angular_velocity; + m_angular_velocity -= UserConfigParams::m_fspcam_angular_velocity; if (m_angular_velocity < m_target_angular_velocity) m_angular_velocity = m_target_angular_velocity; } @@ -525,13 +525,13 @@ void Camera::update(float dt) diff = m_target_direction - direction; if (diff.X != 0 || diff.Y != 0 || diff.Z != 0) { - diff.setLength(UserConfigParams::m_camera_direction_speed); + diff.setLength(UserConfigParams::m_fspcam_direction_speed); m_direction_velocity += diff; if (m_direction_velocity.getLengthSQ() > - UserConfigParams::m_camera_smooth_direction_max_speed * - UserConfigParams::m_camera_smooth_direction_max_speed) + UserConfigParams::m_fspcam_smooth_direction_max_speed * + UserConfigParams::m_fspcam_smooth_direction_max_speed) m_direction_velocity.setLength( - UserConfigParams::m_camera_smooth_direction_max_speed); + UserConfigParams::m_fspcam_smooth_direction_max_speed); direction += m_direction_velocity; m_target_direction = direction; } @@ -541,9 +541,9 @@ void Camera::update(float dt) if (diff.X != 0 || diff.Y != 0 || diff.Z != 0) { if (diff.getLengthSQ() > - UserConfigParams::m_camera_angular_velocity * - UserConfigParams::m_camera_angular_velocity) - diff.setLength(UserConfigParams::m_camera_angular_velocity); + UserConfigParams::m_fspcam_angular_velocity * + UserConfigParams::m_fspcam_angular_velocity) + diff.setLength(UserConfigParams::m_fspcam_angular_velocity); up += diff; } } diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index 511dcd04b..b9b92a2df 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -215,7 +215,7 @@ void InputManager::handleStaticAction(int key, int value) Camera *active_cam = Camera::getActiveCamera(); active_cam->setAngularVelocity(value ? - UserConfigParams::m_camera_max_angular_velocity : 0); + UserConfigParams::m_fspcam_max_angular_velocity : 0); break; } case KEY_KEY_E: @@ -225,7 +225,7 @@ void InputManager::handleStaticAction(int key, int value) Camera *active_cam = Camera::getActiveCamera(); active_cam->setAngularVelocity(value ? - -UserConfigParams::m_camera_max_angular_velocity : 0); + -UserConfigParams::m_fspcam_max_angular_velocity : 0); break; } @@ -971,9 +971,9 @@ EventPropagation InputManager::input(const SEvent& event) int diff_x = event.MouseInput.X - m_mouse_val_x; int diff_y = event.MouseInput.Y - m_mouse_val_y; float mouse_x = ((float) diff_x) * - UserConfigParams::m_camera_direction_speed; + UserConfigParams::m_fspcam_direction_speed; float mouse_y = ((float) diff_y) * - -UserConfigParams::m_camera_direction_speed; + -UserConfigParams::m_fspcam_direction_speed; // No movement the first time it's used // At the moment there's also a hard limit because the mouse // gets reset to the middle of the screen and sometimes there