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