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) :
38 AnimChannel<ACMatrixSwitchType>(name),
39 _pos(pos), _hpr(hpr), _scale(scale)
40 {
41 }
42
43 /**
44 *
45 */
46 bool AnimChannelMatrixFixed::
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 */
64 void AnimChannelMatrixFixed::
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 */
73 void AnimChannelMatrixFixed::
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 */
82 void AnimChannelMatrixFixed::
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 */
92 void AnimChannelMatrixFixed::
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 */
101 void AnimChannelMatrixFixed::
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 */
110 void AnimChannelMatrixFixed::
111 get_shear(int, LVecBase3 &shear) {
112 shear = LVecBase3::zero();
113 }
114
115 /**
116 *
117 */
118 void AnimChannelMatrixFixed::
119 output(std::ostream &out) const {
120 AnimChannel<ACMatrixSwitchType>::output(out);
121 out << ": pos " << _pos << " hpr " << _hpr << " scale " << _scale;
122 }
123
124 /**
125 * Tells the BamReader how to create objects of type AnimChannelMatrixFixed.
126 */
127 void AnimChannelMatrixFixed::
128 register_with_read_factory() {
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 */
136 void AnimChannelMatrixFixed::
137 write_datagram(BamWriter *manager, Datagram &dg) {
138 AnimChannel<ACMatrixSwitchType>::write_datagram(manager, dg);
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) {
169 AnimChannel<ACMatrixSwitchType>::fillin(scan, manager);
170
171 _pos.read_datagram(scan);
172 _hpr.read_datagram(scan);
173 _scale.read_datagram(scan);
174 }
animChannelMatrixFixed.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
ACMatrixSwitchType
Definition: animChannel.h:78
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
AnimChannelMatrixFixed
A specialization on AnimChannel to add all the special matrix component operations.
Definition: animChannelMatrixFixed.h:26
AnimChannelMatrixFixed::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: animChannelMatrixFixed.cxx:137
AnimChannelMatrixFixed::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type AnimChannelMatrixFixed.
Definition: animChannelMatrixFixed.cxx:128
AnimChannelMatrixFixed::get_scale
virtual void get_scale(int frame, LVecBase3 &scale)
Gets the scale value at the indicated frame.
Definition: animChannelMatrixFixed.cxx:74
AnimChannelMatrixFixed::get_shear
virtual void get_shear(int frame, LVecBase3 &shear)
Returns the a, b, and c shear components associated with the current frame.
Definition: animChannelMatrixFixed.cxx:111
AnimChannelMatrixFixed::get_quat
virtual void get_quat(int frame, LQuaternion &quat)
Returns the rotation component associated with the current frame, expressed as a quaternion.
Definition: animChannelMatrixFixed.cxx:93
AnimChannelMatrixFixed::get_pos
virtual void get_pos(int frame, LVecBase3 &pos)
Returns the x, y, and z translation components associated with the current frame.
Definition: animChannelMatrixFixed.cxx:102
AnimChannelMatrixFixed::get_hpr
virtual void get_hpr(int frame, LVecBase3 &hpr)
Returns the h, p, and r components associated with the current frame.
Definition: animChannelMatrixFixed.cxx:83
AnimChannelMatrixFixed::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: animChannelMatrixFixed.cxx:47
AnimChannelMatrixFixed::output
virtual void output(std::ostream &out) const
Writes a one-line description of the group.
Definition: animChannelMatrixFixed.cxx:119
AnimChannelMatrixFixed::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: animChannelMatrixFixed.cxx:65
AnimChannel
This template class is the parent class for all kinds of AnimChannels that return different values.
Definition: animChannel.h:28
AnimGroup
This is the base class for AnimChannel and AnimBundle.
Definition: animGroup.h:33
AnimGroup::output
virtual void output(std::ostream &out) const
Writes a one-line description of the group.
Definition: animGroup.cxx:184
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
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
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
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
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.