Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/chan/animControl.h

Go to the documentation of this file.
00001 // Filename: animControl.h
00002 // Created by:  drose (19Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
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 //       Class : AnimControl
00041 // Description : Controls the timing of a character animation.  An
00042 //               AnimControl object is created for each
00043 //               character/bundle binding and manages the state of the
00044 //               animation: whether started, stopped, or looping, and
00045 //               the current frame number and play rate.
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   // The following functions aren't really part of the public
00079   // interface; they're just public so we don't have to declare a
00080   // bunch of friends.
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   // This is a PT(PartGroup) instead of a PT(PartBundle), just because
00136   // we can't include partBundle.h for circular reasons.  But it
00137   // actually keeps a pointer to a PartBundle.
00138   PT(PartGroup) _part;
00139   PT(AnimBundle) _anim;
00140   int _channel_index;
00141 
00142   double _play_rate;
00143 
00144   // We keep a floating-point frame number.  This increments fluidly,
00145   // and records honest "between-frame" increments.  However, whenever
00146   // we report the current frame number, we just report the integer
00147   // portion.
00148   double _frame;
00149   double _as_of_time;
00150 
00151   bool _playing;
00152 
00153   // This is the frame number as of the last call to mark_channels().
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

Generated on Fri May 2 00:35:03 2003 for Panda by doxygen1.3