From 0b480e7a7157de25ed9c03ae218d204bc308e73d Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 10 Dec 2019 13:35:43 +0800 Subject: [PATCH] Restore linear and angular velocities of 3d animation physical objects --- src/network/rewind_manager.cpp | 7 ++++++- src/tracks/track_object.cpp | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/network/rewind_manager.cpp b/src/network/rewind_manager.cpp index b693be147..2c9c50852 100644 --- a/src/network/rewind_manager.cpp +++ b/src/network/rewind_manager.cpp @@ -360,10 +360,15 @@ void RewindManager::rewindTo(int rewind_ticks, int now_ticks, // Update check line, so the cannon animation can be replayed correctly CheckManager::get()->resetAfterRewind(); - if (exact_rewind_ticks > 0) + if (exact_rewind_ticks >= 2) { // Restore all physical objects moved by 3d animation, as it only // set the motion state of physical bodies, it has 1 frame delay + // the resetAfterRewind will do the saveKinematicState which needs + // the previous frame transforms to calculate current linear and + // angular velocities + world->setTicksForRewind(exact_rewind_ticks - 2); + Track::getCurrentTrack()->getTrackObjectManager()->resetAfterRewind(); world->setTicksForRewind(exact_rewind_ticks - 1); Track::getCurrentTrack()->getTrackObjectManager()->resetAfterRewind(); world->setTicksForRewind(exact_rewind_ticks); diff --git a/src/tracks/track_object.cpp b/src/tracks/track_object.cpp index d85cddcf7..7ed3df008 100644 --- a/src/tracks/track_object.cpp +++ b/src/tracks/track_object.cpp @@ -565,6 +565,7 @@ void TrackObject::resetAfterRewind() btTransform new_trans; m_physical_object->getMotionState()->getWorldTransform(new_trans); m_physical_object->getBody()->setCenterOfMassTransform(new_trans); + m_physical_object->getBody()->saveKinematicState(stk_config->ticks2Time(1)); } // resetAfterRewind // ----------------------------------------------------------------------------