Panda3D

Loading...
Searching...
No Matches
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
14#include "animChannelMatrixDynamic.h"
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 */
30AnimChannelMatrixDynamic::
31AnimChannelMatrixDynamic() {
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 */
39AnimChannelMatrixDynamic::
40AnimChannelMatrixDynamic(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 */
51AnimChannelMatrixDynamic::
52AnimChannelMatrixDynamic(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 */
65 bool AnimChannelMatrixDynamic::
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 */
78 void AnimChannelMatrixDynamic::
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 */
90 void AnimChannelMatrixDynamic::
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 */
106 void AnimChannelMatrixDynamic::
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 */
118 void AnimChannelMatrixDynamic::
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 */
131 void AnimChannelMatrixDynamic::
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 */
143 void AnimChannelMatrixDynamic::
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 */
155 void AnimChannelMatrixDynamic::
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 */
166 void AnimChannelMatrixDynamic::
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 */
176 void AnimChannelMatrixDynamic::
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 */
186 void AnimChannelMatrixDynamic::
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::
200make_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 */
209 void AnimChannelMatrixDynamic::
210 write_datagram(BamWriter *manager, Datagram &dg) {
211 AnimChannelMatrix::write_datagram(manager, dg);
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 */
220 int AnimChannelMatrixDynamic::
221 complete_pointers(TypedWritable **p_list, BamReader *manager) {
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 */
236 void AnimChannelMatrixDynamic::
237 fillin(DatagramIterator &scan, BamReader *manager) {
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 */
248 TypedWritable *AnimChannelMatrixDynamic::
249 make_AnimChannelMatrixDynamic(const FactoryParams &params) {
250 AnimChannelMatrixDynamic *me = new AnimChannelMatrixDynamic;
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 */
262 void AnimChannelMatrixDynamic::
263 register_with_read_factory() {
264 BamReader::get_factory()->register_factory(get_class_type(), make_AnimChannelMatrixDynamic);
265}
animBundle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
animChannelMatrixDynamic.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bamReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
parse_params
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
bamWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
AnimChannelBase::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
Definition animChannelBase.cxx:39
AnimChannelMatrixDynamic
An animation channel that accepts a matrix each frame from some dynamic input provided by code.
Definition animChannelMatrixDynamic.h:33
AnimChannelMatrixDynamic::get_scale
virtual void get_scale(int frame, LVecBase3 &scale)
Gets the scale value at the indicated frame.
Definition animChannelMatrixDynamic.cxx:107
AnimChannelMatrixDynamic::register_with_read_factory
static void register_with_read_factory()
Factory method to generate an AnimChannelMatrixDynamic object.
Definition animChannelMatrixDynamic.cxx:263
AnimChannelMatrixDynamic::get_shear
virtual void get_shear(int frame, LVecBase3 &shear)
Returns the a, b, and c shear components associated with the current frame.
Definition animChannelMatrixDynamic.cxx:156
AnimChannelMatrixDynamic::set_value_node
set_value_node
Specifies a node whose transform will be queried each frame to implicitly specify the transform of th...
Definition animChannelMatrixDynamic.h:60
AnimChannelMatrixDynamic::set_value
void set_value(const LMatrix4 &value)
Explicitly sets the matrix value.
Definition animChannelMatrixDynamic.cxx:167
AnimChannelMatrixDynamic::get_value_no_scale_shear
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.
Definition animChannelMatrixDynamic.cxx:91
AnimChannelMatrixDynamic::has_changed
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().
Definition animChannelMatrixDynamic.cxx:66
AnimChannelMatrixDynamic::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...
Definition animChannelMatrixDynamic.cxx:237
AnimChannelMatrixDynamic::get_quat
virtual void get_quat(int frame, LQuaternion &quat)
Returns the rotation component associated with the current frame, expressed as a quaternion.
Definition animChannelMatrixDynamic.cxx:132
AnimChannelMatrixDynamic::get_pos
virtual void get_pos(int frame, LVecBase3 &pos)
Returns the x, y, and z translation components associated with the current frame.
Definition animChannelMatrixDynamic.cxx:144
AnimChannelMatrixDynamic::complete_pointers
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition animChannelMatrixDynamic.cxx:221
AnimChannelMatrixDynamic::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Function to write the important information in the particular object to a Datagram.
Definition animChannelMatrixDynamic.cxx:210
AnimChannelMatrixDynamic::get_value
virtual void get_value(int frame, LMatrix4 &mat)
Gets the value of the channel at the indicated frame.
Definition animChannelMatrixDynamic.cxx:79
AnimChannelMatrixDynamic::get_hpr
virtual void get_hpr(int frame, LVecBase3 &hpr)
Returns the h, p, and r components associated with the current frame.
Definition animChannelMatrixDynamic.cxx:119
AnimChannelMatrixDynamic::make_AnimChannelMatrixDynamic
static TypedWritable * make_AnimChannelMatrixDynamic(const FactoryParams &params)
Factory method to generate an AnimChannelMatrixDynamic object.
Definition animChannelMatrixDynamic.cxx:249
AnimGroup
This is the base class for AnimChannel and AnimBundle.
Definition animGroup.h:33
AnimGroup::complete_pointers
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
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BamReader::read_pointer
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition bamReader.cxx:610
BamReader::get_factory
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
BamWriter::write_pointer
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
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition factoryParams.h:36
Factory::register_factory
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
PandaNode
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
TransformState
Indicates a coordinate-system transform on vertices.
Definition transformState.h:54
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition typedWritable.h:35
compose_matrix.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
config_chan.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
datagramIterator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
datagram.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indent.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.