15 #include "animInterface.h" 16 #include "clockObject.h" 17 #include "bamReader.h" 18 #include "bamWriter.h" 20 #include "datagramIterator.h" 42 _num_frames(copy._num_frames),
77 output(ostream &out)
const {
90 animation_activated() {
123 AnimInterface::CData::
133 _effective_frame_rate(0.0),
144 AnimInterface::CData::
145 CData(
const AnimInterface::CData ©) :
146 _frame_rate(copy._frame_rate),
147 _play_mode(copy._play_mode),
148 _start_time(copy._start_time),
149 _start_frame(copy._start_frame),
150 _play_frames(copy._play_frames),
151 _from_frame(copy._from_frame),
152 _to_frame(copy._to_frame),
153 _play_rate(copy._play_rate),
154 _effective_frame_rate(copy._effective_frame_rate),
155 _paused(copy._paused),
156 _paused_f(copy._paused_f)
167 return new CData(*
this);
176 void AnimInterface::CData::
197 void AnimInterface::CData::
207 _effective_frame_rate = _frame_rate * _play_rate;
225 void AnimInterface::CData::
226 play(
double from,
double to) {
232 _play_mode = PM_play;
235 _play_frames = to - from + 1.0;
236 _from_frame = (int)floor(from);
237 _to_frame = (int)floor(to);
240 if (_effective_frame_rate < 0.0) {
242 _start_time -= _play_frames / _effective_frame_rate;
255 void AnimInterface::CData::
256 loop(
bool restart,
double from,
double to) {
264 _play_mode = PM_loop;
267 _play_frames = to - from + 1.0;
268 _from_frame = (int)floor(from);
269 _to_frame = (int)floor(to);
273 fframe = min(max(fframe, from), to);
275 _paused_f = fframe - _start_frame;
277 _start_time -= (fframe - _start_frame) / _effective_frame_rate;
289 void AnimInterface::CData::
290 pingpong(
bool restart,
double from,
double to) {
298 _play_mode = PM_pingpong;
301 _play_frames = to - from + 1.0;
302 _from_frame = (int)floor(from);
303 _to_frame = (int)floor(to);
307 fframe = min(max(fframe, from), to);
309 _paused_f = fframe - _start_frame;
311 _start_time -= (fframe - _start_frame) / _effective_frame_rate;
322 void AnimInterface::CData::
324 _play_mode = PM_pose;
326 _start_frame = frame;
328 _from_frame = (int)floor(frame);
329 _to_frame = (int)floor(frame);
348 int AnimInterface::CData::
349 get_full_frame(
int increment)
const {
351 if (_play_mode == PM_play) {
354 frame = min(max(frame, _from_frame), _to_frame);
375 double AnimInterface::CData::
376 get_full_fframe()
const {
377 switch (_play_mode) {
382 return min(max(get_f(), 0.0), _play_frames) + _start_frame;
385 nassertr(_play_frames >= 0.0, 0.0);
386 return cmod(get_f(), _play_frames) + _start_frame;
390 nassertr(_play_frames >= 0.0, 0.0);
391 double f = cmod(get_f(), _play_frames * 2.0);
392 if (f > _play_frames) {
393 return (_play_frames * 2.0 - f) + _start_frame;
395 return f + _start_frame;
411 bool AnimInterface::CData::
413 switch (_play_mode) {
418 if (_effective_frame_rate < 0.0) {
422 return get_f() < _play_frames;
438 void AnimInterface::CData::
439 output(ostream &out)
const {
440 switch (_play_mode) {
466 void AnimInterface::CData::
467 internal_set_rate(
double frame_rate,
double play_rate) {
470 _frame_rate = frame_rate;
471 _play_rate = play_rate;
472 _effective_frame_rate = frame_rate * play_rate;
474 if (_effective_frame_rate == 0.0) {
481 double new_elapsed = f / _effective_frame_rate;
483 _start_time = now - new_elapsed;
494 double AnimInterface::CData::
501 double elapsed = now - _start_time;
502 return (elapsed * _effective_frame_rate);
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
void add_uint8(PN_uint8 value)
Adds an unsigned 8-bit integer to the datagram.
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...
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.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
double get_frame_time(Thread *current_thread=Thread::get_current_thread()) const
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
PN_int32 get_int32()
Extracts a signed 32-bit integer.
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
This is the fundamental interface for things that have a play/loop/stop type interface for frame-base...
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
double get_full_fframe() const
Returns the current floating-point frame number.
void add_bool(bool value)
Adds a boolean value to the datagram.
virtual int get_num_frames() const
Returns the number of frames in the animation.
void pose(double frame)
Sets the animation to the indicated frame and holds it there.
void add_int32(PN_int32 value)
Adds a signed 32-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 ...