added choice of additive or modulated mode

This commit is contained in:
Josh Wilson 2006-04-23 23:52:00 +00:00
parent f71690b252
commit eea0bf839e
3 changed files with 47 additions and 6 deletions

View File

@ -169,6 +169,17 @@ get_time_end() const {
return _t_end;
}
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationSegment::is_modulated
// Access : public
// Description : Returns whether the function is additive or modulated.
////////////////////////////////////////////////////////////////////
INLINE bool ColorInterpolationSegment::
is_modulated() const {
return _is_modulated;
}
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationSegment::is_enabled()
// Access : public
@ -232,6 +243,19 @@ set_time_end(const float time) {
_t_total = _t_end-_t_begin;
}
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationSegment::set_is_modulated
// Access : public
// Description : Sets how the function is applied to the final color.
// If true, the value is multiplied. If false, the value
// is simply added. Default is true.
////////////////////////////////////////////////////////////////////
INLINE void ColorInterpolationSegment::
set_is_modulated(const bool flag) {
_is_modulated = flag;
}
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationSegment::set_enabled()
// Access : public

View File

@ -208,6 +208,7 @@ ColorInterpolationSegment(ColorInterpolationFunction* function,
_t_begin(time_begin),
_t_end(time_end),
_t_total(time_end-time_begin),
_is_modulated(true),
_enabled(true),
_id(id) {
}
@ -224,6 +225,7 @@ ColorInterpolationSegment(const ColorInterpolationSegment &copy) :
_t_begin(copy._t_begin),
_t_end(copy._t_end),
_t_total(copy._t_total),
_is_modulated(copy._is_modulated),
_enabled(copy._enabled),
_id(copy._id) {
}
@ -411,7 +413,7 @@ clear_to_initial() {
Colorf ColorInterpolationManager::
generateColor(const float interpolated_time) {
bool segment_found = false;
Colorf out(0.0f,0.0f,0.0f,0.0f);
Colorf out(_default_color);
ColorInterpolationSegment *cur_seg;
pvector<PT(ColorInterpolationSegment)>::iterator iter;
@ -421,15 +423,27 @@ generateColor(const float interpolated_time) {
interpolated_time >= cur_seg->get_time_begin()
&& interpolated_time <= cur_seg->get_time_end() ) {
segment_found = true;
out += cur_seg->interpolateColor(interpolated_time);
out[0] = max(0.0f, min(out[0], 1.0f));
out[1] = max(0.0f, min(out[1], 1.0f));
out[2] = max(0.0f, min(out[2], 1.0f));
out[3] = max(0.0f, min(out[3], 1.0f));
Colorf cur_color = cur_seg->interpolateColor(interpolated_time);
if( cur_seg->is_modulated() ) {
out[0] *= cur_color[0];
out[1] *= cur_color[1];
out[2] *= cur_color[2];
out[3] *= cur_color[3];
}
else {
out[0] += cur_color[0];
out[1] += cur_color[1];
out[2] += cur_color[2];
out[3] += cur_color[3];
}
}
}
if(segment_found) {
out[0] = max(0.0f, min(out[0], 1.0f));
out[1] = max(0.0f, min(out[1], 1.0f));
out[2] = max(0.0f, min(out[2], 1.0f));
out[3] = max(0.0f, min(out[3], 1.0f));
return out;
}

View File

@ -252,12 +252,14 @@ PUBLISHED:
INLINE TypedReferenceCount* get_function() const;
INLINE float get_time_begin() const;
INLINE float get_time_end() const;
INLINE bool is_modulated() const;
INLINE int get_id() const;
INLINE bool is_enabled() const;
INLINE void set_function(ColorInterpolationFunction* function);
INLINE void set_time_begin(const float time);
INLINE void set_time_end(const float time);
INLINE void set_is_modulated(const bool flag);
INLINE void set_enabled(const bool enabled);
public:
@ -268,6 +270,7 @@ protected:
float _t_begin;
float _t_end;
float _t_total;
bool _is_modulated;
bool _enabled;
const int _id;
};