Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/chan/movingPartScalar.cxx

Go to the documentation of this file.
00001 // Filename: movingPartScalar.cxx
00002 // Created by:  drose (23Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 
00020 #include "movingPartScalar.h"
00021 #include <datagram.h>
00022 #include <datagramIterator.h>
00023 #include <bamReader.h>
00024 #include <bamWriter.h>
00025 
00026 // Tell GCC that we'll take care of the instantiation explicitly here.
00027 #ifdef __GNUC__
00028 #pragma implementation
00029 #endif
00030 
00031 TypeHandle MovingPartScalar::_type_handle;
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //     Function: MovingPartScalar::get_blend_value
00035 //       Access: Public
00036 //  Description: Attempts to blend the various scalar values
00037 //               indicated, and sets the _value member to the
00038 //               resulting scalar.
00039 ////////////////////////////////////////////////////////////////////
00040 void MovingPartScalar::
00041 get_blend_value(const PartBundle *root) {
00042   const PartBundle::ChannelBlend &blend = root->get_blend_map();
00043 
00044   if (blend.empty()) {
00045     // No channel is bound; supply the default value.
00046     _value = _initial_value;
00047 
00048   } else if (blend.size() == 1) {
00049     // A single value, the normal case.
00050     AnimControl *control = (*blend.begin()).first;
00051 
00052     int channel_index = control->get_channel_index();
00053     nassertv(channel_index >= 0 && channel_index < (int)_channels.size());
00054     ChannelType *channel = DCAST(ChannelType, _channels[channel_index]);
00055     nassertv(channel != NULL);
00056 
00057     channel->get_value(control->get_frame(), _value);
00058 
00059   } else {
00060     // A blend of two or more values.
00061     _value = 0.0f;
00062     float net = 0.0f;
00063 
00064     PartBundle::ChannelBlend::const_iterator cbi;
00065     for (cbi = blend.begin(); cbi != blend.end(); ++cbi) {
00066       AnimControl *control = (*cbi).first;
00067       float effect = (*cbi).second;
00068       nassertv(effect != 0.0f);
00069 
00070       int channel_index = control->get_channel_index();
00071       nassertv(channel_index >= 0 && channel_index < (int)_channels.size());
00072       ChannelType *channel = DCAST(ChannelType, _channels[channel_index]);
00073       nassertv(channel != NULL);
00074 
00075       ValueType v;
00076       channel->get_value(control->get_frame(), v);
00077 
00078       _value += v * effect;
00079       net += effect;
00080     }
00081 
00082     nassertv(net != 0.0f);
00083     _value /= net;
00084   }
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: MovingPartScalar::make_MovingPartScalar
00089 //       Access: Protected
00090 //  Description: Factory method to generate a MovingPartScalar object
00091 ////////////////////////////////////////////////////////////////////
00092 TypedWritable* MovingPartScalar::
00093 make_MovingPartScalar(const FactoryParams &params)
00094 {
00095   MovingPartScalar *me = new MovingPartScalar;
00096   DatagramIterator scan;
00097   BamReader *manager;
00098 
00099   parse_params(params, scan, manager);
00100   me->fillin(scan, manager);
00101   return me;
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //     Function: MovingPartScalar::register_with_factory
00106 //       Access: Public, Static
00107 //  Description: Factory method to generate a MovingPartScalar object
00108 ////////////////////////////////////////////////////////////////////
00109 void MovingPartScalar::
00110 register_with_read_factory(void)
00111 {
00112   BamReader::get_factory()->register_factory(get_class_type(), make_MovingPartScalar);
00113 }
00114 

Generated on Fri May 2 00:35:10 2003 for Panda by doxygen1.3