Restore linear and angular velocities of 3d animation physical objects

This commit is contained in:
Benau 2019-12-10 13:35:43 +08:00
parent c09585eaf7
commit 0b480e7a71
2 changed files with 7 additions and 1 deletions

View File

@ -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);

View File

@ -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
// ----------------------------------------------------------------------------