Skip to content

Commit b1da13f

Browse files
Add smooth strength
1 parent 7b065b4 commit b1da13f

File tree

5 files changed

+124
-76
lines changed

5 files changed

+124
-76
lines changed

data/gui/dialogs/custom_camera_settings.stkgui

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,21 @@
3939

4040
<spacer height="2%" width="100%" />
4141

42+
<label width="100%" I18N="In the ui/camera settings" text="Smooth camera"/>
43+
<spacer height="1%" width="100%" />
4244
<div width="100%" height="fit" layout="horizontal-row">
4345
<spacer width="3%" height="100%" />
44-
<div proportion="1" height="fit" layout="horizontal-row" >
45-
<checkbox id="camera_smoothing"/>
46-
<spacer width="1%" height="100%" />
47-
<label height="100%" text_align="left" I18N="In the ui/camera screen" text="Smooth camera"/>
48-
</div>
46+
<label width="fit" height="100%" text_align="left" I18N="In the ui/camera screen" text="Distance"/>
47+
<gauge id="smooth_position" width="35%"/>
48+
<spacer width="2%" height="100%" />
49+
<label width="fit" height="100%" text_align="left" I18N="In the ui/camera screen" text="Angle"/>
50+
<gauge id="smooth_rotation" width="35%"/>
4951
</div>
5052

5153
<spacer width="5" height="2%"/>
5254

5355
<label width="100%" I18N="In the ui/camera settings" text="Backward camera"/>
54-
<spacer height="2%" width="100%" />
56+
<spacer height="1%" width="100%" />
5557
<div width="100%" height="fit" layout="horizontal-row">
5658
<spacer width="3%" height="100%" />
5759
<label width="fit" height="100%" text_align="left" I18N="In the ui/camera screen" text="Distance"/>
@@ -72,7 +74,7 @@
7274
</div>
7375
</div>
7476

75-
<spacer height="2%" width="100%" />
77+
<spacer proportion="1" width="100%" />
7678

7779
<buttonbar id="buttons" height="20%" width="90%" align="center">
7880
<icon-button id="reset" width="128" height="128" icon="gui/icons/restart.png"

src/config/user_config.hpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,15 @@ namespace UserConfigParams
10501050
&m_camera_normal,
10511051
"Angle between camera and plane of kart (pitch) when the camera is pointing forward"));
10521052

1053-
PARAM_PREFIX BoolUserConfigParam m_camera_forward_smoothing
1054-
PARAM_DEFAULT( BoolUserConfigParam(true, "forward-smoothing",
1053+
PARAM_PREFIX FloatUserConfigParam m_camera_forward_smooth_position
1054+
PARAM_DEFAULT( FloatUserConfigParam(0.2, "forward-smooth-position",
10551055
&m_camera_normal,
1056-
"if true, use smoothing (forward-up-angle become relative to speed) when pointing forward"));
1056+
"The strength of smoothness of the position of the camera"));
1057+
1058+
PARAM_PREFIX FloatUserConfigParam m_camera_forward_smooth_rotation
1059+
PARAM_DEFAULT( FloatUserConfigParam(0.125, "forward-smooth-rotation",
1060+
&m_camera_normal,
1061+
"The strength of smoothness of the rotation of the camera"));
10571062

10581063
PARAM_PREFIX FloatUserConfigParam m_camera_backward_distance
10591064
PARAM_DEFAULT( FloatUserConfigParam(2.0, "backward-distance",
@@ -1095,10 +1100,15 @@ namespace UserConfigParams
10951100
&m_standard_camera_settings,
10961101
"Angle between camera and plane of kart (pitch) when the camera is pointing forward"));
10971102

1098-
PARAM_PREFIX BoolUserConfigParam m_standard_camera_forward_smoothing
1099-
PARAM_DEFAULT( BoolUserConfigParam(true, "forward-smoothing",
1103+
PARAM_PREFIX FloatUserConfigParam m_standard_camera_forward_smooth_position
1104+
PARAM_DEFAULT( FloatUserConfigParam(0.2, "forward-smooth-position",
1105+
&m_standard_camera_settings,
1106+
"The strength of smoothness of the position of the camera"));
1107+
1108+
PARAM_PREFIX FloatUserConfigParam m_standard_camera_forward_smooth_rotation
1109+
PARAM_DEFAULT( FloatUserConfigParam(0.125, "forward-smooth-rotation",
11001110
&m_standard_camera_settings,
1101-
"if true, use smoothing (forward-up-angle become relative to speed) when pointing forward"));
1111+
"The strength of smoothness of the rotation of the camera"));
11021112

11031113
PARAM_PREFIX FloatUserConfigParam m_standard_camera_backward_distance
11041114
PARAM_DEFAULT( FloatUserConfigParam(2.0, "backward-distance",
@@ -1136,10 +1146,15 @@ namespace UserConfigParams
11361146
&m_drone_camera_settings,
11371147
"Angle between camera and plane of kart (pitch) when the camera is pointing forward"));
11381148

