Updated the downcasting to use TypedReferenceCount' and added the 'enabled' field to the segment

This commit is contained in:
Josh Wilson 2005-06-16 20:56:16 +00:00
parent 8b1aa5c90a
commit dc8224f347
5 changed files with 150 additions and 124 deletions

View File

@ -135,12 +135,10 @@ set_period(const float p) {
// Function : ColorInterpolationSegment::get_function // Function : ColorInterpolationSegment::get_function
// Access : public // Access : public
// Description : Returns a reference to the function object // Description : Returns a reference to the function object
// corresponding to this segment. It should be downcast // corresponding to this segment.
// using the function's get_type() and the manager's
// downcastFunctionTo*****() functions.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE ColorInterpolationFunction* ColorInterpolationSegment:: INLINE TypedReferenceCount* ColorInterpolationSegment::
get_function(void) const { get_function(void) const {
return _color_inter_func; return _color_inter_func;
} }
@ -171,6 +169,17 @@ get_time_end(void) const {
return _t_end; return _t_end;
} }
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationSegment::is_enabled()
// Access : public
// Description : Returns whether the segments effects are being applied.
////////////////////////////////////////////////////////////////////
INLINE bool ColorInterpolationSegment::
is_enabled(void) const {
return _enabled;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationSegment::get_id // Function : ColorInterpolationSegment::get_id
// Access : public // Access : public
@ -223,6 +232,17 @@ set_time_end(const float time) {
_t_total = _t_end-_t_begin; _t_total = _t_end-_t_begin;
} }
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationSegment::set_enabled()
// Access : public
// Description : Sets whether the segments effects should be applied.
////////////////////////////////////////////////////////////////////
INLINE void ColorInterpolationSegment::
set_enabled(const bool enabled) {
_enabled = enabled;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationManager::get_segment // Function : ColorInterpolationManager::get_segment
// Access : public // Access : public

View File

@ -18,6 +18,12 @@
#include "colorInterpolationManager.h" #include "colorInterpolationManager.h"
#include "mathNumbers.h" #include "mathNumbers.h"
TypeHandle ColorInterpolationFunction::_type_handle;
TypeHandle ColorInterpolationFunctionConstant::_type_handle;
TypeHandle ColorInterpolationFunctionLinear::_type_handle;
TypeHandle ColorInterpolationFunctionStepwave::_type_handle;
TypeHandle ColorInterpolationFunctionSinusoid::_type_handle;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunction::ColorInterpolationFunction // Function : ColorInterpolationFunction::ColorInterpolationFunction
// Access : public // Access : public
@ -38,19 +44,6 @@ ColorInterpolationFunction::
~ColorInterpolationFunction(void) { ~ColorInterpolationFunction(void) {
} }
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunction::get_type
// Access : public
// Description : Returns a string of type of the current object.
// Since it is virtual, derived classes should define
// their own version.
////////////////////////////////////////////////////////////////////
string ColorInterpolationFunction::
get_type(void) {
return "ColorInterpolationFunction";
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunctionConstant::ColorInterpolationFunctionConstant // Function : ColorInterpolationFunctionConstant::ColorInterpolationFunctionConstant
// Access : public // Access : public
@ -84,17 +77,6 @@ interpolate(const float t) const {
return _c_a; return _c_a;
} }
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunctionConstant::get_type
// Access : protected
// Description : Returns a string representing this class type.
////////////////////////////////////////////////////////////////////
string ColorInterpolationFunctionConstant::
get_type(void) {
return "ColorInterpolationFunctionConstant";
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunctionLinear::ColorInterpolationFunctionLinear // Function : ColorInterpolationFunctionLinear::ColorInterpolationFunctionLinear
// Access : public // Access : public
@ -130,17 +112,6 @@ interpolate(const float t) const {
return (1.0f-t)*_c_a + t*_c_b; return (1.0f-t)*_c_a + t*_c_b;
} }
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunctionLinear::get_type
// Access : protected
// Description : Returns a string representing this class type.
////////////////////////////////////////////////////////////////////
string ColorInterpolationFunctionLinear::
get_type(void) {
return "ColorInterpolationFunctionLinear";
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunctionStepwave::ColorInterpolationFunctionStepwave // Function : ColorInterpolationFunctionStepwave::ColorInterpolationFunctionStepwave
// Access : public // Access : public
@ -183,17 +154,6 @@ interpolate(const float t) const {
return _c_b; return _c_b;
} }
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunctionStepwave::get_type
// Access : protected
// Description : Returns a string representing this class type.
////////////////////////////////////////////////////////////////////
string ColorInterpolationFunctionStepwave::
get_type(void) {
return "ColorInterpolationFunctionStepwave";
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunctionSinusoid::ColorInterpolationFunctionSinusoid // Function : ColorInterpolationFunctionSinusoid::ColorInterpolationFunctionSinusoid
// Access : public // Access : public
@ -233,17 +193,6 @@ interpolate(const float t) const {
return (weight_a*_c_a)+((1.0f-weight_a)*_c_b); return (weight_a*_c_a)+((1.0f-weight_a)*_c_b);
} }
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationFunctionSinusoid::get_type
// Access : protected
// Description : Returns a string representing this class type.
////////////////////////////////////////////////////////////////////
string ColorInterpolationFunctionSinusoid::
get_type(void) {
return "ColorInterpolationFunctionSinusoid";
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationSegment::ColorInterpolationSegment // Function : ColorInterpolationSegment::ColorInterpolationSegment
// Access : public // Access : public
@ -259,6 +208,7 @@ ColorInterpolationSegment(ColorInterpolationFunction* function,
_t_begin(time_begin), _t_begin(time_begin),
_t_end(time_end), _t_end(time_end),
_t_total(time_end-time_begin), _t_total(time_end-time_begin),
_enabled(true),
_id(id) { _id(id) {
} }
@ -274,6 +224,7 @@ ColorInterpolationSegment(const ColorInterpolationSegment &copy) :
_t_begin(copy._t_begin), _t_begin(copy._t_begin),
_t_end(copy._t_end), _t_end(copy._t_end),
_t_total(copy._t_total), _t_total(copy._t_total),
_enabled(copy._enabled),
_id(copy._id) { _id(copy._id) {
} }
@ -418,58 +369,6 @@ add_sinusoid(const float time_begin, const float time_end, const Colorf color_a,
return _id_generator++; return _id_generator++;
} }
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationManager::downcast_function_to_constant
// Access : public
// Description : Downcasts a ptr to abstract type
// ColorInterpolationFunction to concrete
// type ColorInterpolationFunctionConstant
////////////////////////////////////////////////////////////////////
ColorInterpolationFunctionConstant* ColorInterpolationManager::
downcast_function_to_constant(ColorInterpolationFunction* f) {
return (ColorInterpolationFunctionConstant*) f;
}
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationManager::downcast_function_to_linear
// Access : public
// Description : Downcasts a ptr to abstract type
// ColorInterpolationFunction to concrete
// type ColorInterpolationFunctionLinear
////////////////////////////////////////////////////////////////////
ColorInterpolationFunctionLinear* ColorInterpolationManager::
downcast_function_to_linear(ColorInterpolationFunction* f) {
return (ColorInterpolationFunctionLinear*) f;
}
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationManager::downcast_function_to_stepwave
// Access : public
// Description : Downcasts a ptr to abstract type
// ColorInterpolationFunction to concrete
// type ColorInterpolationFunctionStepwave
////////////////////////////////////////////////////////////////////
ColorInterpolationFunctionStepwave* ColorInterpolationManager::
downcast_function_to_stepwave(ColorInterpolationFunction* f) {
return (ColorInterpolationFunctionStepwave*) f;
}
////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationManager::downcast_function_to_sinusoid
// Access : public
// Description : Downcasts a ptr to abstract type
// ColorInterpolationFunction to concrete
// type ColorInterpolationFunctionSinusoid
////////////////////////////////////////////////////////////////////
ColorInterpolationFunctionSinusoid* ColorInterpolationManager::
downcast_function_to_sinusoid(ColorInterpolationFunction* f) {
return (ColorInterpolationFunctionSinusoid*) f;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function : ColorInterpolationManager::clear_segment // Function : ColorInterpolationManager::clear_segment
// Access : public // Access : public
@ -518,7 +417,9 @@ generateColor(const float interpolated_time) {
for(iter = _i_segs.begin();iter != _i_segs.end();++iter) { for(iter = _i_segs.begin();iter != _i_segs.end();++iter) {
cur_seg = (*iter); cur_seg = (*iter);
if( interpolated_time >= cur_seg->get_time_begin() && interpolated_time <= cur_seg->get_time_end() ) { if( cur_seg->is_enabled() &&
interpolated_time >= cur_seg->get_time_begin()
&& interpolated_time <= cur_seg->get_time_end() ) {
segment_found = true; segment_found = true;
out += cur_seg->interpolateColor(interpolated_time); out += cur_seg->interpolateColor(interpolated_time);
out[0] = max(0,min(out[0],1.0f)); out[0] = max(0,min(out[0],1.0f));

View File

@ -21,6 +21,7 @@
#include "luse.h" #include "luse.h"
#include "pvector.h" #include "pvector.h"
#include "typedObject.h"
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : ColorInterpolationFunction // Class : ColorInterpolationFunction
@ -29,15 +30,33 @@
// function. // function.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class ColorInterpolationFunction : public ReferenceCount { class ColorInterpolationFunction : public TypedReferenceCount {
PUBLISHED: PUBLISHED:
virtual string get_type(void); // virtual string get_type(void);
public: public:
ColorInterpolationFunction(void); ColorInterpolationFunction(void);
virtual ~ColorInterpolationFunction(void); virtual ~ColorInterpolationFunction(void);
virtual Colorf interpolate(const float t = 0) const = 0; virtual Colorf interpolate(const float t = 0) const = 0;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedReferenceCount::init_type();
register_type(_type_handle, "ColorInterpolationFunction",
TypedReferenceCount::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
}; };
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -58,9 +77,27 @@ public:
protected: protected:
virtual Colorf interpolate(const float t = 0) const; virtual Colorf interpolate(const float t = 0) const;
virtual string get_type(void); // virtual string get_type(void);
Colorf _c_a; Colorf _c_a;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
ColorInterpolationFunction::init_type();
register_type(_type_handle, "ColorInterpolationFunctionConstant",
ColorInterpolationFunction::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
}; };
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -81,9 +118,27 @@ public:
protected: protected:
Colorf interpolate(const float t = 0) const; Colorf interpolate(const float t = 0) const;
virtual string get_type(void); // virtual string get_type(void);
Colorf _c_b; Colorf _c_b;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
ColorInterpolationFunctionConstant::init_type();
register_type(_type_handle, "ColorInterpolationFunctionLinear",
ColorInterpolationFunctionConstant::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
}; };
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -109,10 +164,28 @@ public:
protected: protected:
Colorf interpolate(const float t = 0) const; Colorf interpolate(const float t = 0) const;
virtual string get_type(void); // virtual string get_type(void);
float _w_a; float _w_a;
float _w_b; float _w_b;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
ColorInterpolationFunctionLinear::init_type();
register_type(_type_handle, "ColorInterpolationFunctionStepwave",
ColorInterpolationFunctionLinear::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
}; };
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -137,9 +210,27 @@ public:
protected: protected:
Colorf interpolate(const float t = 0) const; Colorf interpolate(const float t = 0) const;
virtual string get_type(void); // virtual string get_type(void);
float _period; float _period;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
ColorInterpolationFunctionLinear::init_type();
register_type(_type_handle, "ColorInterpolationFunctionSinusoid",
ColorInterpolationFunctionLinear::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
}; };
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -156,14 +247,17 @@ PUBLISHED:
ColorInterpolationSegment(const ColorInterpolationSegment &s); ColorInterpolationSegment(const ColorInterpolationSegment &s);
virtual ~ColorInterpolationSegment(void); virtual ~ColorInterpolationSegment(void);
INLINE ColorInterpolationFunction* get_function(void) const; // INLINE ColorInterpolationFunction* get_function(void) const;
INLINE TypedReferenceCount* get_function(void) const;
INLINE float get_time_begin(void) const; INLINE float get_time_begin(void) const;
INLINE float get_time_end(void) const; INLINE float get_time_end(void) const;
INLINE int get_id(void) const; INLINE int get_id(void) const;
INLINE bool is_enabled(void) const;
INLINE void set_function(ColorInterpolationFunction* function); INLINE void set_function(ColorInterpolationFunction* function);
INLINE void set_time_begin(const float time); INLINE void set_time_begin(const float time);
INLINE void set_time_end(const float time); INLINE void set_time_end(const float time);
INLINE void set_enabled(const bool enabled);
public: public:
Colorf interpolateColor(const float t) const; Colorf interpolateColor(const float t) const;
@ -173,6 +267,7 @@ protected:
float _t_begin; float _t_begin;
float _t_end; float _t_end;
float _t_total; float _t_total;
bool _enabled;
const int _id; const int _id;
}; };
@ -196,12 +291,12 @@ ColorInterpolationManager(void);
int add_linear(const float time_begin = 0.0f, const float time_end = 1.0f, const Colorf color_a = Colorf(1.0f,0.0f,0.0f,1.0f), const Colorf color_b = Colorf(0.0f,1.0f,0.0f,1.0f)); int add_linear(const float time_begin = 0.0f, const float time_end = 1.0f, const Colorf color_a = Colorf(1.0f,0.0f,0.0f,1.0f), const Colorf color_b = Colorf(0.0f,1.0f,0.0f,1.0f));
int add_stepwave(const float time_begin = 0.0f, const float time_end = 1.0f, const Colorf color_a = Colorf(1.0f,0.0f,0.0f,1.0f), const Colorf color_b = Colorf(0.0f,1.0f,0.0f,1.0f), const float width_a = 0.5f, const float width_b = 0.5f); int add_stepwave(const float time_begin = 0.0f, const float time_end = 1.0f, const Colorf color_a = Colorf(1.0f,0.0f,0.0f,1.0f), const Colorf color_b = Colorf(0.0f,1.0f,0.0f,1.0f), const float width_a = 0.5f, const float width_b = 0.5f);
int add_sinusoid(const float time_begin = 0.0f, const float time_end = 1.0f, const Colorf color_a = Colorf(1.0f,0.0f,0.0f,1.0f), const Colorf color_b = Colorf(0.0f,1.0f,0.0f,1.0f), const float period = 1.0f); int add_sinusoid(const float time_begin = 0.0f, const float time_end = 1.0f, const Colorf color_a = Colorf(1.0f,0.0f,0.0f,1.0f), const Colorf color_b = Colorf(0.0f,1.0f,0.0f,1.0f), const float period = 1.0f);
/*
static ColorInterpolationFunctionConstant* downcast_function_to_constant(ColorInterpolationFunction* f); static ColorInterpolationFunctionConstant* downcast_function_to_constant(ColorInterpolationFunction* f);
static ColorInterpolationFunctionLinear* downcast_function_to_linear(ColorInterpolationFunction* f); static ColorInterpolationFunctionLinear* downcast_function_to_linear(ColorInterpolationFunction* f);
static ColorInterpolationFunctionStepwave* downcast_function_to_stepwave(ColorInterpolationFunction* f); static ColorInterpolationFunctionStepwave* downcast_function_to_stepwave(ColorInterpolationFunction* f);
static ColorInterpolationFunctionSinusoid* downcast_function_to_sinusoid(ColorInterpolationFunction* f); static ColorInterpolationFunctionSinusoid* downcast_function_to_sinusoid(ColorInterpolationFunction* f);
*/
INLINE ColorInterpolationSegment* get_segment(const int seg_id); INLINE ColorInterpolationSegment* get_segment(const int seg_id);
INLINE string get_segment_id_list(void); INLINE string get_segment_id_list(void);
void clear_segment(const int seg_id); void clear_segment(const int seg_id);

View File

@ -24,6 +24,11 @@ ConfigureDef(config_particlesystem);
NotifyCategoryDef(particlesystem, ""); NotifyCategoryDef(particlesystem, "");
ConfigureFn(config_particlesystem) { ConfigureFn(config_particlesystem) {
ColorInterpolationFunction::init_type();
ColorInterpolationFunctionConstant::init_type();
ColorInterpolationFunctionLinear::init_type();
ColorInterpolationFunctionStepwave::init_type();
ColorInterpolationFunctionSinusoid::init_type();
init_libparticlesystem(); init_libparticlesystem();
} }

View File

@ -60,6 +60,11 @@ SpriteParticleRenderer(Texture *tex) :
_color_interpolation_manager(new ColorInterpolationManager(_color)) _color_interpolation_manager(new ColorInterpolationManager(_color))
{ {
init_geoms(); init_geoms();
if(use_qpgeom)
cout<<"using qpgeoms"<<endl;
else
cout<<"not using qpgeoms"<<endl;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////