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

panda/src/chan/partBundle.h

Go to the documentation of this file.
00001 // Filename: partBundle.h
00002 // Created by:  drose (22Feb99)
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 PARTBUNDLE_H
00020 #define PARTBUNDLE_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "partGroup.h"
00025 #include "animControl.h"
00026 #include "animControlCollection.h"
00027 
00028 #include "pointerTo.h"
00029 #include "iterator_types.h"
00030 
00031 class AnimBundle;
00032 class PartBundleNode;
00033 class PartBundleNode;
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //       Class : PartBundle
00037 // Description : This is the root of a MovingPart hierarchy.  It
00038 //               defines the hierarchy of moving parts that make up an
00039 //               animatable object.
00040 ////////////////////////////////////////////////////////////////////
00041 class EXPCL_PANDA PartBundle : public PartGroup, public AnimControlCollection {
00042 public:
00043 
00044   // This is passed down through the MovingParts during the
00045   // do_update() call to specify the channels that are in effect.
00046   typedef pmap<AnimControl *, float> ChannelBlend;
00047 
00048   typedef first_of_pair_iterator<ChannelBlend::const_iterator> control_iterator;
00049   typedef ChannelBlend::size_type control_size_type;
00050 
00051 protected:
00052   // The copy constructor is protected; use make_copy() or copy_subgraph().
00053   PartBundle(const PartBundle &copy);
00054 
00055 public:
00056   PartBundle(const string &name = "");
00057   virtual PartGroup *make_copy() const;
00058 
00059 PUBLISHED:
00060 
00061   // This is the parameter to set_blend_type() and specifies the kind
00062   // of blending operation to be performed when multiple controls are
00063   // in effect simultaneously (see set_control_effect()).
00064   enum BlendType {
00065 
00066     // BT_single means no blending is performed.  Only one AnimControl
00067     // is allowed to be set at a time in set_control_effect().  In
00068     // this mode, and this mode only, activating a particular
00069     // AnimControl (via play(), loop(), or pose()) will implicitly set
00070     // the bundle's control_effect to 100% of that particular
00071     // AnimControl, removing any AnimControls previously set.  In
00072     // other modes, the control_effect must be set manually.
00073     BT_single,
00074 
00075     // BT_linear does a componentwise average of all blended matrices,
00076     // which is a linear blend.  The result of this is that if a
00077     // particular vertex would have been at point P in one animation
00078     // and point Q in another one, it will end up on the line in
00079     // between them in the resulting blend animation.  However, this
00080     // tends to stretch and squash limbs in strange and disturbing
00081     // ways.
00082     BT_linear,
00083 
00084     // BT_normalized_linear is a compromise on BT_linear.  The matrix
00085     // is blended linearly without the scale component, and the
00086     // blended scale component is applied separately.  This keeps all
00087     // of the character's body parts in the correct size and shape.
00088     // However, if the hierarchy is disconnected, body parts can fly
00089     // off.  It's essential the skeleton hierarchy be completely
00090     // connected to use this blend mode successully.
00091     BT_normalized_linear,
00092   };
00093 
00094   void set_blend_type(BlendType bt);
00095   INLINE BlendType get_blend_type() const;
00096 
00097   INLINE PartBundleNode *get_node() const;
00098 
00099   void clear_control_effects();
00100   void set_control_effect(AnimControl *control, float effect);
00101   float get_control_effect(AnimControl *control);
00102 
00103   virtual void output(ostream &out) const;
00104   virtual void write(ostream &out, int indent_level) const;
00105 
00106   PT(AnimControl) bind_anim(AnimBundle *anim,
00107                             int hierarchy_match_flags = 0);
00108 
00109   bool bind_anim(AnimBundle *anim, const string &name,
00110                  int hierarchy_match_flags = 0);
00111 
00112 public:
00113   // The following functions may be used to traverse the set of
00114   // controls applied to the PartBundle.  Beware!  These are not safe
00115   // to use outside of PANDA.DLL.
00116   INLINE control_iterator control_begin() const;
00117   INLINE control_iterator control_end() const;
00118   INLINE control_size_type control_size() const;
00119 
00120   INLINE const ChannelBlend &get_blend_map() const;
00121 
00122   // The following functions aren't really part of the public
00123   // interface; they're just public so we don't have to declare a
00124   // bunch of friends.
00125 
00126   void advance_time(double time);
00127   bool update();
00128   bool force_update();
00129   virtual void control_activated(AnimControl *control);
00130 
00131 protected:
00132   void recompute_net_blend();
00133   void clear_and_stop_except(AnimControl *control);
00134 
00135   BlendType _blend_type;
00136   PartBundleNode *_node;
00137 
00138   AnimControl *_last_control_set;
00139   ChannelBlend _blend;
00140   float _net_blend;
00141   bool _anim_changed;
00142 
00143 public:
00144   static void register_with_read_factory(void);
00145   virtual void finalize();
00146 
00147   static TypedWritable *make_PartBundle(const FactoryParams &params);
00148 
00149 public:
00150 
00151   virtual TypeHandle get_type() const {
00152     return get_class_type();
00153   }
00154   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00155   static TypeHandle get_class_type() {
00156     return _type_handle;
00157   }
00158   static void init_type() {
00159     PartGroup::init_type();
00160     register_type(_type_handle, "PartBundle",
00161                   PartGroup::get_class_type());
00162   }
00163 
00164 private:
00165   static TypeHandle _type_handle;
00166 
00167   friend class PartBundleNode;
00168 };
00169 
00170 inline ostream &operator <<(ostream &out, const PartBundle &bundle) {
00171   bundle.output(out);
00172   return out;
00173 }
00174 
00175 #include "partBundle.I"
00176 
00177 #endif

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