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