Panda3D

characterJoint.h

00001 // Filename: characterJoint.h
00002 // Created by:  drose (23Feb99)
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 CHARACTERJOINT_H
00016 #define CHARACTERJOINT_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "movingPartMatrix.h"
00021 #include "pandaNode.h"
00022 #include "nodePathCollection.h"
00023 #include "ordered_vector.h"
00024 
00025 class JointVertexTransform;
00026 class Character;
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : CharacterJoint
00030 // Description : This represents one joint of the character's
00031 //               animation, containing an animating transform matrix.
00032 ////////////////////////////////////////////////////////////////////
00033 class EXPCL_PANDA_CHAR CharacterJoint : public MovingPartMatrix {
00034 protected:
00035   CharacterJoint();
00036   CharacterJoint(const CharacterJoint &copy);
00037 
00038 PUBLISHED:
00039   CharacterJoint(Character *character,
00040                  PartBundle *root, PartGroup *parent, const string &name,
00041                  const LMatrix4f &default_value);
00042   virtual ~CharacterJoint();
00043 
00044 public:
00045   virtual bool is_character_joint() const;
00046   virtual PartGroup *make_copy() const;
00047 
00048   virtual bool update_internals(PartBundle *root, PartGroup *parent, 
00049                                 bool self_changed, bool parent_changed, 
00050                                 Thread *current_thread);
00051   virtual void do_xform(const LMatrix4f &mat, const LMatrix4f &inv_mat);
00052 
00053 PUBLISHED:
00054   bool add_net_transform(PandaNode *node);
00055   bool remove_net_transform(PandaNode *node);
00056   bool has_net_transform(PandaNode *node) const;
00057   void clear_net_transforms();
00058   NodePathCollection get_net_transforms();
00059 
00060   bool add_local_transform(PandaNode *node);
00061   bool remove_local_transform(PandaNode *node);
00062   bool has_local_transform(PandaNode *node) const;
00063   void clear_local_transforms();
00064   NodePathCollection get_local_transforms();
00065 
00066   void get_transform(LMatrix4f &transform) const;
00067   void get_net_transform(LMatrix4f &transform) const;
00068 
00069   Character *get_character() const;
00070 
00071 private:
00072   void set_character(Character *character);
00073 
00074 private:
00075   // Not a reference-counted pointer.
00076   Character *_character;
00077 
00078   typedef ov_set< PT(PandaNode) > NodeList;
00079   NodeList _net_transform_nodes;
00080   NodeList _local_transform_nodes;
00081 
00082   typedef ov_set<JointVertexTransform *> VertexTransforms;
00083   VertexTransforms _vertex_transforms;
00084 
00085 public:
00086   static void register_with_read_factory();
00087   virtual void write_datagram(BamWriter* manager, Datagram &me);
00088   virtual int complete_pointers(TypedWritable **p_list,
00089                                 BamReader *manager);
00090 
00091   static TypedWritable *make_CharacterJoint(const FactoryParams &params);
00092 
00093 protected:
00094   void fillin(DatagramIterator& scan, BamReader* manager);
00095 
00096 private:
00097   int _num_net_nodes, _num_local_nodes;
00098 
00099 public:
00100   // The _geom_node member just holds a temporary pointer to a node
00101   // for the CharacterMaker's convenenience while creating the
00102   // character.  It does not store any meaningful value after
00103   // creation is complete.
00104   PT(PandaNode) _geom_node;
00105 
00106   // These are filled in as the joint animates.
00107   LMatrix4f _net_transform;
00108   LMatrix4f _initial_net_transform_inverse;
00109 
00110 public:
00111   virtual TypeHandle get_type() const {
00112     return get_class_type();
00113   }
00114   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00115   static TypeHandle get_class_type() {
00116     return _type_handle;
00117   }
00118   static void init_type() {
00119     MovingPartMatrix::init_type();
00120     register_type(_type_handle, "CharacterJoint",
00121                   MovingPartMatrix::get_class_type());
00122   }
00123 
00124 private:
00125   static TypeHandle _type_handle;
00126 
00127   friend class Character;
00128   friend class CharacterJointBundle;
00129   friend class JointVertexTransform;
00130 };
00131 
00132 #include "characterJoint.I"
00133 
00134 #endif
00135 
00136 
 All Classes Functions Variables Enumerations