Panda3D

movingPartBase.h

00001 // Filename: movingPartBase.h
00002 // Created by:  drose (22Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef MOVINGPARTBASE_H
00016 #define MOVINGPARTBASE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "partGroup.h"
00021 #include "partBundle.h"
00022 #include "animChannelBase.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : MovingPartBase
00026 // Description : This is the base class for a single animatable piece
00027 //               that may be bound to one channel (or more, if
00028 //               blending is in effect).  It corresponds to, for
00029 //               instance, a single joint or slider of a character.
00030 //
00031 //               MovingPartBase does not have a particular value type.
00032 //               See the derived template class, MovingPart, for this.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_PANDA_CHAN MovingPartBase : public PartGroup {
00035 protected:
00036   INLINE MovingPartBase(const MovingPartBase &copy);
00037 
00038 public:
00039   MovingPartBase(PartGroup *parent, const string &name);
00040 
00041 PUBLISHED:
00042   INLINE int get_max_bound() const;
00043   INLINE AnimChannelBase *get_bound(int n) const;
00044 
00045 public:
00046   virtual TypeHandle get_value_type() const=0;
00047   virtual AnimChannelBase *make_default_channel() const=0;
00048 
00049 PUBLISHED:
00050   virtual bool clear_forced_channel();
00051   virtual AnimChannelBase *get_forced_channel() const;
00052 
00053   virtual void write(ostream &out, int indent_level) const;
00054   virtual void write_with_value(ostream &out, int indent_level) const;
00055   virtual void output_value(ostream &out) const=0;
00056 
00057 public:
00058   virtual bool do_update(PartBundle *root, const CycleData *root_cdata,
00059                          PartGroup *parent, bool parent_changed, 
00060                          bool anim_changed, Thread *current_thread);
00061 
00062   virtual void get_blend_value(const PartBundle *root)=0;
00063   virtual bool update_internals(PartBundle *root, PartGroup *parent, 
00064                                 bool self_changed, bool parent_changed, 
00065                                 Thread *current_thread);
00066 
00067 protected:
00068   MovingPartBase();
00069 
00070   virtual void pick_channel_index(plist<int> &holes, int &next) const;
00071   virtual void bind_hierarchy(AnimGroup *anim, int channel_index,
00072                               int &joint_index, bool is_included, 
00073                               BitArray &bound_joints,
00074                               const PartSubset &subset);
00075   virtual void find_bound_joints(int &joint_index, bool is_included, 
00076                                  BitArray &bound_joints,
00077                                  const PartSubset &subset);
00078   virtual void determine_effective_channels(const CycleData *root_cdata);
00079 
00080   // This is the vector of all channels bound to this part.
00081   typedef pvector< PT(AnimChannelBase) > Channels;
00082   Channels _channels;
00083 
00084   // This is the number of channels in the above _channels vector that
00085   // actually have an effect on this part.
00086   int _num_effective_channels;
00087 
00088   // This is the single channel that has an effect on this part, as
00089   // determined by determine_effective_channels().  It is only set if
00090   // there is exactly one channel that affects this part
00091   // (i.e. _num_effective_channels is 1).  If there are multiple
00092   // channels, or no channels at all, it is NULL.
00093   AnimControl *_effective_control;
00094   PT(AnimChannelBase) _effective_channel;
00095 
00096   // This is the particular channel that's been forced to this part,
00097   // via set_forced_channel().  It overrides all of the above if set.
00098   PT(AnimChannelBase) _forced_channel;
00099 
00100 public:
00101   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00102   virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
00103 
00104 protected:
00105   void fillin(DatagramIterator &scan, BamReader *manager);
00106 
00107 public:
00108   virtual TypeHandle get_type() const {
00109     return get_class_type();
00110   }
00111   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00112 PUBLISHED:
00113   static TypeHandle get_class_type() {
00114     return _type_handle;
00115   }
00116 public:
00117   static void init_type() {
00118     PartGroup::init_type();
00119     register_type(_type_handle, "MovingPartBase",
00120                   PartGroup::get_class_type());
00121   }
00122 
00123 private:
00124   static TypeHandle _type_handle;
00125 };
00126 
00127 #include "movingPartBase.I"
00128 
00129 #endif
00130 
00131 
00132 
00133 
 All Classes Functions Variables Enumerations