00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef ANIMCONTROL_H
00020 #define ANIMCONTROL_H
00021
00022 #include <pandabase.h>
00023
00024 #include "animBundle.h"
00025 #include "partGroup.h"
00026
00027 #include <clockObject.h>
00028 #include <typedef.h>
00029 #include <referenceCount.h>
00030 #include <event.h>
00031 #include <pt_Event.h>
00032 #include <cmath.h>
00033 #include <string>
00034 #include "pmap.h"
00035
00036 class PartBundle;
00037 class AnimChannelBase;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class EXPCL_PANDA AnimControl : public ReferenceCount {
00048 public:
00049 AnimControl(PartBundle *part, AnimBundle *anim, int channel_index);
00050
00051 PUBLISHED:
00052 ~AnimControl();
00053 void play(const CPT_Event &stop_event = NULL);
00054 void play(int from, int to, const CPT_Event &stop_event = NULL);
00055 void loop(bool restart);
00056 void loop(bool restart, int from, int to);
00057 void pingpong(bool restart, int from, int to);
00058 void stop();
00059 void pose(int frame);
00060
00061 void add_event(int frame, const CPT_Event &event);
00062 int remove_event(const string &event_name);
00063 void remove_all_events();
00064
00065 INLINE void set_play_rate(double play_rate);
00066 INLINE double get_play_rate() const;
00067 INLINE double get_frame_rate() const;
00068
00069 INLINE int get_frame() const;
00070 INLINE int get_num_frames() const;
00071
00072 INLINE bool is_playing() const;
00073
00074 PartBundle *get_part() const;
00075 INLINE AnimBundle *get_anim() const;
00076
00077 public:
00078
00079
00080
00081
00082 void advance_time(double time);
00083
00084 bool channel_has_changed(AnimChannelBase *channel) const;
00085 void mark_channels();
00086
00087 INLINE int get_channel_index() const;
00088
00089 void output(ostream &out) const;
00090
00091 private:
00092
00093 enum ActionType {
00094 AT_event,
00095 AT_stop,
00096 AT_jump,
00097 AT_forward,
00098 AT_backward,
00099 };
00100
00101 #ifdef WIN32_VC
00102 public:
00103 #endif
00104
00105 class EXPCL_PANDA Action {
00106 public:
00107 ActionType _type;
00108 CPT_Event _event;
00109 int _jump_to;
00110
00111 void output(ostream &out) const;
00112 };
00113
00114 private:
00115 typedef pmultimap<int, Action> Actions;
00116
00117 static void insert_event_action(Actions &actions, int frame, const CPT_Event &event);
00118 static void insert_stop_action(Actions &actions, int frame);
00119 static void insert_jump_action(Actions &actions, int frame, int jump_to);
00120 static void insert_forward_action(Actions &actions, int frame);
00121 static void insert_backward_action(Actions &actions, int frame);
00122
00123 void set_frame(double frame);
00124
00125 bool do_actions_forward(int from, int to);
00126 bool do_actions_backward(int from, int to);
00127
00128 void do_action(int frame, const Action &action,
00129 int &sequence_frame, const Action *&sequence_action);
00130 void do_sequence_action(int frame, const Action &action);
00131
00132 Actions _actions;
00133 Actions _user_actions;
00134
00135
00136
00137
00138 PT(PartGroup) _part;
00139 PT(AnimBundle) _anim;
00140 int _channel_index;
00141
00142 double _play_rate;
00143
00144
00145
00146
00147
00148 double _frame;
00149 double _as_of_time;
00150
00151 bool _playing;
00152
00153
00154 int _marked_frame;
00155
00156 public:
00157 static TypeHandle get_class_type() {
00158 return _type_handle;
00159 }
00160 static void init_type() {
00161 ReferenceCount::init_type();
00162 register_type(_type_handle, "AnimControl",
00163 ReferenceCount::get_class_type());
00164 }
00165
00166 private:
00167 static TypeHandle _type_handle;
00168
00169 friend inline ostream &operator << (ostream &, const AnimControl::Action &);
00170 friend class AnimControl::Action;
00171 };
00172
00173 inline ostream &operator << (ostream &out, const AnimControl &ac) {
00174 ac.output(out);
00175 return out;
00176 }
00177
00178 inline ostream &operator << (ostream &out, const AnimControl::Action &action) {
00179 action.output(out);
00180 return out;
00181 }
00182
00183 #include "animControl.I"
00184
00185 #endif