Panda3D
animControlCollection.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file animControlCollection.I
10  * @author drose
11  * @date 2000-02-22
12  */
13 
14 /**
15  * Starts the named animation playing.
16  */
17 INLINE bool AnimControlCollection::
18 play(const std::string &anim_name) {
19  AnimControl *control = find_anim(anim_name);
20  if (control == nullptr) {
21  return false;
22  }
23  _last_started_control = control;
24  control->play();
25  return true;
26 }
27 
28 /**
29  * Starts the named animation playing.
30  */
31 INLINE bool AnimControlCollection::
32 play(const std::string &anim_name, double from, double to) {
33  AnimControl *control = find_anim(anim_name);
34  if (control == nullptr) {
35  return false;
36  }
37  _last_started_control = control;
38  control->play(from, to);
39  return true;
40 }
41 
42 /**
43  * Starts the named animation looping.
44  */
45 INLINE bool AnimControlCollection::
46 loop(const std::string &anim_name, bool restart) {
47  AnimControl *control = find_anim(anim_name);
48  if (control == nullptr) {
49  return false;
50  }
51  _last_started_control = control;
52  control->loop(restart);
53  return true;
54 }
55 
56 /**
57  * Starts the named animation looping.
58  */
59 INLINE bool AnimControlCollection::
60 loop(const std::string &anim_name, bool restart, double from, double to) {
61  AnimControl *control = find_anim(anim_name);
62  if (control == nullptr) {
63  return false;
64  }
65  _last_started_control = control;
66  control->loop(restart, from, to);
67  return true;
68 }
69 
70 /**
71  * Stops the named animation.
72  */
73 INLINE bool AnimControlCollection::
74 stop(const std::string &anim_name) {
75  AnimControl *control = find_anim(anim_name);
76  if (control == nullptr) {
77  return false;
78  }
79  control->stop();
80  return true;
81 }
82 
83 
84 /**
85  * Sets to a particular frame in the named animation.
86  */
87 INLINE bool AnimControlCollection::
88 pose(const std::string &anim_name, double frame) {
89  AnimControl *control = find_anim(anim_name);
90  if (control == nullptr) {
91  return false;
92  }
93  _last_started_control = control;
94  control->pose(frame);
95  return true;
96 }
97 
98 /**
99  * Returns the current frame in the named animation, or 0 if the animation is
100  * not found.
101  */
102 INLINE int AnimControlCollection::
103 get_frame(const std::string &anim_name) const {
104  AnimControl *control = find_anim(anim_name);
105  if (control == nullptr) {
106  return 0;
107  }
108  return control->get_frame();
109 }
110 
111 /**
112  * Returns the current frame in the last-started animation.
113  */
114 INLINE int AnimControlCollection::
115 get_frame() const {
116  if (_last_started_control == nullptr) {
117  return 0;
118  }
119  return _last_started_control->get_frame();
120 }
121 
122 /**
123  * Returns true if the named animation is currently playing, false otherwise.
124  */
125 INLINE bool AnimControlCollection::
126 is_playing(const std::string &anim_name) const {
127  AnimControl *control = find_anim(anim_name);
128  if (control == nullptr) {
129  return false;
130  }
131  return control->is_playing();
132 }
133 
134 /**
135  * Returns true if the last-started animation is currently playing, false
136  * otherwise.
137  */
138 INLINE bool AnimControlCollection::
139 is_playing() const {
140  if (_last_started_control == nullptr) {
141  return false;
142  }
143  return _last_started_control->is_playing();
144 }
145 
146 /**
147  * Returns the total number of frames in the named animation, or 0 if the
148  * animation is not found.
149  */
150 INLINE int AnimControlCollection::
151 get_num_frames(const std::string &anim_name) const {
152  AnimControl *control = find_anim(anim_name);
153  if (control == nullptr) {
154  return 0;
155  }
156  return control->get_num_frames();
157 }
158 
159 /**
160  * Returns the total number of frames in the last-started animation.
161  */
162 INLINE int AnimControlCollection::
163 get_num_frames() const {
164  if (_last_started_control == nullptr) {
165  return 0;
166  }
167  return _last_started_control->get_num_frames();
168 }
169 
170 INLINE std::ostream &
171 operator << (std::ostream &out, const AnimControlCollection &collection) {
172  collection.output(out);
173  return out;
174 }
int get_frame() const
Returns the current frame in the last-started animation.
void loop(bool restart)
Starts the entire animation looping.
Definition: animInterface.I:45
bool play(const std::string &anim_name)
Starts the named animation playing.
bool stop(const std::string &anim_name)
Stops the named animation.
bool is_playing() const
Returns true if the last-started animation is currently playing, false otherwise.
void stop()
Stops a currently playing or looping animation right where it is.
Definition: animInterface.I:91
bool loop(const std::string &anim_name, bool restart)
Starts the named animation looping.
This is a named collection of AnimControl pointers.
get_frame
Returns the current integer frame number.
Definition: animInterface.h:70
AnimControl * find_anim(const std::string &name) const
Returns the AnimControl associated with the given name, or NULL if no such control has been associate...
int get_num_frames() const
Returns the total number of frames in the last-started animation.
is_playing
Returns true if the animation is currently playing, false if it is stopped (e.g.
Definition: animInterface.h:75
get_num_frames
Returns the number of frames in the animation.
Definition: animInterface.h:68
void pose(double frame)
Sets the animation to the indicated frame and holds it there.
Controls the timing of a character animation.
Definition: animControl.h:38
void play()
Runs the entire animation from beginning to end and stops.
Definition: animInterface.I:18
bool pose(const std::string &anim_name, double frame)
Sets to a particular frame in the named animation.