animControl.I 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Filename: animControl.I
  2. // Created by: drose (19Feb99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include <math.h>
  19. ////////////////////////////////////////////////////////////////////
  20. // Function: AnimControl::set_play_rate
  21. // Access: Published
  22. // Description: Sets the speed of the animation, relative to its
  23. // "normal" speed. Setting this number to 2.0 plays it
  24. // twice as fast, 0.5 half as fast. -1.0 plays it
  25. // backwards, and 0.0 stops it. The change is actually
  26. // retroactive to the last frame.
  27. //
  28. // If you are going to change the play_rate from a
  29. // positive number to a negative number, or vice-versa,
  30. // you should do this before starting the animation.
  31. // The various flavors of play() and loop() do slightly
  32. // different behavior based on whether play_rate is
  33. // positive or negative.
  34. ////////////////////////////////////////////////////////////////////
  35. INLINE void AnimControl::
  36. set_play_rate(double play_rate) {
  37. _play_rate = play_rate;
  38. }
  39. ////////////////////////////////////////////////////////////////////
  40. // Function: AnimControl::get_play_rate
  41. // Access: Published
  42. // Description: Returns the current speed of the animation. See
  43. // set_play_rate().
  44. ////////////////////////////////////////////////////////////////////
  45. INLINE double AnimControl::
  46. get_play_rate() const {
  47. return _play_rate;
  48. }
  49. ////////////////////////////////////////////////////////////////////
  50. // Function: AnimControl::get_frame_rate
  51. // Access: Published
  52. // Description: Returns the actual frame rate of the animation, based
  53. // on the play_rate (see set_play_rate()) and the
  54. // animation's base frame rate (see
  55. // AnimBundle::get_base_frame_rate()). This is in
  56. // frames per second.
  57. ////////////////////////////////////////////////////////////////////
  58. INLINE double AnimControl::
  59. get_frame_rate() const {
  60. return get_play_rate() * get_anim()->get_base_frame_rate();
  61. }
  62. ////////////////////////////////////////////////////////////////////
  63. // Function: AnimControl::get_frame
  64. // Access: Published
  65. // Description: Returns the current frame number of the animation.
  66. ////////////////////////////////////////////////////////////////////
  67. INLINE int AnimControl::
  68. get_frame() const {
  69. // We have to use floor() here instead of simply casting the number
  70. // to an integer, becase the frame number might have become
  71. // negative.
  72. return (int)cfloor(_frame + 0.0001);
  73. }
  74. ////////////////////////////////////////////////////////////////////
  75. // Function: AnimControl::get_num_frames
  76. // Access: Published
  77. // Description: Returns the number of frames of animation. This is
  78. // actually just extracted directly from the AnimBundle;
  79. // the function is duplicated here for convenience. The
  80. // frame number will never be outside the range 0 <=
  81. // frame < get_num_frames().
  82. ////////////////////////////////////////////////////////////////////
  83. INLINE int AnimControl::
  84. get_num_frames() const {
  85. return get_anim()->get_num_frames();
  86. }
  87. ////////////////////////////////////////////////////////////////////
  88. // Function: AnimControl::is_playing
  89. // Access: Published
  90. // Description: Returns true if the AnimControl is currently playing,
  91. // false otherwise.
  92. ////////////////////////////////////////////////////////////////////
  93. INLINE bool AnimControl::
  94. is_playing() const {
  95. return _playing;
  96. }
  97. ////////////////////////////////////////////////////////////////////
  98. // Function: AnimControl::get_anim
  99. // Access: Published
  100. // Description: Returns the AnimBundle bound in with this
  101. // AnimControl.
  102. ////////////////////////////////////////////////////////////////////
  103. INLINE AnimBundle *AnimControl::
  104. get_anim() const {
  105. return _anim;
  106. }
  107. ////////////////////////////////////////////////////////////////////
  108. // Function: AnimControl::get_channel_index
  109. // Access: Public
  110. // Description:
  111. ////////////////////////////////////////////////////////////////////
  112. INLINE int AnimControl::
  113. get_channel_index() const {
  114. return _channel_index;
  115. }