14 #include "colorInterpolationManager.h"
15 #include "mathNumbers.h"
17 TypeHandle ColorInterpolationFunction::_type_handle;
18 TypeHandle ColorInterpolationFunctionConstant::_type_handle;
19 TypeHandle ColorInterpolationFunctionLinear::_type_handle;
20 TypeHandle ColorInterpolationFunctionStepwave::_type_handle;
21 TypeHandle ColorInterpolationFunctionSinusoid::_type_handle;
51 _c_a(1.0f,1.0f,1.0f,1.0f) {
71 LColor ColorInterpolationFunctionConstant::
72 interpolate(
const PN_stdfloat t)
const {
84 _c_b(1.0f,1.0f,1.0f,1.0f) {
106 LColor ColorInterpolationFunctionLinear::
107 interpolate(
const PN_stdfloat t)
const {
108 return (1.0f-t)*_c_a + t*_c_b;
132 const PN_stdfloat width_a,
133 const PN_stdfloat width_b) :
145 LColor ColorInterpolationFunctionStepwave::
146 interpolate(
const PN_stdfloat t)
const {
147 if(fmodf(t,(_w_a+_w_b))<_w_a) {
173 const PN_stdfloat period) :
186 LColor ColorInterpolationFunctionSinusoid::
187 interpolate(
const PN_stdfloat t)
const {
188 PN_stdfloat weight_a = (1.0f+cos(t*MathNumbers::pi_f*2.0f/_period))/2.0f;
189 return (weight_a*_c_a)+((1.0f-weight_a)*_c_b);
200 const PN_stdfloat &time_begin,
201 const PN_stdfloat &time_end,
202 const bool is_modulated,
204 _color_inter_func(function),
205 _t_begin(time_begin),
207 _t_total(time_end-time_begin),
208 _is_modulated(is_modulated),
221 _color_inter_func(copy._color_inter_func),
222 _t_begin(copy._t_begin),
224 _t_total(copy._t_total),
225 _is_modulated(copy._is_modulated),
226 _enabled(copy._enabled),
251 return _color_inter_func->interpolate((t-_t_begin)/_t_total);
262 _default_color(
LColor(1.0f,1.0f,1.0f,1.0f)),
286 _default_color(copy._default_color),
287 _i_segs(copy._i_segs),
288 _id_generator(copy._id_generator) {
314 _i_segs.push_back(sPtr);
316 return _id_generator++;
327 add_linear(
const PN_stdfloat time_begin,
const PN_stdfloat time_end,
const LColor &color_a,
const LColor &color_b,
const bool is_modulated) {
331 _i_segs.push_back(sPtr);
333 return _id_generator++;
344 add_stepwave(
const PN_stdfloat time_begin,
const PN_stdfloat time_end,
const LColor &color_a,
const LColor &color_b,
const PN_stdfloat width_a,
const PN_stdfloat width_b,
const bool is_modulated) {
348 _i_segs.push_back(sPtr);
350 return _id_generator++;
362 add_sinusoid(
const PN_stdfloat time_begin,
const PN_stdfloat time_end,
const LColor &color_a,
const LColor &color_b,
const PN_stdfloat period,
const bool is_modulated) {
366 _i_segs.push_back(sPtr);
368 return _id_generator++;
381 for(iter = _i_segs.begin();iter != _i_segs.end();++iter) {
382 if( seg_id == (*iter)->get_id() ) {
412 bool segment_found =
false;
413 LColor out(_default_color);
417 for (iter = _i_segs.begin();iter != _i_segs.end();++iter) {
422 segment_found =
true;
425 out[0] *= cur_color[0];
426 out[1] *= cur_color[1];
427 out[2] *= cur_color[2];
428 out[3] *= cur_color[3];
431 out[0] += cur_color[0];
432 out[1] += cur_color[1];
433 out[2] += cur_color[2];
434 out[3] += cur_color[3];
440 out[0] = max((PN_stdfloat)0.0, min(out[0], (PN_stdfloat)1.0));
441 out[1] = max((PN_stdfloat)0.0, min(out[1], (PN_stdfloat)1.0));
442 out[2] = max((PN_stdfloat)0.0, min(out[2], (PN_stdfloat)1.0));
443 out[3] = max((PN_stdfloat)0.0, min(out[3], (PN_stdfloat)1.0));
447 return _default_color;
PN_stdfloat get_time_begin() const
Returns the point in the particle's lifetime at which this segment begins its effect.
PN_stdfloat get_time_end() const
Returns the point in the particle's lifetime at which this segment's effect stops.
virtual ~ColorInterpolationSegment()
destructor
ColorInterpolationManager()
default constructor
int add_sinusoid(const PN_stdfloat time_begin=0.0f, const PN_stdfloat time_end=1.0f, const LColor &color_a=LColor(1.0f, 0.0f, 0.0f, 1.0f), const LColor &color_b=LColor(0.0f, 1.0f, 0.0f, 1.0f), const PN_stdfloat period=1.0f, const bool is_modulated=true)
Adds a stepwave segment of two colors and a specified period to the manager and returns the segment's...
bool is_modulated() const
Returns whether the function is additive or modulated.
A single unit of interpolation.
ColorInterpolationFunctionConstant()
default constructor
void clear_segment(const int seg_id)
Removes the segment of 'id' from the manager.
int add_constant(const PN_stdfloat time_begin=0.0f, const PN_stdfloat time_end=1.0f, const LColor &color=LColor(1.0f, 1.0f, 1.0f, 1.0f), const bool is_modulated=true)
Adds a constant segment of the specified color to the manager and returns the segment's id as known b...
virtual ~ColorInterpolationManager()
destructor
ColorInterpolationSegment(ColorInterpolationFunction *function, const PN_stdfloat &time_begin, const PN_stdfloat &time_end, const bool is_modulated, const int id)
constructor
ColorInterpolationFunctionLinear()
default constructor
This is our own Panda specialization on the default STL vector.
void clear_to_initial()
Removes all segments from the manager.
int add_linear(const PN_stdfloat time_begin=0.0f, const PN_stdfloat time_end=1.0f, const LColor &color_a=LColor(1.0f, 0.0f, 0.0f, 1.0f), const LColor &color_b=LColor(0.0f, 1.0f, 0.0f, 1.0f), const bool is_modulated=true)
Adds a linear segment between two colors to the manager and returns the segment's id as known by the ...
ColorInterpolationFunctionStepwave()
default constructor
High level class for color interpolation.
Defines a discrete cyclical transition between two colors.
ColorInterpolationFunctionSinusoid()
default constructor
Defines a sinusoidal blending between two colors.
Abstract class from which all other functions should inherit.
This is the base class for all three-component vectors and points.
int add_stepwave(const PN_stdfloat time_begin=0.0f, const PN_stdfloat time_end=1.0f, const LColor &color_a=LColor(1.0f, 0.0f, 0.0f, 1.0f), const LColor &color_b=LColor(0.0f, 1.0f, 0.0f, 1.0f), const PN_stdfloat width_a=0.5f, const PN_stdfloat width_b=0.5f, const bool is_modulated=true)
Adds a stepwave segment of two colors to the manager and returns the segment's id as known by the man...
LColor generateColor(const PN_stdfloat interpolated_time)
For time 'interpolated_time', this returns the additive composite color of all segments that influenc...
LColor interpolateColor(const PN_stdfloat t) const
Returns the interpolated color according to the segment's function and start and end times...
TypeHandle is the identifier used to differentiate C++ class types.
virtual ~ColorInterpolationFunction()
destructor
Defines a constant color over the lifetime of the segment.
Defines a linear interpolation over the lifetime of the segment.
bool is_enabled() const
Returns whether the segments effects are being applied.
ColorInterpolationFunction()
constructor