From dce135ab1061b7fcddba6a4524c4a78879ac60b9 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 21 Dec 2001 19:34:15 +0000 Subject: [PATCH] fix backward animation playing --- panda/src/chan/animControl.I | 5 ++++- panda/src/chan/animControl.cxx | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/panda/src/chan/animControl.I b/panda/src/chan/animControl.I index 08a52d7dc5..3c333f3199 100644 --- a/panda/src/chan/animControl.I +++ b/panda/src/chan/animControl.I @@ -72,7 +72,10 @@ get_frame_rate() const { //////////////////////////////////////////////////////////////////// INLINE int AnimControl:: get_frame() const { - return (int)(_frame + 0.0001); + // We have to use floor() here instead of simply casting the number + // to an integer, becase the frame number might have become + // negative. + return (int)floor(_frame + 0.0001); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/chan/animControl.cxx b/panda/src/chan/animControl.cxx index 3c5e6d8372..fc1cad45eb 100644 --- a/panda/src/chan/animControl.cxx +++ b/panda/src/chan/animControl.cxx @@ -382,7 +382,12 @@ advance_time(double time) { do_actions_backward(orig_frame-1, new_frame); } else { if (do_actions_backward(orig_frame-1, 0)) { - _frame = _frame - (int)(_frame / num_frames) * num_frames; + // floor() is correct here, instead of simply an integer + // cast, because we are using floating-point arithmetic + // anyway (no need to convert to integer format and back + // again), and because we need correct behavior when the + // frame number is negative. + _frame = _frame - floor(_frame / num_frames) * num_frames; new_frame = get_frame(); do_actions_backward(get_num_frames(), new_frame); } @@ -394,7 +399,12 @@ advance_time(double time) { do_actions_forward(orig_frame+1, new_frame); } else { if (do_actions_forward(orig_frame+1, get_num_frames()-1)) { - _frame = _frame - (int)(_frame / num_frames) * num_frames; + // floor() is correct here, instead of simply an integer + // cast, because we are using floating-point arithmetic + // anyway (no need to convert to integer format and back + // again), and because we need correct behavior when the + // frame number is negative. + _frame = _frame - floor(_frame / num_frames) * num_frames; new_frame = get_frame(); do_actions_forward(0, new_frame); }