Panda3D
 All Classes Functions Variables Enumerations
animChannelMatrixFixed.cxx
1 // Filename: animChannelMatrixFixed.cxx
2 // Created by: drose (19Jan06)
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 "animChannelMatrixFixed.h"
16 #include "compose_matrix.h"
17 
18 TypeHandle AnimChannelMatrixFixed::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: AnimChannelMatrixFixed::Copy Constructor
22 // Access: Protected
23 // Description: Creates a new AnimChannelMatrixFixed, just like this
24 // one, without copying any children. The new copy is
25 // added to the indicated parent. Intended to be called
26 // by make_copy() only.
27 ////////////////////////////////////////////////////////////////////
28 AnimChannelMatrixFixed::
29 AnimChannelMatrixFixed(AnimGroup *parent, const AnimChannelMatrixFixed &copy) :
30  AnimChannel<ACMatrixSwitchType>(parent, copy),
31  _pos(copy._pos),
32  _hpr(copy._hpr),
33  _scale(copy._scale)
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: AnimChannelMatrixFixed::Constructor
39 // Access: Public
40 // Description:
41 ////////////////////////////////////////////////////////////////////
42 AnimChannelMatrixFixed::
43 AnimChannelMatrixFixed(const string &name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale) :
45  _pos(pos), _hpr(hpr), _scale(scale)
46 {
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: AnimChannelFixed::has_changed
51 // Access: Public, Virtual
52 // Description:
53 ////////////////////////////////////////////////////////////////////
55 has_changed(int, double, int, double) {
56  return false;
57 }
58 
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: AnimChannelFixed::get_value
62 // Access: Public, Virtual
63 // Description:
64 ////////////////////////////////////////////////////////////////////
65 void AnimChannelMatrixFixed::
66 get_value(int, LMatrix4 &value) {
67  compose_matrix(value, _scale, LVecBase3::zero(), _hpr, _pos);
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: AnimChannelMatrixFixed::get_value_no_scale_shear
72 // Access: Public, Virtual
73 // Description: Gets the value of the channel at the indicated frame,
74 // without any scale or shear information.
75 ////////////////////////////////////////////////////////////////////
78  compose_matrix(mat, LVecBase3(1.0f, 1.0f, 1.0f), LVecBase3::zero(),
79  _hpr, _pos);
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: AnimChannelMatrixFixed::get_scale
84 // Access: Public, Virtual
85 // Description: Gets the scale value at the indicated frame.
86 ////////////////////////////////////////////////////////////////////
88 get_scale(int, LVecBase3 &scale) {
89  scale = _scale;
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: AnimChannelMatrixFixed::get_hpr
94 // Access: Public, Virtual
95 // Description: Returns the h, p, and r components associated
96 // with the current frame. As above, this only makes
97 // sense for a matrix-type channel.
98 ////////////////////////////////////////////////////////////////////
100 get_hpr(int, LVecBase3 &hpr) {
101  hpr = _hpr;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: AnimChannelMatrixFixed::get_quat
106 // Access: Public, Virtual
107 // Description: Returns the rotation component associated with the
108 // current frame, expressed as a quaternion. As above,
109 // this only makes sense for a matrix-type channel.
110 ////////////////////////////////////////////////////////////////////
112 get_quat(int, LQuaternion &quat) {
113  quat.set_hpr(_hpr);
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: AnimChannelMatrixFixed::get_pos
118 // Access: Public, Virtual
119 // Description: Returns the x, y, and z translation components
120 // associated with the current frame. As above, this
121 // only makes sense for a matrix-type channel.
122 ////////////////////////////////////////////////////////////////////
124 get_pos(int, LVecBase3 &pos) {
125  pos = _pos;
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: AnimChannelMatrixFixed::get_shear
130 // Access: Public, Virtual
131 // Description: Returns the a, b, and c shear components associated
132 // with the current frame. As above, this only makes
133 // sense for a matrix-type channel.
134 ////////////////////////////////////////////////////////////////////
136 get_shear(int, LVecBase3 &shear) {
137  shear = LVecBase3::zero();
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: AnimChannelMatrixFixed::output
142 // Access: Public, Virtual
143 // Description:
144 ////////////////////////////////////////////////////////////////////
146 output(ostream &out) const {
148  out << ": pos " << _pos << " hpr " << _hpr << " scale " << _scale;
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: AnimChannelMatrixFixed::register_with_read_factory
153 // Access: Public, Static
154 // Description: Tells the BamReader how to create objects of type
155 // AnimChannelMatrixFixed.
156 ////////////////////////////////////////////////////////////////////
159  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
160 }
161 
162 ////////////////////////////////////////////////////////////////////
163 // Function: AnimChannelMatrixFixed::write_datagram
164 // Access: Public, Virtual
165 // Description: Writes the contents of this object to the datagram
166 // for shipping out to a Bam file.
167 ////////////////////////////////////////////////////////////////////
171 
172  _pos.write_datagram(dg);
173  _hpr.write_datagram(dg);
174  _scale.write_datagram(dg);
175 }
176 
177 ////////////////////////////////////////////////////////////////////
178 // Function: AnimChannelMatrixFixed::make_from_bam
179 // Access: Protected, Static
180 // Description: This function is called by the BamReader's factory
181 // when a new object of type AnimChannelMatrixFixed is encountered
182 // in the Bam file. It should create the AnimChannelMatrixFixed
183 // and extract its information from the file.
184 ////////////////////////////////////////////////////////////////////
185 TypedWritable *AnimChannelMatrixFixed::
186 make_from_bam(const FactoryParams &params) {
188  DatagramIterator scan;
189  BamReader *manager;
190 
191  parse_params(params, scan, manager);
192  chan->fillin(scan, manager);
193 
194  return chan;
195 }
196 
197 ////////////////////////////////////////////////////////////////////
198 // Function: AnimChannelMatrixFixed::fillin
199 // Access: Protected
200 // Description: This internal function is called by make_from_bam to
201 // read in all of the relevant data from the BamFile for
202 // the new AnimChannelMatrixFixed.
203 ////////////////////////////////////////////////////////////////////
204 void AnimChannelMatrixFixed::
205 fillin(DatagramIterator &scan, BamReader *manager) {
207 
208  _pos.read_datagram(scan);
209  _hpr.read_datagram(scan);
210  _scale.read_datagram(scan);
211 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
Definition: lvecBase3.h:1373
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
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:73
static const LVecBase3f & zero()
Returns a zero-length vector.
Definition: lvecBase3.h:381
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:30
static void register_with_read_factory()
Tells the BamReader how to create objects of type AnimChannelMatrixFixed.
virtual void output(ostream &out) const
Writes a one-line description of the group.
Definition: animGroup.cxx:214
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:36
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.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
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:40
void set_hpr(const LVecBase3f &hpr, CoordinateSystem cs=CS_default)
Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
virtual void write_datagram(BamWriter *manager, Datagram &me)
Function to write the important information in the particular object to a Datagram.
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_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.
This is the base quaternion class.
Definition: lquaternion.h:96
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:85
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:43
void write_datagram(Datagram &destination) const
Writes the vector to the Datagram using add_stdfloat().
Definition: lvecBase3.h:1355
virtual void output(ostream &out) const
Writes a one-line description of the group.