David Rose 24 anni fa
parent
commit
c919dcf228
2 ha cambiato i file con 56 aggiunte e 15 eliminazioni
  1. 52 13
      panda/src/chan/animControl.cxx
  2. 4 2
      panda/src/chan/animControl.h

+ 52 - 13
panda/src/chan/animControl.cxx

@@ -208,8 +208,8 @@ pingpong(bool restart, int from, int to) {
 
 
   _actions = _user_actions;
   _actions = _user_actions;
 
 
-  insert_reverse_action(_actions, (to-1+get_num_frames())%get_num_frames());
-  insert_reverse_action(_actions, (to+1)%get_num_frames());
+  insert_forward_action(_actions, from);
+  insert_backward_action(_actions, to);
 
 
   get_part()->control_activated(this);
   get_part()->control_activated(this);
   if (restart) {
   if (restart) {
@@ -494,16 +494,32 @@ insert_jump_action(Actions &actions, int frame, int jump_to) {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: AnimControl::insert_reverse_action
+//     Function: AnimControl::insert_forward_action
 //       Access: Private, Static
 //       Access: Private, Static
-//  Description: Inserts a "reverse" action at the indicated frame
-//               number.  The animation will stop and go back the
-//               other direction when it reaches the indicated frame.
+//  Description: Inserts a "forward" action at the indicated frame
+//               number.  When the animation hits this action while
+//               playing in a backward direction, it will stop and
+//               play in a forward direction instead.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void AnimControl::
 void AnimControl::
-insert_reverse_action(Actions &actions, int frame) {
+insert_forward_action(Actions &actions, int frame) {
   Action new_action;
   Action new_action;
-  new_action._type = AT_reverse;
+  new_action._type = AT_forward;
+  actions.insert(pair<int, Action>(frame, new_action));
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AnimControl::insert_backward_action
+//       Access: Private, Static
+//  Description: Inserts a "backward" action at the indicated frame
+//               number.  When the animation hits this action while
+//               playing in a forward direction, it will stop and
+//               play in a backward direction instead.
+////////////////////////////////////////////////////////////////////
+void AnimControl::
+insert_backward_action(Actions &actions, int frame) {
+  Action new_action;
+  new_action._type = AT_backward;
   actions.insert(pair<int, Action>(frame, new_action));
   actions.insert(pair<int, Action>(frame, new_action));
 }
 }
 
 
@@ -637,11 +653,28 @@ do_action(int frame, const Action &action,
   switch (action._type) {
   switch (action._type) {
   case AT_stop:
   case AT_stop:
   case AT_jump:
   case AT_jump:
-  case AT_reverse:
     sequence_frame = frame;
     sequence_frame = frame;
     sequence_action = &action;
     sequence_action = &action;
     break;
     break;
 
 
+  case AT_forward:
+    // We only see "forward" actions if we're currently playing
+    // backwards.
+    if (_play_rate < 0.0) {
+      sequence_frame = frame;
+      sequence_action = &action;
+    }
+    break;
+
+  case AT_backward:
+    // We only see "backward" actions if we're currently playing
+    // forwards.
+    if (_play_rate > 0.0) {
+      sequence_frame = frame;
+      sequence_action = &action;
+    }
+    break;
+
   case AT_event:
   case AT_event:
     throw_event(action._event);
     throw_event(action._event);
     break;
     break;
@@ -662,7 +695,7 @@ do_action(int frame, const Action &action,
 //               that frame first.
 //               that frame first.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void AnimControl::
 void AnimControl::
-do_sequence_action(int, const Action &action) {
+do_sequence_action(int frame, const Action &action) {
   switch (action._type) {
   switch (action._type) {
   case AT_stop:
   case AT_stop:
     stop();
     stop();
@@ -672,8 +705,10 @@ do_sequence_action(int, const Action &action) {
     set_frame(action._jump_to);
     set_frame(action._jump_to);
     break;
     break;
 
 
-  case AT_reverse:
+  case AT_forward:
+  case AT_backward:
     _play_rate = -_play_rate;
     _play_rate = -_play_rate;
+    set_frame(frame);
     break;
     break;
 
 
   case AT_event:
   case AT_event:
@@ -703,8 +738,12 @@ output(ostream &out) const {
     out << "jump to " << _jump_to;
     out << "jump to " << _jump_to;
     break;
     break;
 
 
-  case AT_reverse:
-    out << "reverse";
+  case AT_forward:
+    out << "forward";
+    break;
+
+  case AT_backward:
+    out << "backward";
     break;
     break;
 
 
   default:
   default:

+ 4 - 2
panda/src/chan/animControl.h

@@ -93,7 +93,8 @@ private:
     AT_event,
     AT_event,
     AT_stop,
     AT_stop,
     AT_jump,
     AT_jump,
-    AT_reverse,
+    AT_forward,
+    AT_backward,
   };
   };
 
 
 #ifdef WIN32_VC
 #ifdef WIN32_VC
@@ -115,7 +116,8 @@ private:
   static void insert_event_action(Actions &actions, int frame, const CPT_Event &event);
   static void insert_event_action(Actions &actions, int frame, const CPT_Event &event);
   static void insert_stop_action(Actions &actions, int frame);
   static void insert_stop_action(Actions &actions, int frame);
   static void insert_jump_action(Actions &actions, int frame, int jump_to);
   static void insert_jump_action(Actions &actions, int frame, int jump_to);
-  static void insert_reverse_action(Actions &actions, int frame);
+  static void insert_forward_action(Actions &actions, int frame);
+  static void insert_backward_action(Actions &actions, int frame);
 
 
   void set_frame(double frame);
   void set_frame(double frame);