Panda3D
animChannelMatrixDynamic.cxx
1 // Filename: animChannelMatrixDynamic.cxx
2 // Created by: drose (20Oct03)
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 #include "animChannelMatrixDynamic.h"
16 #include "animBundle.h"
17 #include "config_chan.h"
18 
19 #include "compose_matrix.h"
20 #include "indent.h"
21 #include "datagram.h"
22 #include "datagramIterator.h"
23 #include "bamReader.h"
24 #include "bamWriter.h"
25 
26 TypeHandle AnimChannelMatrixDynamic::_type_handle;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: AnimChannelMatrixDynamic::Constructor
30 // Access: Protected
31 // Description: For use only with the bam reader.
32 /////////////////////////////////////////////////////////////
33 AnimChannelMatrixDynamic::
34 AnimChannelMatrixDynamic() {
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: AnimChannelMatrixDynamic::Copy Constructor
39 // Access: Protected
40 // Description: Creates a new AnimChannelMatrixDynamic, just like
41 // this one, without copying any children. The new copy
42 // is added to the indicated parent. Intended to be
43 // called by make_copy() only.
44 ////////////////////////////////////////////////////////////////////
45 AnimChannelMatrixDynamic::
46 AnimChannelMatrixDynamic(AnimGroup *parent, const AnimChannelMatrixDynamic &copy) :
47  AnimChannelMatrix(parent, copy),
48  _value_node(copy._value_node),
49  _value(copy._value),
50  _last_value(NULL)
51 {
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: AnimChannelMatrixDynamic::Constructor
56 // Access: Public
57 // Description:
58 ////////////////////////////////////////////////////////////////////
59 AnimChannelMatrixDynamic::
60 AnimChannelMatrixDynamic(const string &name)
61  : AnimChannelMatrix(name)
62 {
63  _value = TransformState::make_identity();
64  _last_value = NULL; // This is impossible; thus, has_changed() will
65  // always return true the first time.
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: AnimChannelMatrixDynamic::has_changed
70 // Access: Public, Virtual
71 // Description: Returns true if the value has changed since the last
72 // call to has_changed(). last_frame is the frame
73 // number of the last call; this_frame is the current
74 // frame number.
75 ////////////////////////////////////////////////////////////////////
77 has_changed(int, double, int, double) {
78  if (_value_node != (PandaNode *)NULL) {
79  _value = _value_node->get_transform();
80  }
81  bool has_changed = (_value != _last_value);
82  _last_value = _value;
83  return has_changed;
84 }
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: AnimChannelMatrixDynamic::get_value
88 // Access: Public, Virtual
89 // Description: Gets the value of the channel at the indicated frame.
90 ////////////////////////////////////////////////////////////////////
92 get_value(int, LMatrix4 &mat) {
93  if (_value_node != (PandaNode *)NULL) {
94  _value = _value_node->get_transform();
95  }
96  mat = _value->get_mat();
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: AnimChannelMatrixDynamic::get_value_no_scale_shear
101 // Access: Public, Virtual
102 // Description: Gets the value of the channel at the indicated frame,
103 // without any scale or shear information.
104 ////////////////////////////////////////////////////////////////////
107  if (_value_node != (PandaNode *)NULL) {
108  _value = _value_node->get_transform();
109  }
110  if (_value->has_scale() || _value->has_shear()) {
111  compose_matrix(mat, LVecBase3(1.0f, 1.0f, 1.0f),
112  _value->get_hpr(), _value->get_pos());
113  } else {
114  mat = _value->get_mat();
115  }
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: AnimChannelMatrixDynamic::get_scale
120 // Access: Public, Virtual
121 // Description: Gets the scale value at the indicated frame.
122 ////////////////////////////////////////////////////////////////////
124 get_scale(int, LVecBase3 &scale) {
125  if (_value_node != (PandaNode *)NULL) {
126  _value = _value_node->get_transform();
127  }
128  scale = _value->get_scale();
129 }
130 
131 ////////////////////////////////////////////////////////////////////
132 // Function: AnimChannelMatrixDynamic::get_hpr
133 // Access: Public, Virtual
134 // Description: Returns the h, p, and r components associated
135 // with the current frame. As above, this only makes
136 // sense for a matrix-type channel.
137 ////////////////////////////////////////////////////////////////////
139 get_hpr(int, LVecBase3 &hpr) {
140  if (_value_node != (PandaNode *)NULL) {
141  _value = _value_node->get_transform();
142  }
143  hpr = _value->get_hpr();
144 }
145 
146 ////////////////////////////////////////////////////////////////////
147 // Function: AnimChannelMatrixDynamic::get_quat
148 // Access: Public, Virtual
149 // Description: Returns the rotation component associated with the
150 // current frame, expressed as a quaternion. As above,
151 // this only makes sense for a matrix-type channel.
152 ////////////////////////////////////////////////////////////////////
154 get_quat(int, LQuaternion &quat) {
155  if (_value_node != (PandaNode *)NULL) {
156  _value = _value_node->get_transform();
157  }
158  quat = _value->get_quat();
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: AnimChannelMatrixDynamic::get_pos
163 // Access: Public, Virtual
164 // Description: Returns the x, y, and z translation components
165 // associated with the current frame. As above, this
166 // only makes sense for a matrix-type channel.
167 ////////////////////////////////////////////////////////////////////
169 get_pos(int, LVecBase3 &pos) {
170  if (_value_node != (PandaNode *)NULL) {
171  _value = _value_node->get_transform();
172  }
173  pos = _value->get_pos();
174 }
175 
176 ////////////////////////////////////////////////////////////////////
177 // Function: AnimChannelMatrixDynamic::get_shear
178 // Access: Public, Virtual
179 // Description: Returns the a, b, and c shear components associated
180 // with the current frame. As above, this only makes
181 // sense for a matrix-type channel.
182 ////////////////////////////////////////////////////////////////////
184 get_shear(int, LVecBase3 &shear) {
185  if (_value_node != (PandaNode *)NULL) {
186  _value = _value_node->get_transform();
187  }
188  shear = _value->get_shear();
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: AnimChannelMatrixDynamic::set_value
193 // Access: Published
194 // Description: Explicitly sets the matrix value.
195 ////////////////////////////////////////////////////////////////////
197 set_value(const LMatrix4 &value) {
198  _value = TransformState::make_mat(value);
199  _value_node.clear();
200 }
201 
202 ////////////////////////////////////////////////////////////////////
203 // Function: AnimChannelMatrixDynamic::set_value
204 // Access: Published
205 // Description: Explicitly sets the matrix value, using the indicated
206 // TransformState object as a convenience.
207 ////////////////////////////////////////////////////////////////////
209 set_value(const TransformState *value) {
210  _value = value;
211  _value_node.clear();
212 }
213 
214 ////////////////////////////////////////////////////////////////////
215 // Function: AnimChannelMatrixDynamic::set_value_node
216 // Access: Published
217 // Description: Specifies a node whose transform will be queried each
218 // frame to implicitly specify the transform of this
219 // joint.
220 ////////////////////////////////////////////////////////////////////
222 set_value_node(PandaNode *value_node) {
223  _value_node = value_node;
224  if (_value_node != (PandaNode *)NULL) {
225  _value = _value_node->get_transform();
226  }
227 }
228 
229 ////////////////////////////////////////////////////////////////////
230 // Function: AnimChannelMatrixDynamic::make_copy
231 // Access: Protected, Virtual
232 // Description: Returns a copy of this object, and attaches it to the
233 // indicated parent (which may be NULL only if this is
234 // an AnimBundle). Intended to be called by
235 // copy_subtree() only.
236 ////////////////////////////////////////////////////////////////////
237 AnimGroup *AnimChannelMatrixDynamic::
238 make_copy(AnimGroup *parent) const {
239  return new AnimChannelMatrixDynamic(parent, *this);
240 }
241 
242 
243 ////////////////////////////////////////////////////////////////////
244 // Function: AnimChannelMatrixDynamic::write_datagram
245 // Access: Public
246 // Description: Function to write the important information in
247 // the particular object to a Datagram
248 ////////////////////////////////////////////////////////////////////
252  manager->write_pointer(dg, _value_node);
253  manager->write_pointer(dg, _value);
254 }
255 
256 ////////////////////////////////////////////////////////////////////
257 // Function: AnimChannelMatrixDynamic::complete_pointers
258 // Access: Public, Virtual
259 // Description: Receives an array of pointers, one for each time
260 // manager->read_pointer() was called in fillin().
261 // Returns the number of pointers processed.
262 ////////////////////////////////////////////////////////////////////
265  int pi = AnimChannelMatrix::complete_pointers(p_list, manager);
266 
267  // Get the _value_node and _value pointers.
268  _value_node = DCAST(PandaNode, p_list[pi++]);
269  _value = DCAST(TransformState, p_list[pi++]);
270 
271  return pi;
272 }
273 
274 ////////////////////////////////////////////////////////////////////
275 // Function: AnimChannelMatrixDynamic::fillin
276 // Access: Public
277 // Description: Function that reads out of the datagram (or asks
278 // manager to read) all of the data that is needed to
279 // re-create this object and stores it in the appropiate
280 // place
281 ////////////////////////////////////////////////////////////////////
284  AnimChannelMatrix::fillin(scan, manager);
285 
286  // Read the _value_node and _value pointers.
287  manager->read_pointer(scan);
288  manager->read_pointer(scan);
289 }
290 
291 ////////////////////////////////////////////////////////////////////
292 // Function: AnimChannelMatrixDynamic::make_AnimChannelMatrixDynamic
293 // Access: Public
294 // Description: Factory method to generate an
295 // AnimChannelMatrixDynamic object.
296 ////////////////////////////////////////////////////////////////////
300  DatagramIterator scan;
301  BamReader *manager;
302 
303  parse_params(params, scan, manager);
304  me->fillin(scan, manager);
305  return me;
306 }
307 
308 ////////////////////////////////////////////////////////////////////
309 // Function: AnimChannelMatrixDynamic::register_with_factory
310 // Access: Public, Static
311 // Description: Factory method to generate an
312 // AnimChannelMatrixDynamic object.
313 ////////////////////////////////////////////////////////////////////
317 }
318 
319 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
static void register_with_read_factory()
Factory method to generate an AnimChannelMatrixDynamic object.
virtual void get_scale(int frame, LVecBase3 &scale)
Gets the scale value at the indicated frame.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Takes in a vector of pointes to TypedWritable objects that correspond to all the requests for pointer...
Definition: animGroup.cxx:327
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
virtual void get_value(int frame, LMatrix4 &mat)
Gets the value of the channel at the indicated frame.
void set_value_node(PandaNode *node)
Specifies a node whose transform will be queried each frame to implicitly specify the transform of th...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual bool has_changed(int last_frame, double last_frac, int this_frame, double this_frac)
Returns true if the value has changed since the last call to has_changed().
An animation channel that accepts a matrix each frame from some dynamic input provided by code...
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:36
virtual void get_shear(int frame, LVecBase3 &shear)
Returns the a, b, and c shear components associated with the current frame.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
virtual void get_quat(int frame, LQuaternion &quat)
Returns the rotation component associated with the current frame, expressed as a quaternion.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
static TypedWritable * make_AnimChannelMatrixDynamic(const FactoryParams &params)
Factory method to generate an AnimChannelMatrixDynamic object.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
virtual void get_hpr(int frame, LVecBase3 &hpr)
Returns the h, p, and r components associated with the current frame.
This is the base quaternion class.
Definition: lquaternion.h:96
A class to retrieve the individual data elements previously stored in a Datagram. ...
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
void fillin(DatagramIterator &scan, BamReader *manager)
Function that reads out of the datagram (or asks manager to read) all of the data that is needed to r...
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 write_datagram(BamWriter *manager, Datagram &dg)
Function to write the important information in the particular object to a Datagram.
virtual void get_pos(int frame, LVecBase3 &pos)
Returns the x, y, and z translation components associated with the current frame. ...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:279
void set_value(const LMatrix4 &value)
Explicitly sets the matrix value.
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:658
virtual void get_value_no_scale_shear(int frame, LMatrix4 &value)
Gets the value of the channel at the indicated frame, without any scale or shear information.