Skip to content

Commit 7cd5eb4

Browse files
MirceaKitsunekwolekr
authored andcommittedApr 11, 2013
Swing the camera down when the player lands on the ground, based on the velocity the surface is hit with.
1 parent 17cfb18 commit 7cd5eb4

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed
 

‎src/camera.cpp

+27-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
6767
m_view_bobbing_anim(0),
6868
m_view_bobbing_state(0),
6969
m_view_bobbing_speed(0),
70+
m_view_bobbing_fall(0),
7071

7172
m_digging_anim(0),
7273
m_digging_button(-1),
@@ -134,6 +135,13 @@ inline f32 my_modf(f32 x)
134135

135136
void Camera::step(f32 dtime)
136137
{
138+
if(m_view_bobbing_fall > 0)
139+
{
140+
m_view_bobbing_fall -= 3 * dtime;
141+
if(m_view_bobbing_fall <= 0)
142+
m_view_bobbing_fall = -1; // Mark the effect as finished
143+
}
144+
137145
if (m_view_bobbing_state != 0)
138146
{
139147
//f32 offset = dtime * m_view_bobbing_speed * 0.035;
@@ -237,11 +245,28 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
237245
m_playernode->setRotation(v3f(0, -1 * player->getYaw(), 0));
238246
m_playernode->updateAbsolutePosition();
239247

240-
//Get camera tilt timer (hurt animation)
248+
// Get camera tilt timer (hurt animation)
241249
float cameratilt = fabs(fabs(player->hurt_tilt_timer-0.75)-0.75);
242250

251+
// Fall bobbing animation
252+
float fall_bobbing = 0;
253+
if(player->camera_impact >= 1)
254+
{
255+
if(m_view_bobbing_fall == -1) // Effect took place and has finished
256+
player->camera_impact = m_view_bobbing_fall = 0;
257+
else if(m_view_bobbing_fall == 0) // Initialize effect
258+
m_view_bobbing_fall = 1;
259+
260+
// Convert 0 -> 1 to 0 -> 1 -> 0
261+
fall_bobbing = m_view_bobbing_fall < 0.5 ? m_view_bobbing_fall * 2 : -(m_view_bobbing_fall - 0.5) * 2 + 1;
262+
// Smoothen and invert the above
263+
fall_bobbing = sin(fall_bobbing * 0.5 * M_PI) * -1;
264+
// Amplify according to the intensity of the impact
265+
fall_bobbing *= (1 - rangelim(50 / player->camera_impact, 0, 1)) * 5;
266+
}
267+
243268
// Set head node transformation
244-
m_headnode->setPosition(player->getEyeOffset()+v3f(0,cameratilt*-player->hurt_tilt_strength,0));
269+
m_headnode->setPosition(player->getEyeOffset()+v3f(0,cameratilt*-player->hurt_tilt_strength+fall_bobbing,0));
245270
m_headnode->setRotation(v3f(player->getPitch(), 0, cameratilt*player->hurt_tilt_strength));
246271
m_headnode->updateAbsolutePosition();
247272

‎src/camera.h

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ class Camera
166166
s32 m_view_bobbing_state;
167167
// Speed of view bobbing animation
168168
f32 m_view_bobbing_speed;
169+
// Fall view bobbing
170+
f32 m_view_bobbing_fall;
169171

170172
// Digging animation frame (0 <= m_digging_anim < 1)
171173
f32 m_digging_anim;

‎src/localplayer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
329329
if(!touching_ground_was && touching_ground){
330330
MtEvent *e = new SimpleTriggerEvent("PlayerRegainGround");
331331
m_gamedef->event()->put(e);
332+
333+
// Set camera impact value to be used for view bobbing
334+
camera_impact = getSpeed().Y * -1;
332335
}
333336

334337
{

‎src/localplayer.h

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class LocalPlayer : public Player
5959
float last_yaw;
6060
unsigned int last_keyPressed;
6161

62+
float camera_impact;
63+
6264
private:
6365
// This is used for determining the sneaking range
6466
v3s16 m_sneak_node;

0 commit comments

Comments
 (0)
Please sign in to comment.