Panda3D
animChannelMatrixDynamic.cxx
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 animChannelMatrixDynamic.cxx
10  * @author drose
11  * @date 2003-10-20
12  */
13 
15 #include "animBundle.h"
16 #include "config_chan.h"
17 
18 #include "compose_matrix.h"
19 #include "indent.h"
20 #include "datagram.h"
21 #include "datagramIterator.h"
22 #include "bamReader.h"
23 #include "bamWriter.h"
24 
25 TypeHandle AnimChannelMatrixDynamic::_type_handle;
26 
27 /**
28  * For use only with the bam reader.
29  */
30 AnimChannelMatrixDynamic::
31 AnimChannelMatrixDynamic() {
32 }
33 
34 /**
35  * Creates a new AnimChannelMatrixDynamic, just like this one, without copying
36  * any children. The new copy is added to the indicated parent. Intended to
37  * be called by make_copy() only.
38  */
39 AnimChannelMatrixDynamic::
40 AnimChannelMatrixDynamic(AnimGroup *parent, const AnimChannelMatrixDynamic &copy) :
41  AnimChannelMatrix(parent, copy),
42  _value_node(copy._value_node),
43  _value(copy._value),
44  _last_value(nullptr)
45 {
46 }
47 
48 /**
49  *
50  */
51 AnimChannelMatrixDynamic::
52 AnimChannelMatrixDynamic(const std::string &name)
53  : AnimChannelMatrix(name)
54 {
55  _value = TransformState::make_identity();
56  _last_value = nullptr; // This is impossible; thus, has_changed() will
57  // always return true the first time.
58 }
59 
60 /**
61  * Returns true if the value has changed since the last call to has_changed().
62  * last_frame is the frame number of the last call; this_frame is the current
63  * frame number.
64  */
66 has_changed(int, double, int, double) {
67  if (_value_node != nullptr) {
68  _value = _value_node->get_transform();
69  }
70  bool has_changed = (_value != _last_value);
71  _last_value = _value;
72  return has_changed;
73 }
74 
75 /**
76  * Gets the value of the channel at the indicated frame.
77  */
79 get_value(int, LMatrix4 &mat) {
80  if (_value_node != nullptr) {
81  _value = _value_node->get_transform();
82  }
83  mat = _value->get_mat();
84 }
85 
86 /**
87  * Gets the value of the channel at the indicated frame, without any scale or
88  * shear information.
89  */
91 get_value_no_scale_shear(int, LMatrix4 &mat) {
92  if (_value_node != nullptr) {
93  _value = _value_node->get_transform();
94  }
95  if (_value->has_scale() || _value->has_shear()) {
96  compose_matrix(mat, LVecBase3(1.0f, 1.0f, 1.0f),
97  _value->get_hpr(), _value->get_pos());
98  } else {
99  mat = _value->get_mat();
100  }
101 }
102 
103 /**
104  * Gets the scale value at the indicated frame.
105  */
107 get_scale(int, LVecBase3 &scale) {
108  if (_value_node != nullptr) {
109  _value = _value_node->get_transform();
110  }
111  scale = _value->get_scale();
112 }
113 
114 /**
115  * Returns the h, p, and r components associated with the current frame. As
116  * above, this only makes sense for a matrix-type channel.
117  */
119 get_hpr(int, LVecBase3 &hpr) {
120  if (_value_node != nullptr) {
121  _value = _value_node->get_transform();
122  }
123  hpr = _value->get_hpr();
124 }
125 
126 /**
127  * Returns the rotation component associated with the current frame, expressed
128  * as a quaternion. As above, this only makes sense for a matrix-type
129  * channel.
130  */
132 get_quat(int, LQuaternion &quat) {
133  if (_value_node != nullptr) {
134  _value = _value_node->get_transform();
135  }
136  quat = _value->get_quat();
137 }
138 
139 /**
140  * Returns the x, y, and z translation components associated with the current
141  * frame. As above, this only makes sense for a matrix-type channel.
142  */
144 get_pos(int, LVecBase3 &pos) {
145  if (_value_node != nullptr) {
146  _value = _value_node->get_transform();
147  }
148  pos = _value->get_pos();
149 }
150 
151 /**
152  * Returns the a, b, and c shear components associated with the current frame.
153  * As above, this only makes sense for a matrix-type channel.
154  */
156 get_shear(int, LVecBase3 &shear) {
157  if (_value_node != nullptr) {
158  _value = _value_node->get_transform();
159  }
160  shear = _value->get_shear();
161 }
162 
163 /**
164  * Explicitly sets the matrix value.
165  */
167 set_value(const LMatrix4 &value) {
168  _value = TransformState::make_mat(value);
169  _value_node.clear();
170 }
171 
172 /**
173  * Explicitly sets the matrix value, using the indicated TransformState object
174  * as a convenience.
175  */
177 set_value(const TransformState *value) {
178  _value = value;
179  _value_node.clear();
180 }
181 
182 /**
183  * Specifies a node whose transform will be queried each frame to implicitly
184  * specify the transform of this joint.
185  */
187 set_value_node(PandaNode *value_node) {
188  _value_node = value_node;
189  if (_value_node != nullptr) {
190  _value = _value_node->get_transform();
191  }
192 }
193 
194 /**
195  * Returns a copy of this object, and attaches it to the indicated parent
196  * (which may be NULL only if this is an AnimBundle). Intended to be called
197  * by copy_subtree() only.
198  */
199 AnimGroup *AnimChannelMatrixDynamic::
200 make_copy(AnimGroup *parent) const {
201  return new AnimChannelMatrixDynamic(parent, *this);
202 }
203 
204 
205 /**
206  * Function to write the important information in the particular object to a
207  * Datagram
208  */
212  manager->write_pointer(dg, _value_node);
213  manager->write_pointer(dg, _value);
214 }
215 
216 /**
217  * Receives an array of pointers, one for each time manager->read_pointer()
218  * was called in fillin(). Returns the number of pointers processed.
219  */
222  int pi = AnimChannelMatrix::complete_pointers(p_list, manager);
223 
224  // Get the _value_node and _value pointers.
225  _value_node = DCAST(PandaNode, p_list[pi++]);
226  _value = DCAST(TransformState, p_list[pi++]);
227 
228  return pi;
229 }
230 
231 /**
232  * Function that reads out of the datagram (or asks manager to read) all of
233  * the data that is needed to re-create this object and stores it in the
234  * appropiate place
235  */
238  AnimChannelMatrix::fillin(scan, manager);
239 
240  // Read the _value_node and _value pointers.
241  manager->read_pointer(scan);
242  manager->read_pointer(scan);
243 }
244 
245 /**
246  * Factory method to generate an AnimChannelMatrixDynamic object.
247  */
251  DatagramIterator scan;
252  BamReader *manager;
253 
254  parse_params(params, scan, manager);
255  me->fillin(scan, manager);
256  return me;
257 }
258 
259 /**
260  * Factory method to generate an AnimChannelMatrixDynamic object.
261  */
265 }
set_value_node
Specifies a node whose transform will be queried each frame to implicitly specify the transform of th...
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void register_with_read_factory()
Factory method to generate an AnimChannelMatrixDynamic object.
Indicates a coordinate-system transform on vertices.
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:277
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
virtual void get_value(int frame, LMatrix4 &mat)
Gets the value of the channel at the indicated frame.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:33
virtual void get_shear(int frame, LVecBase3 &shear)
Returns the a, b, and c shear components associated with the current frame.
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:36
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
virtual void get_hpr(int frame, LVecBase3 &hpr)
Returns the h, p, and r components associated with the current frame.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:610
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:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Function to write the important information in the particular object to a Datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void get_pos(int frame, LVecBase3 &pos)
Returns the x, y, and z translation components associated with the current frame.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:317
void set_value(const LMatrix4 &value)
Explicitly sets the matrix value.
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.