Panda3D
animChannel.h
1 // Filename: animChannel.h
2 // Created by: drose (22Feb99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef ANIMCHANNEL_H
16 #define ANIMCHANNEL_H
17 
18 #include "pandabase.h"
19 
20 #include "animChannelBase.h"
21 
22 #include "luse.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : AnimChannel
26 // Description : This template class is the parent class for all kinds
27 // of AnimChannels that return different values.
28 ////////////////////////////////////////////////////////////////////
29 template<class SwitchType>
30 class AnimChannel : public AnimChannelBase {
31 protected:
32  // The default constructor is protected: don't try to create an
33  // AnimChannel without a parent. To create an AnimChannel hierarchy,
34  // you must first create an AnimBundle, and use that to create any
35  // subsequent children.
36  INLINE AnimChannel(const string &name = "");
37  INLINE AnimChannel(AnimGroup *parent, const AnimChannel &copy);
38 public:
39  typedef TYPENAME SwitchType::ValueType ValueType;
40 
41  INLINE AnimChannel(AnimGroup *parent, const string &name);
42  INLINE ~AnimChannel();
43 
44 PUBLISHED:
45  virtual void get_value(int frame, ValueType &value)=0;
46 
47  // These transform-component methods only have meaning for matrix types.
48  virtual void get_value_no_scale_shear(int frame, ValueType &value);
49  virtual void get_scale(int frame, LVecBase3 &scale);
50  virtual void get_hpr(int frame, LVecBase3 &hpr);
51  virtual void get_quat(int frame, LQuaternion &quat);
52  virtual void get_pos(int frame, LVecBase3 &pos);
53  virtual void get_shear(int frame, LVecBase3 &shear);
54 
55  virtual TypeHandle get_value_type() const;
56 
57  //This class has no Read/Write functions as it is abstract
58  //and defines no new data
59 
60 public:
61  virtual TypeHandle get_type() const {
62  return get_class_type();
63  }
64  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
65  static TypeHandle get_class_type() {
66  return _type_handle;
67  }
68  static void init_type() {
69  AnimChannelBase::init_type();
70  register_type(_type_handle, SwitchType::get_channel_type_name(),
71  AnimChannelBase::get_class_type());
72  }
73 
74 private:
75  static TypeHandle _type_handle;
76 };
77 
78 
79 // And now we instantiate a few useful types.
80 
81 class EXPCL_PANDA_CHAN ACMatrixSwitchType {
82 public:
83  typedef LMatrix4 ValueType;
84  static const char *get_channel_type_name() { return "AnimChannelMatrix"; }
85  static const char *get_fixed_channel_type_name() { return "AnimChannelFixed<LMatrix4>"; }
86  static const char *get_part_type_name() { return "MovingPart<LMatrix4>"; }
87  static void output_value(ostream &out, const ValueType &value);
88 
89  static void write_datagram(Datagram &dest, ValueType& me)
90  {
91  me.write_datagram(dest);
92  }
93  static void read_datagram(DatagramIterator &source, ValueType& me)
94  {
95  me.read_datagram(source);
96  }
97 };
98 
99 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_CHAN, EXPTP_PANDA_CHAN, AnimChannel<ACMatrixSwitchType>);
101 
102 
103 class EXPCL_PANDA_CHAN ACScalarSwitchType {
104 public:
105  typedef PN_stdfloat ValueType;
106  static const char *get_channel_type_name() { return "AnimChannelScalar"; }
107  static const char *get_fixed_channel_type_name() { return "AnimChannelScalarFixed"; }
108  static const char *get_part_type_name() { return "MovingPart<PN_stdfloat>"; }
109  static void output_value(ostream &out, ValueType value) {
110  out << value;
111  }
112  static void write_datagram(Datagram &dest, ValueType& me)
113  {
114  dest.add_stdfloat(me);
115  }
116  static void read_datagram(DatagramIterator &source, ValueType& me)
117  {
118  me = source.get_stdfloat();
119  }
120 };
121 
122 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_CHAN, EXPTP_PANDA_CHAN, AnimChannel<ACScalarSwitchType>);
124 
125 
126 #include "animChannel.I"
127 
128 
129 // Tell GCC that we'll take care of the instantiation explicitly here.
130 #ifdef __GNUC__
131 #pragma interface
132 #endif
133 
134 #endif
135 
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
virtual void get_pos(int frame, LVecBase3 &pos)
Returns the x, y, and z translation components associated with the current frame. ...
Definition: animChannel.I:158
virtual void get_quat(int frame, LQuaternion &quat)
Returns the rotation component associated with the current frame, expressed as a quaternion.
Definition: animChannel.I:145
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
virtual void get_scale(int frame, LVecBase3 &scale)
Returns the x, y, and z scale components associated with the current frame.
Definition: animChannel.I:119
virtual void get_hpr(int frame, LVecBase3 &hpr)
Returns the h, p, and r components associated with the current frame.
Definition: animChannel.I:132
This template class is the parent class for all kinds of AnimChannels that return different values...
Definition: animChannel.h:30
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
Definition: datagram.I:240
Parent class for all animation channels.
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:36
void write_datagram(Datagram &destination) const
Writes the matrix to the Datagram using add_stdfloat().
Definition: lmatrix.cxx:1148
virtual TypeHandle get_value_type() const
Returns the TypeHandle associated with the ValueType we return.
Definition: animChannel.I:186
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
virtual void get_value_no_scale_shear(int frame, ValueType &value)
Returns the value associated with the current frame, with no scale or share components.
Definition: animChannel.I:106
void read_datagram(DatagramIterator &source)
Reads the matrix from the Datagram using get_stdfloat().
Definition: lmatrix.cxx:1162
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
This is the base quaternion class.
Definition: lquaternion.h:96
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual void get_shear(int frame, LVecBase3 &shear)
Returns the a, b, and c shear components associated with the current frame.
Definition: animChannel.I:171