16 #include "movingPartMatrix.h" 17 #include "animChannelMatrixDynamic.h" 18 #include "animChannelMatrixFixed.h" 19 #include "compose_matrix.h" 21 #include "datagramIterator.h" 22 #include "bamReader.h" 23 #include "bamWriter.h" 24 #include "config_chan.h" 28 #pragma implementation 53 decompose_matrix(_default_value, pos, hpr, scale, shear);
71 channel->get_value(0, _value);
77 if (cdata->_blend.empty()) {
79 if (restore_initial_pose) {
80 _value = _default_value;
83 }
else if (_effective_control != (
AnimControl *)NULL &&
84 !cdata->_frame_blend_flag) {
87 channel->get_value(_effective_control->get_frame(), _value);
93 switch (cdata->_blend_type) {
94 case PartBundle::BT_linear:
98 PN_stdfloat net_effect = 0.0f;
100 PartBundle::ChannelBlend::const_iterator cbi;
101 for (cbi = cdata->_blend.begin(); cbi != cdata->_blend.end(); ++cbi) {
103 PN_stdfloat effect = (*cbi).second;
104 nassertv(effect != 0.0f);
107 nassertv(channel_index >= 0 && channel_index < (
int)_channels.size());
111 channel->get_value(control->
get_frame(), v);
113 if (!cdata->_frame_blend_flag) {
115 net_value += v * effect;
118 PN_stdfloat frac = (PN_stdfloat)control->
get_frac();
119 net_value += v * (effect * (1.0f - frac));
122 net_value += v * (effect * frac);
124 net_effect += effect;
128 if (net_effect == 0.0f) {
129 if (restore_initial_pose) {
130 _value = _default_value;
133 _value = net_value / net_effect;
138 case PartBundle::BT_normalized_linear:
149 PN_stdfloat net_effect = 0.0f;
151 PartBundle::ChannelBlend::const_iterator cbi;
152 for (cbi = cdata->_blend.begin(); cbi != cdata->_blend.end(); ++cbi) {
154 PN_stdfloat effect = (*cbi).second;
155 nassertv(effect != 0.0f);
159 if (channel_index >= 0 && channel_index < (
int)_channels.size()) {
160 channel = DCAST(
ChannelType, _channels[channel_index]);
170 if (!cdata->_frame_blend_flag) {
172 net_value += v * effect;
173 scale += iscale * effect;
174 shear += ishear * effect;
177 PN_stdfloat frac = (PN_stdfloat)control->
get_frac();
178 PN_stdfloat e0 = effect * (1.0f - frac);
180 scale += iscale * e0;
181 shear += ishear * e0;
187 PN_stdfloat e1 = effect * frac;
189 scale += iscale * e1;
190 shear += ishear * e1;
192 net_effect += effect;
196 if (net_effect == 0.0f) {
197 if (restore_initial_pose) {
198 _value = _default_value;
202 net_value /= net_effect;
208 LVector3 false_scale, false_shear, hpr, translate;
209 decompose_matrix(net_value, false_scale, false_shear, hpr, translate);
210 compose_matrix(_value, scale, shear, hpr, translate);
215 case PartBundle::BT_componentwise:
222 PN_stdfloat net_effect = 0.0f;
224 PartBundle::ChannelBlend::const_iterator cbi;
225 for (cbi = cdata->_blend.begin(); cbi != cdata->_blend.end(); ++cbi) {
227 PN_stdfloat effect = (*cbi).second;
228 nassertv(effect != 0.0f);
232 if (channel_index >= 0 && channel_index < (
int)_channels.size()) {
233 channel = DCAST(
ChannelType, _channels[channel_index]);
243 if (!cdata->_frame_blend_flag) {
245 scale += iscale * effect;
246 hpr += ihpr * effect;
247 pos += ipos * effect;
248 shear += ishear * effect;
251 PN_stdfloat frac = (PN_stdfloat)control->
get_frac();
252 PN_stdfloat e0 = effect * (1.0f - frac);
254 scale += iscale * e0;
257 shear += ishear * e0;
261 channel->
get_hpr(next_frame, ihpr);
262 channel->
get_pos(next_frame, ipos);
264 PN_stdfloat e1 = effect * frac;
266 scale += iscale * e1;
269 shear += ishear * e1;
271 net_effect += effect;
275 if (net_effect == 0.0f) {
276 if (restore_initial_pose) {
277 _value = _default_value;
286 compose_matrix(_value, scale, shear, hpr, pos);
291 case PartBundle::BT_componentwise_quat:
299 PN_stdfloat net_effect = 0.0f;
301 PartBundle::ChannelBlend::const_iterator cbi;
302 for (cbi = cdata->_blend.begin(); cbi != cdata->_blend.end(); ++cbi) {
304 PN_stdfloat effect = (*cbi).second;
305 nassertv(effect != 0.0f);
309 if (channel_index >= 0 && channel_index < (
int)_channels.size()) {
310 channel = DCAST(
ChannelType, _channels[channel_index]);
321 if (!cdata->_frame_blend_flag) {
323 scale += iscale * effect;
324 quat += iquat * effect;
325 pos += ipos * effect;
326 shear += ishear * effect;
330 PN_stdfloat frac = (PN_stdfloat)control->
get_frac();
331 PN_stdfloat e0 = effect * (1.0f - frac);
333 scale += iscale * e0;
336 shear += ishear * e0;
340 channel->
get_quat(next_frame, iquat);
341 channel->
get_pos(next_frame, ipos);
343 PN_stdfloat e1 = effect * frac;
345 scale += iscale * e1;
348 shear += ishear * e1;
350 net_effect += effect;
354 if (net_effect == 0.0f) {
355 if (restore_initial_pose) {
356 _value = _default_value;
370 _value.set_row(3, pos);
406 _forced_channel = chan;
421 parse_params(params, scan, manager);
422 me->fillin(scan, manager);
static void register_with_read_factory()
Factory method to generate a MovingPartMatrix object.
A basic node of the scene graph or data graph.
This is the base class for all three-component vectors and points.
virtual void get_pos(int frame, LVecBase3 &pos)
Returns the x, y, and z translation 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.
virtual void get_scale(int frame, LVecBase3 &scale)
Returns the x, y, and z scale components associated with the current frame.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
virtual void get_blend_value(const PartBundle *root)
Attempts to blend the various matrix values indicated, and sets the _value member to the resulting ma...
static LMatrix4f scale_shear_mat(const LVecBase3f &scale, const LVecBase3f &shear, CoordinateSystem cs=CS_default)
Returns a matrix that applies the indicated scale and shear.
Base class for objects that can be written to and read from Bam files.
virtual bool apply_control(PandaNode *node)
Specifies a node to influence this particular joint so that it will always hold the node's transform...
void set_value_node(PandaNode *node)
Specifies a node whose transform will be queried each frame to implicitly specify the transform of th...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
virtual void get_hpr(int frame, LVecBase3 &hpr)
Returns the h, p, and r components associated with the current frame.
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
Parent class for all animation channels.
An animation channel that accepts a matrix each frame from some dynamic input provided by code...
This is a 4-by-4 transform matrix.
virtual void get_value_no_scale_shear(int frame, ValueType &value)
Returns the value associated with the current frame, with no scale or share components.
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...
virtual bool apply_freeze_matrix(const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale)
Freezes this particular joint so that it will always hold the specified transform.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
int get_next_frame() const
Returns the current integer frame number + 1, constrained to the range 0 <= f < get_num_frames().
static const LMatrix4f & zeros_mat()
Returns an matrix filled with zeros.
virtual AnimChannelBase * make_default_channel() const
Creates and returns a new AnimChannel that is not part of any hierarchy, but that returns the default...
This is a particular kind of MovingPart that accepts a matrix each frame.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the base quaternion class.
This is the root of a MovingPart hierarchy.
int get_channel_index() const
Returns the particular channel index associated with this AnimControl.
Controls the timing of a character animation.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
int get_frame() const
Returns the current integer frame number.
double get_frac() const
Returns the fractional part of the current frame.
virtual void get_shear(int frame, LVecBase3 &shear)
Returns the a, b, and c shear components associated with the current frame.
static TypedWritable * make_MovingPartMatrix(const FactoryParams ¶ms)
Factory method to generate a MovingPartMatrix object.