00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "movingPartMatrix.h"
00021
00022 #include <compose_matrix.h>
00023 #include <datagram.h>
00024 #include <datagramIterator.h>
00025 #include <bamReader.h>
00026 #include <bamWriter.h>
00027
00028
00029 #ifdef __GNUC__
00030 #pragma implementation
00031 #endif
00032
00033 TypeHandle MovingPartMatrix::_type_handle;
00034
00035
00036
00037
00038
00039
00040
00041
00042 void MovingPartMatrix::
00043 get_blend_value(const PartBundle *root) {
00044 const PartBundle::ChannelBlend &blend = root->get_blend_map();
00045
00046 if (blend.empty()) {
00047
00048 _value = _initial_value;
00049
00050 } else if (blend.size() == 1) {
00051
00052 AnimControl *control = (*blend.begin()).first;
00053
00054 int channel_index = control->get_channel_index();
00055 nassertv(channel_index >= 0 && channel_index < (int)_channels.size());
00056 ChannelType *channel = DCAST(ChannelType, _channels[channel_index]);
00057 nassertv(channel != NULL);
00058
00059 channel->get_value(control->get_frame(), _value);
00060
00061 } else {
00062
00063
00064 if (root->get_blend_type() == PartBundle::BT_linear) {
00065
00066 _value = 0.0f;
00067 float net = 0.0f;
00068
00069 PartBundle::ChannelBlend::const_iterator cbi;
00070 for (cbi = blend.begin(); cbi != blend.end(); ++cbi) {
00071 AnimControl *control = (*cbi).first;
00072 float effect = (*cbi).second;
00073 nassertv(effect != 0.0f);
00074
00075 int channel_index = control->get_channel_index();
00076 nassertv(channel_index >= 0 && channel_index < (int)_channels.size());
00077 ChannelType *channel = DCAST(ChannelType, _channels[channel_index]);
00078 nassertv(channel != NULL);
00079
00080 ValueType v;
00081 channel->get_value(control->get_frame(), v);
00082
00083 _value += v * effect;
00084 net += effect;
00085 }
00086
00087 nassertv(net != 0.0f);
00088 _value /= net;
00089
00090 } else if (root->get_blend_type() == PartBundle::BT_normalized_linear) {
00091
00092
00093
00094
00095
00096 _value = 0.0f;
00097 LVector3f scale(0.0f, 0.0f, 0.0f);
00098 float net = 0.0f;
00099
00100 PartBundle::ChannelBlend::const_iterator cbi;
00101 for (cbi = blend.begin(); cbi != blend.end(); ++cbi) {
00102 AnimControl *control = (*cbi).first;
00103 float effect = (*cbi).second;
00104 nassertv(effect != 0.0f);
00105
00106 int channel_index = control->get_channel_index();
00107 nassertv(channel_index >= 0 && channel_index < (int)_channels.size());
00108 ChannelType *channel = DCAST(ChannelType, _channels[channel_index]);
00109 nassertv(channel != NULL);
00110
00111 ValueType v;
00112 channel->get_value_no_scale(control->get_frame(), v);
00113 LVector3f s;
00114 channel->get_scale(control->get_frame(), &s[0]);
00115
00116 _value += v * effect;
00117 scale += s * effect;
00118 net += effect;
00119 }
00120
00121 nassertv(net != 0.0f);
00122 _value /= net;
00123 scale /= net;
00124
00125
00126
00127 LVector3f false_scale, hpr, translate;
00128 decompose_matrix(_value, false_scale, hpr, translate);
00129 compose_matrix(_value, scale, hpr, translate);
00130 }
00131 }
00132 }
00133
00134
00135
00136
00137
00138
00139 TypedWritable* MovingPartMatrix::
00140 make_MovingPartMatrix(const FactoryParams ¶ms)
00141 {
00142 MovingPartMatrix *me = new MovingPartMatrix;
00143 DatagramIterator scan;
00144 BamReader *manager;
00145
00146 parse_params(params, scan, manager);
00147 me->fillin(scan, manager);
00148 return me;
00149 }
00150
00151
00152
00153
00154
00155
00156 void MovingPartMatrix::
00157 register_with_read_factory(void)
00158 {
00159 BamReader::get_factory()->register_factory(get_class_type(), make_MovingPartMatrix);
00160 }