20 TypeHandle ColorInterpolationFunction::_type_handle;
21 TypeHandle ColorInterpolationFunctionConstant::_type_handle;
22 TypeHandle ColorInterpolationFunctionLinear::_type_handle;
23 TypeHandle ColorInterpolationFunctionStepwave::_type_handle;
24 TypeHandle ColorInterpolationFunctionSinusoid::_type_handle;
48 _c_a(1.0f,1.0f,1.0f,1.0f) {
64 LColor ColorInterpolationFunctionConstant::
65 interpolate(
const PN_stdfloat t)
const {
75 _c_b(1.0f,1.0f,1.0f,1.0f) {
84 const LColor &color_b) :
93 LColor ColorInterpolationFunctionLinear::
94 interpolate(
const PN_stdfloat t)
const {
95 return (1.0f-t)*_c_a + t*_c_b;
114 const LColor &color_b,
115 const PN_stdfloat width_a,
116 const PN_stdfloat width_b) :
126 LColor ColorInterpolationFunctionStepwave::
127 interpolate(
const PN_stdfloat t)
const {
128 if(fmodf(t,(_w_a+_w_b))<_w_a) {
149 const LColor &color_b,
150 const PN_stdfloat period) :
160 LColor ColorInterpolationFunctionSinusoid::
161 interpolate(
const PN_stdfloat t)
const {
162 PN_stdfloat weight_a = (1.0f+cos(t*MathNumbers::pi_f*2.0f/_period))/2.0f;
163 return (weight_a*_c_a)+((1.0f-weight_a)*_c_b);
172 const PN_stdfloat &time_begin,
173 const PN_stdfloat &time_end,
174 const bool is_modulated,
176 _color_inter_func(function),
177 _t_begin(time_begin),
179 _t_total(time_end-time_begin),
180 _is_modulated(is_modulated),
191 _color_inter_func(copy._color_inter_func),
192 _t_begin(copy._t_begin),
194 _t_total(copy._t_total),
195 _is_modulated(copy._is_modulated),
196 _enabled(copy._enabled),
216 return _color_inter_func->interpolate((t-_t_begin)/_t_total);
225 _default_color(LColor(1.0f,1.0f,1.0f,1.0f)),
245 _default_color(copy._default_color),
246 _i_segs(copy._i_segs),
247 _id_generator(copy._id_generator) {
264 add_constant(
const PN_stdfloat time_begin,
const PN_stdfloat time_end,
const LColor &color,
const bool is_modulated) {
268 _i_segs.push_back(sPtr);
270 return _id_generator++;
279 add_linear(
const PN_stdfloat time_begin,
const PN_stdfloat time_end,
const LColor &color_a,
const LColor &color_b,
const bool is_modulated) {
283 _i_segs.push_back(sPtr);
285 return _id_generator++;
294 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) {
298 _i_segs.push_back(sPtr);
300 return _id_generator++;
309 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) {
313 _i_segs.push_back(sPtr);
315 return _id_generator++;
326 for(iter = _i_segs.begin();iter != _i_segs.end();++iter) {
327 if( seg_id == (*iter)->get_id() ) {
352 bool segment_found =
false;
353 LColor out(_default_color);
357 for (iter = _i_segs.begin();iter != _i_segs.end();++iter) {
362 segment_found =
true;
365 out[0] *= cur_color[0];
366 out[1] *= cur_color[1];
367 out[2] *= cur_color[2];
368 out[3] *= cur_color[3];
371 out[0] += cur_color[0];
372 out[1] += cur_color[1];
373 out[2] += cur_color[2];
374 out[3] += cur_color[3];
380 out[0] = max((PN_stdfloat)0.0, min(out[0], (PN_stdfloat)1.0));
381 out[1] = max((PN_stdfloat)0.0, min(out[1], (PN_stdfloat)1.0));
382 out[2] = max((PN_stdfloat)0.0, min(out[2], (PN_stdfloat)1.0));
383 out[3] = max((PN_stdfloat)0.0, min(out[3], (PN_stdfloat)1.0));
387 return _default_color;
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...
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
bool is_enabled() const
Returns whether the segments effects are being applied.
LColor interpolateColor(const PN_stdfloat t) const
Returns the interpolated color according to the segment's function and start and end times.
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.
PN_stdfloat get_time_begin() const
Returns the point in the particle's lifetime at which this segment begins its effect.
ColorInterpolationFunctionSinusoid()
default constructor
Defines a sinusoidal blending between two colors.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Abstract class from which all other functions should inherit.
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...
PN_stdfloat get_time_end() const
Returns the point in the particle's lifetime at which this segment's effect stops.
LColor generateColor(const PN_stdfloat interpolated_time)
For time 'interpolated_time', this returns the additive composite color of all segments that influenc...
TypeHandle is the identifier used to differentiate C++ class types.
virtual ~ColorInterpolationFunction()
destructor
bool is_modulated() const
Returns whether the function is additive or modulated.
Defines a constant color over the lifetime of the segment.
Defines a linear interpolation over the lifetime of the segment.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ColorInterpolationFunction()
constructor