Parcourir la source

stagger_animations

David Rose il y a 18 ans
Parent
commit
591a2096b4

+ 18 - 0
panda/src/framework/windowFramework.cxx

@@ -717,6 +717,24 @@ loop_animations(int hierarchy_match_flags) {
   _anim_controls.loop_all(true);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WindowFramework::stagger_animations
+//       Access: Public
+//  Description: Walks through all the animations that were bound by
+//               loop_animations() and staggers their play rate
+//               slightly so that they will not remain perfectly in
+//               sync.
+////////////////////////////////////////////////////////////////////
+void WindowFramework::
+stagger_animations() {
+  for (int i = 0; i < _anim_controls.get_num_anims(); ++i) {
+    AnimControl *control = _anim_controls.get_anim(i);
+    double r = (double)rand() / (double)RAND_MAX;
+    r = r * 0.2 + 0.9;
+    control->set_play_rate(r);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WindowFramework::next_anim_control
 //       Access: Public

+ 1 - 0
panda/src/framework/windowFramework.h

@@ -94,6 +94,7 @@ public:
   void loop_animations(int hierarchy_match_flags = 
                        PartGroup::HMF_ok_part_extra |
                        PartGroup::HMF_ok_anim_extra);
+  void stagger_animations();
   void next_anim_control();
   void set_anim_controls(bool enable);
   INLINE bool get_anim_controls() const;