Panda3D
animChannelMatrixFixed.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 animChannelMatrixFixed.cxx
10  * @author drose
11  * @date 2006-01-19
12  */
13 
14 #include "animChannelMatrixFixed.h"
15 #include "compose_matrix.h"
16 
17 TypeHandle AnimChannelMatrixFixed::_type_handle;
18 
19 /**
20  * Creates a new AnimChannelMatrixFixed, just like this one, without copying
21  * any children. The new copy is added to the indicated parent. Intended to
22  * be called by make_copy() only.
23  */
24 AnimChannelMatrixFixed::
25 AnimChannelMatrixFixed(AnimGroup *parent, const AnimChannelMatrixFixed &copy) :
26  AnimChannel<ACMatrixSwitchType>(parent, copy),
27  _pos(copy._pos),
28  _hpr(copy._hpr),
29  _scale(copy._scale)
30 {
31 }
32 
33 /**
34  *
35  */
36 AnimChannelMatrixFixed::
37 AnimChannelMatrixFixed(const std::string &name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale) :
39  _pos(pos), _hpr(hpr), _scale(scale)
40 {
41 }
42 
43 /**
44  *
45  */
47 has_changed(int, double, int, double) {
48  return false;
49 }
50 
51 
52 /**
53  *
54  */
55 void AnimChannelMatrixFixed::
56 get_value(int, LMatrix4 &value) {
57  compose_matrix(value, _scale, LVecBase3::zero(), _hpr, _pos);
58 }
59 
60 /**
61  * Gets the value of the channel at the indicated frame, without any scale or
62  * shear information.
63  */
65 get_value_no_scale_shear(int, LMatrix4 &mat) {
66  compose_matrix(mat, LVecBase3(1.0f, 1.0f, 1.0f), LVecBase3::zero(),
67  _hpr, _pos);
68 }
69 
70 /**
71  * Gets the scale value at the indicated frame.
72  */
74 get_scale(int, LVecBase3 &scale) {
75  scale = _scale;
76 }
77 
78 /**
79  * Returns the h, p, and r components associated with the current frame. As
80  * above, this only makes sense for a matrix-type channel.
81  */
83 get_hpr(int, LVecBase3 &hpr) {
84  hpr = _hpr;
85 }
86 
87 /**
88  * Returns the rotation component associated with the current frame, expressed
89  * as a quaternion. As above, this only makes sense for a matrix-type
90  * channel.
91  */
93 get_quat(int, LQuaternion &quat) {
94  quat.set_hpr(_hpr);
95 }
96 
97 /**
98  * Returns the x, y, and z translation components associated with the current
99  * frame. As above, this only makes sense for a matrix-type channel.
100  */
102 get_pos(int, LVecBase3 &pos) {
103  pos = _pos;
104 }
105 
106 /**
107  * Returns the a, b, and c shear components associated with the current frame.
108  * As above, this only makes sense for a matrix-type channel.
109  */
111 get_shear(int, LVecBase3 &shear) {
112  shear = LVecBase3::zero();
113 }
114 
115 /**
116  *
117  */
119 output(std::ostream &out) const {
121  out << ": pos " << _pos << " hpr " << _hpr << " scale " << _scale;
122 }
123 
124 /**
125  * Tells the BamReader how to create objects of type AnimChannelMatrixFixed.
126  */
129  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
130 }
131 
132 /**
133  * Writes the contents of this object to the datagram for shipping out to a
134  * Bam file.
135  */
139 
140  _pos.write_datagram(dg);
141  _hpr.write_datagram(dg);
142  _scale.write_datagram(dg);
143 }
144 
145 /**
146  * This function is called by the BamReader's factory when a new object of
147  * type AnimChannelMatrixFixed is encountered in the Bam file. It should
148  * create the AnimChannelMatrixFixed and extract its information from the
149  * file.
150  */
151 TypedWritable *AnimChannelMatrixFixed::
152 make_from_bam(const FactoryParams &params) {
153  AnimChannelMatrixFixed *chan = new AnimChannelMatrixFixed("", LVecBase3::zero(), LVecBase3::zero(), LVecBase3::zero());
154  DatagramIterator scan;
155  BamReader *manager;
156 
157  parse_params(params, scan, manager);
158  chan->fillin(scan, manager);
159 
160  return chan;
161 }
162 
163 /**
164  * This internal function is called by make_from_bam to read in all of the
165  * relevant data from the BamFile for the new AnimChannelMatrixFixed.
166  */
167 void AnimChannelMatrixFixed::
168 fillin(DatagramIterator &scan, BamReader *manager) {
170 
171  _pos.read_datagram(scan);
172  _hpr.read_datagram(scan);
173  _scale.read_datagram(scan);
174 }
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_shear(int frame, LVecBase3 &shear)
Returns the a, b, and c shear components associated with the current frame.
virtual void get_scale(int frame, LVecBase3 &scale)
Gets the scale value at the indicated frame.
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().
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
virtual void get_pos(int frame, LVecBase3 &pos)
Returns the x, y, and z translation components associated with the current frame.
This template class is the parent class for all kinds of AnimChannels that return different values.
Definition: animChannel.h:28
static void register_with_read_factory()
Tells the BamReader how to create objects of type AnimChannelMatrixFixed.
virtual void output(std::ostream &out) const
Writes a one-line description of the group.
Definition: animGroup.cxx:184
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_value_no_scale_shear(int frame, LMatrix4 &value)
Gets the value of the channel at the indicated frame, without any scale or shear information.
A specialization on AnimChannel to add all the special matrix component operations.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
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
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
virtual void output(std::ostream &out) const
Writes a one-line description of the group.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
virtual void get_quat(int frame, LQuaternion &quat)
Returns the rotation component associated with the current frame, expressed as a quaternion.
virtual void get_hpr(int frame, LVecBase3 &hpr)
Returns the h, p, and r components associated with the current frame.
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:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38