40 _num_frames(copy._num_frames),
67 output(std::ostream &out)
const {
68 CDReader cdata(_cycler);
77 animation_activated() {
103 AnimInterface::CData::
113 _effective_frame_rate(0.0),
122 AnimInterface::CData::
123 CData(
const AnimInterface::CData ©) :
124 _frame_rate(copy._frame_rate),
125 _play_mode(copy._play_mode),
126 _start_time(copy._start_time),
127 _start_frame(copy._start_frame),
128 _play_frames(copy._play_frames),
129 _from_frame(copy._from_frame),
130 _to_frame(copy._to_frame),
131 _play_rate(copy._play_rate),
132 _effective_frame_rate(copy._effective_frame_rate),
133 _paused(copy._paused),
134 _paused_f(copy._paused_f)
143 return new CData(*
this);
150 void AnimInterface::CData::
168 void AnimInterface::CData::
178 _effective_frame_rate = _frame_rate * _play_rate;
191 void AnimInterface::CData::
192 play(
double from,
double to) {
198 _play_mode = PM_play;
201 _play_frames = to - from + 1.0;
202 _from_frame = (int)floor(from);
203 _to_frame = (int)floor(to);
206 if (_effective_frame_rate < 0.0) {
208 _start_time -= _play_frames / _effective_frame_rate;
217 void AnimInterface::CData::
218 loop(
bool restart,
double from,
double to) {
224 double fframe = get_full_fframe();
226 _play_mode = PM_loop;
229 _play_frames = to - from + 1.0;
230 _from_frame = (int)floor(from);
231 _to_frame = (int)floor(to);
235 fframe = min(max(fframe, from), to);
237 _paused_f = fframe - _start_frame;
239 _start_time -= (fframe - _start_frame) / _effective_frame_rate;
248 void AnimInterface::CData::
249 pingpong(
bool restart,
double from,
double to) {
255 double fframe = get_full_fframe();
257 _play_mode = PM_pingpong;
260 _play_frames = to - from + 1.0;
261 _from_frame = (int)floor(from);
262 _to_frame = (int)floor(to);
266 fframe = min(max(fframe, from), to);
268 _paused_f = fframe - _start_frame;
270 _start_time -= (fframe - _start_frame) / _effective_frame_rate;
278 void AnimInterface::CData::
280 _play_mode = PM_pose;
282 _start_frame = frame;
284 _from_frame = (int)floor(frame);
285 _to_frame = (int)floor(frame);
299 int AnimInterface::CData::
300 get_full_frame(
int increment)
const {
301 int frame = (int)floor(get_full_fframe()) + increment;
302 if (_play_mode == PM_play) {
305 frame = min(max(frame, _from_frame), _to_frame);
322 double AnimInterface::CData::
323 get_full_fframe()
const {
324 switch (_play_mode) {
329 return min(max(get_f(), 0.0), _play_frames) + _start_frame;
332 nassertr(_play_frames >= 0.0, 0.0);
333 return cmod(get_f(), _play_frames) + _start_frame;
337 nassertr(_play_frames >= 0.0, 0.0);
338 double f =
cmod(get_f(), _play_frames * 2.0);
339 if (f > _play_frames) {
340 return (_play_frames * 2.0 - f) + _start_frame;
342 return f + _start_frame;
355 bool AnimInterface::CData::
357 switch (_play_mode) {
362 if (_effective_frame_rate < 0.0) {
366 return get_f() < _play_frames;
380 void AnimInterface::CData::
381 output(std::ostream &out)
const {
382 switch (_play_mode) {
384 out <<
"pose, frame " << get_full_fframe();
388 out <<
"play, frame " << get_full_fframe();
392 out <<
"loop, frame " << get_full_fframe();
396 out <<
"pingpong, frame " << get_full_fframe();
406 void AnimInterface::CData::
407 internal_set_rate(
double frame_rate,
double play_rate) {
410 _frame_rate = frame_rate;
411 _play_rate = play_rate;
412 _effective_frame_rate = frame_rate * play_rate;
414 if (_effective_frame_rate == 0.0) {
421 double new_elapsed = f / _effective_frame_rate;
423 _start_time = now - new_elapsed;
432 double AnimInterface::CData::
439 double elapsed = now - _start_time;
440 return (elapsed * _effective_frame_rate);