diff options
Diffstat (limited to 'src/client/camera.cpp')
-rw-r--r-- | src/client/camera.cpp | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 350b685e1..f3aa4bafe 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "constants.h" #include "fontengine.h" #include "script/scripting_client.h" +#include "wieldanimation.h" #define CAMERA_OFFSET_STEP 200 #define WIELDMESH_OFFSET_X 55.0f @@ -173,8 +174,12 @@ void Camera::step(f32 dtime) bool was_under_zero = m_wield_change_timer < 0; m_wield_change_timer = MYMIN(m_wield_change_timer + dtime, 0.125); - if (m_wield_change_timer >= 0 && was_under_zero) +if (m_wield_change_timer >= 0 && was_under_zero) { m_wieldnode->setItem(m_wield_item_next, m_client); + m_wield_animation = m_wield_item_next + .getDefinition(m_client->getItemDefManager()) + .wield_animation; +} if (m_view_bobbing_state != 0) { @@ -217,15 +222,15 @@ void Camera::step(f32 dtime) } if (m_digging_button != -1) { - f32 offset = dtime * 3.5f; float m_digging_anim_was = m_digging_anim; - m_digging_anim += offset; - if (m_digging_anim >= 1) + m_digging_anim += dtime; + const WieldAnimation &wield_anim = WieldAnimation::getNamed(m_wield_animation); + if (m_digging_anim >= wield_anim.getDuration()) { m_digging_anim = 0; m_digging_button = -1; } - float lim = 0.15; + float lim = 0.05f; if(m_digging_anim_was < lim && m_digging_anim >= lim) { if (m_digging_button == 0) { @@ -553,12 +558,16 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r if (m_arm_inertia) addArmInertia(player->getYaw()); + const WieldAnimation &wield_anim = WieldAnimation::getNamed(m_wield_animation); + // Position the wielded item //v3f wield_position = v3f(45, -35, 65); v3f wield_position = v3f(m_wieldmesh_offset.X, m_wieldmesh_offset.Y, 65); //v3f wield_rotation = v3f(-100, 120, -100); v3f wield_rotation = v3f(-100, 120, -100); + core::quaternion wield_rotation_q = core::quaternion(wield_rotation * core::DEGTORAD); wield_position.Y += fabs(m_wield_change_timer)*320 - 40; +#if 0 if(m_digging_anim < 0.05 || m_digging_anim > 0.5) { f32 frac = 1.0; @@ -575,24 +584,55 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r //wield_rotation.X -= frac * 15.0 * pow(ratiothing2, 1.4f); //wield_rotation.Z += frac * 15.0 * pow(ratiothing2, 1.0f); } +#endif if (m_digging_button != -1) { f32 digfrac = m_digging_anim; - wield_position.X -= 50 * sin(pow(digfrac, 0.8f) * M_PI); - wield_position.Y += 24 * sin(digfrac * 1.8 * M_PI); - wield_position.Z += 25 * 0.5; + v3f anim_position = wield_anim.getTranslationAt(digfrac); + wield_position.X += anim_position.X; + wield_position.Y += anim_position.Y; + wield_position.Z += anim_position.Z; // Euler angles are PURE EVIL, so why not use quaternions? - core::quaternion quat_begin(wield_rotation * core::DEGTORAD); - core::quaternion quat_end(v3f(80, 30, 100) * core::DEGTORAD); - core::quaternion quat_slerp; - quat_slerp.slerp(quat_begin, quat_end, sin(digfrac * M_PI)); - quat_slerp.toEuler(wield_rotation); + core::quaternion quat_rot = wield_anim.getRotationAt(digfrac); + // apply rotation to starting rotation + wield_rotation_q *= quat_rot; + // convert back to euler angles + wield_rotation_q.toEuler(wield_rotation); wield_rotation *= core::RADTODEG; } else { f32 bobfrac = my_modf(m_view_bobbing_anim); + // std::cout << "Third block, frac = " << bobfrac << std::endl; wield_position.X -= sin(bobfrac*M_PI*2.0) * 3.0; wield_position.Y += sin(my_modf(bobfrac*2.0)*M_PI) * 3.0; +#if 0 + // to help with finding rotations, change the '0' above + // to '1' and recompile, then fly around. + + wield_position.X += -50; + wield_position.Y += 20; + wield_position.Z += 0; + + float pitch = wrapDegrees_180(player_position.X); + float yaw = wrapDegrees_180(player_position.Y); + float roll = wrapDegrees_180(player_position.Z); + //wield_rotation_q *= core::quaternion( + // (pitch) * core::DEGTORAD, + // (roll) * core::DEGTORAD, + // (yaw) * core::DEGTORAD + //); + wield_rotation_q *= core::quaternion(pitch * core::DEGTORAD, 0, 0); + wield_rotation_q *= core::quaternion(0, yaw * core::DEGTORAD, 0); + wield_rotation_q *= core::quaternion(0, 0, roll * core::DEGTORAD); + dstream << "Wield rotation " << pitch << ", " << yaw << ", " << roll << std::endl; + // -90, 15, -60 + // convert back to euler angles + wield_rotation_q.toEuler(wield_rotation); + wield_rotation *= core::RADTODEG; +#endif + } + if (!wield_position.equals(v3f(55, -35, 65))) { + // std::cout << m_digging_anim << ": " << wield_position.X-55 << ", " << wield_position.Y+35 << ", " << wield_position.Z-65 << std::endl; } m_wieldnode->setPosition(wield_position); m_wieldnode->setRotation(wield_rotation); |