From c490db927b2e5d516a93e5787354b4ef086a4acd Mon Sep 17 00:00:00 2001 From: Alayan-stk-2 Date: Thu, 12 Apr 2018 21:45:53 +0200 Subject: [PATCH] Remember previous positions --- src/karts/kart.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 23cc58192..a4b198ea1 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -147,6 +147,12 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id, m_boosted_ai = false; m_type = RaceManager::KT_AI; + for (int i=0;i<30;i++) + { + m_previous_xyz[i] = getXYZ(); + } + time_previous_counter = 0.0f; + m_view_blocked_by_plunger = 0; m_has_caught_nolok_bubblegum = false; @@ -370,6 +376,12 @@ void Kart::reset() m_has_caught_nolok_bubblegum = false; m_is_jumping = false; + for (int i=0;i<30;i++) + { + m_previous_xyz[i] = getXYZ(); + } + time_previous_counter = 0.0f; + // In case that the kart was in the air, in which case its // linear damping is 0 if(m_body) @@ -1278,9 +1290,22 @@ void Kart::update(float dt) { m_kart_animation->update(dt); } + + time_previous_counter += dt; + while (time_previous_counter > (1.0f/120.0f)) + { + m_previous_xyz[0] = getXYZ(); + for (int i=29;i>0;i--) + { + m_previous_xyz[i] = m_previous_xyz[i-1]; + } + time_previous_counter -= (1.0f/120.0f); + } + // Update the position and other data taken from the physics (or // an animation which calls setXYZ(), which also updates the kart // physical position). + Moveable::update(dt); Vec3 front(0, 0, getKartLength()*0.5f); @@ -3050,6 +3075,14 @@ const Vec3& Kart::getNormal() const return m_terrain_info->getNormal(); } // getNormal +// ------------------------------------------------------------------------ +/** Returns the position 0,25s before */ +const Vec3& Kart::getPreviousXYZ() const +{ + return m_previous_xyz[29]; +} // getPreviousXYZ + + // ------------------------------------------------------------------------ void Kart::playSound(SFXBuffer* buffer) {