Panda3D
 All Classes Functions Variables Enumerations
animChannel.h
00001 // Filename: animChannel.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 ANIMCHANNEL_H
00016 #define ANIMCHANNEL_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "animChannelBase.h"
00021 
00022 #include "luse.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : AnimChannel
00026 // Description : This template class is the parent class for all kinds
00027 //               of AnimChannels that return different values.
00028 ////////////////////////////////////////////////////////////////////
00029 template<class SwitchType>
00030 class AnimChannel : public AnimChannelBase {
00031 protected:
00032   // The default constructor is protected: don't try to create an
00033   // AnimChannel without a parent.  To create an AnimChannel hierarchy,
00034   // you must first create an AnimBundle, and use that to create any
00035   // subsequent children.
00036   INLINE AnimChannel(const string &name = "");
00037   INLINE AnimChannel(AnimGroup *parent, const AnimChannel &copy);
00038 public:
00039   typedef TYPENAME SwitchType::ValueType ValueType;
00040 
00041   INLINE AnimChannel(AnimGroup *parent, const string &name);
00042   INLINE ~AnimChannel();
00043 
00044 PUBLISHED:
00045   virtual void get_value(int frame, ValueType &value)=0;
00046 
00047   // These transform-component methods only have meaning for matrix types.
00048   virtual void get_value_no_scale_shear(int frame, ValueType &value);
00049   virtual void get_scale(int frame, LVecBase3 &scale);
00050   virtual void get_hpr(int frame, LVecBase3 &hpr);
00051   virtual void get_quat(int frame, LQuaternion &quat);
00052   virtual void get_pos(int frame, LVecBase3 &pos);
00053   virtual void get_shear(int frame, LVecBase3 &shear);
00054 
00055   virtual TypeHandle get_value_type() const;
00056 
00057   //This class has no Read/Write functions as it is abstract
00058   //and defines no new data
00059 
00060 public:
00061   virtual TypeHandle get_type() const {
00062     return get_class_type();
00063   }
00064   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00065   static TypeHandle get_class_type() {
00066     return _type_handle;
00067   }
00068   static void init_type() {
00069     AnimChannelBase::init_type();
00070     register_type(_type_handle, SwitchType::get_channel_type_name(),
00071                   AnimChannelBase::get_class_type());
00072   }
00073 
00074 private:
00075   static TypeHandle _type_handle;
00076 };
00077 
00078 
00079 // And now we instantiate a few useful types.
00080 
00081 class EXPCL_PANDA_CHAN ACMatrixSwitchType {
00082 public:
00083   typedef LMatrix4 ValueType;
00084   static const char *get_channel_type_name() { return "AnimChannelMatrix"; }
00085   static const char *get_fixed_channel_type_name() { return "AnimChannelFixed<LMatrix4>"; }
00086   static const char *get_part_type_name() { return "MovingPart<LMatrix4>"; }
00087   static void output_value(ostream &out, const ValueType &value);
00088 
00089   static void write_datagram(Datagram &dest, ValueType& me)
00090   {
00091     me.write_datagram(dest);
00092   }
00093   static void read_datagram(DatagramIterator &source, ValueType& me)
00094   {
00095     me.read_datagram(source);
00096   }
00097 };
00098 
00099 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_CHAN, EXPTP_PANDA_CHAN, AnimChannel<ACMatrixSwitchType>);
00100 typedef AnimChannel<ACMatrixSwitchType> AnimChannelMatrix;
00101 
00102 
00103 class EXPCL_PANDA_CHAN ACScalarSwitchType {
00104 public:
00105   typedef PN_stdfloat ValueType;
00106   static const char *get_channel_type_name() { return "AnimChannelScalar"; }
00107   static const char *get_fixed_channel_type_name() { return "AnimChannelScalarFixed"; }
00108   static const char *get_part_type_name() { return "MovingPart<PN_stdfloat>"; }
00109   static void output_value(ostream &out, ValueType value) {
00110     out << value;
00111   }
00112   static void write_datagram(Datagram &dest, ValueType& me)
00113   {
00114     dest.add_stdfloat(me);
00115   }
00116   static void read_datagram(DatagramIterator &source, ValueType& me)
00117   {
00118     me = source.get_stdfloat();
00119   }
00120 };
00121 
00122 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_CHAN, EXPTP_PANDA_CHAN, AnimChannel<ACScalarSwitchType>);
00123 typedef AnimChannel<ACScalarSwitchType> AnimChannelScalar;
00124 
00125 
00126 #include "animChannel.I"
00127 
00128 
00129 // Tell GCC that we'll take care of the instantiation explicitly here.
00130 #ifdef __GNUC__
00131 #pragma interface
00132 #endif
00133 
00134 #endif
00135 
 All Classes Functions Variables Enumerations