1139-
PARAM_PREFIX BoolUserConfigParam m_drone_camera_forward_smoothing
1140-
PARAM_DEFAULT( BoolUserConfigParam(false, "forward-smoothing",
1149+
PARAM_PREFIX FloatUserConfigParam m_drone_camera_forward_smooth_position
1150+
PARAM_DEFAULT( FloatUserConfigParam(0.0, "forward-smooth-position",
1151+
&m_drone_camera_settings,
1152+
"The strength of smoothness of the position of the camera"));
1153+
1154+
PARAM_PREFIX FloatUserConfigParam m_drone_camera_forward_smooth_rotation
1155+
PARAM_DEFAULT( FloatUserConfigParam(0.0, "forward-smooth-rotation",
11411156
&m_drone_camera_settings,
1142-
"if true, use smoothing (forward-up-angle become relative to speed) when pointing forward"));
1157+
"The strength of smoothness of the rotation of the camera"));
11431158

11441159
PARAM_PREFIX FloatUserConfigParam m_drone_camera_backward_distance
11451160
PARAM_DEFAULT( FloatUserConfigParam(2.0, "backward-distance",
@@ -1168,19 +1183,24 @@ namespace UserConfigParams
11681183
"Saved custom camera settings for player.") );
11691184

11701185
PARAM_PREFIX FloatUserConfigParam m_saved_camera_distance
1171-
PARAM_DEFAULT( FloatUserConfigParam(1.0, "distance",
1186+
PARAM_DEFAULT( FloatUserConfigParam(1.5, "distance",
11721187
&m_saved_camera_settings,
11731188
"Distance between kart and camera"));
11741189

11751190
PARAM_PREFIX FloatUserConfigParam m_saved_camera_forward_up_angle
1176-
PARAM_DEFAULT( FloatUserConfigParam(0, "forward-up-angle",
1191+
PARAM_DEFAULT( FloatUserConfigParam(25, "forward-up-angle",
11771192
&m_saved_camera_settings,
11781193
"Angle between camera and plane of kart (pitch) when the camera is pointing forward"));
11791194

1180-
PARAM_PREFIX BoolUserConfigParam m_saved_camera_forward_smoothing
1181-
PARAM_DEFAULT( BoolUserConfigParam(true, "forward-smoothing",
1195+
PARAM_PREFIX FloatUserConfigParam m_saved_camera_forward_smooth_position
1196+
PARAM_DEFAULT( FloatUserConfigParam(0.1, "forward-smooth-position",
11821197
&m_saved_camera_settings,
1183-
"if true, use smoothing (forward-up-angle become relative to speed) when pointing forward"));
1198+
"The strength of smoothness of the position of the camera"));
1199+
1200+
PARAM_PREFIX FloatUserConfigParam m_saved_camera_forward_smooth_rotation
1201+
PARAM_DEFAULT( FloatUserConfigParam(0.125, "forward-smooth-rotation",
1202+
&m_saved_camera_settings,
1203+
"The strength of smoothness of the rotation of the camera"));
11841204

11851205
PARAM_PREFIX FloatUserConfigParam m_saved_camera_backward_distance
11861206
PARAM_DEFAULT( FloatUserConfigParam(2.0, "backward-distance",
@@ -1193,7 +1213,7 @@ namespace UserConfigParams
11931213
"Angle between camera and plane of kart (pitch) when the camera is pointing backwards. This is usually larger than the forward-up-angle, since the kart itself otherwise obstricts too much of the view"));
11941214

11951215
PARAM_PREFIX IntUserConfigParam m_saved_camera_fov
1196-
PARAM_DEFAULT( IntUserConfigParam(80, "fov",
1216+
PARAM_DEFAULT( IntUserConfigParam(85, "fov",
11971217
&m_saved_camera_settings,
11981218
"Focal distance (single player)"));
11991219

src/graphics/camera/camera_normal.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,11 @@ void CameraNormal::moveCamera(float dt, bool smooth, float cam_angle, float dist
117117
(0.85f + ratio / 2.5f) - tan_up,
118118
camera_distance * cosf(skid_angle / 2));
119119

120-
float delta = (dt*5.0f);
121-
if (delta < 0.0f)
122-
delta = 0.0f;
123-
else if (delta > 1.0f)
124-
delta = 1.0f;
125-
126-
float delta2 = dt * 8.0f;
127-
if (delta2 < 0)
128-
delta2 = 0;
129-
else if (delta2 > 1)
130-
delta2 = 1;
120+
float delta = dt / std::max(dt, float(UserConfigParams::m_camera_forward_smooth_position));
121+
float delta2 = dt / std::max(dt, float(UserConfigParams::m_camera_forward_smooth_rotation));
122+
123+
delta = irr::core::clamp(delta, 0.0f, 1.0f);
124+
delta2 = irr::core::clamp(delta2, 0.0f, 1.0f);
131125

132126
btTransform btt = m_kart->getSmoothedTrans();
133127
m_kart_position = btt.getOrigin();
@@ -210,7 +204,8 @@ void CameraNormal::getCameraSettings(Mode mode,
210204
// quadratically to dampen small variations (but keep sign)
211205
float dampened_steer = fabsf(steering) * steering;
212206
*sideway = -m_rotation_range*dampened_steer*0.5f;
213-
*smoothing = UserConfigParams::m_camera_forward_smoothing;
207+
*smoothing = UserConfigParams::m_camera_forward_smooth_position != 0.
208+
|| UserConfigParams::m_camera_forward_smooth_rotation != 0.;
214209
*cam_roll_angle = 0.0f;
215210
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
216211
{

0 commit comments

Comments
 (0)