40 _num_frames(copy._num_frames),
59 get_num_frames()
const {
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);
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
float cmod(float x, float y)
This is similar to fmod(), but it behaves properly when x is negative: that is, it always returns a v...
bool get_bool()
Extracts a boolean value.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void read_cdata(DatagramIterator &scan, PipelineCyclerBase &cycler)
Reads in the indicated CycleData object.
A single page of data maintained by a PipelineCycler.
void write_cdata(Datagram &packet, const PipelineCyclerBase &cycler)
Writes out the indicated CycleData object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
int32_t get_int32()
Extracts a signed 32-bit integer.
This is the fundamental interface for things that have a play/loop/stop type interface for frame-base...
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void add_bool(bool value)
Adds a boolean value to the datagram.
get_frame_time
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.