An interpolator that offers flexible control over particle parameters. More...
Public Member Functions | |
void | setType (InterpolationType type, ModelParam param=PARAM_SIZE) |
Sets the value used to interpolate. | |
void | enableLooping (bool loop) |
Enables or disables the looping of the graph. | |
void | setScaleXVariation (float scaleXVariation) |
Sets the scale variation in x. | |
void | setOffsetXVariation (float offsetXVariation) |
Sets the offset variation in x. | |
InterpolationType | getType () const |
Gets the type of value used to interpolate. | |
ModelParam | getInterpolatorParam () const |
Gets the parameter used to interpolate. | |
bool | isLoopingEnabled () const |
Tells whether the looping is enabled or not. | |
float | getScaleXVariation () const |
Gets the scale variation along x. | |
float | getOffsetXVariation () const |
Gets the offset variation along x. | |
std::set< InterpolatorEntry > & | getGraph () |
Gets the graph of the interpolator. | |
const std::set < InterpolatorEntry > & | getGraph () const |
Gets the graph of the interpolator (constant version). | |
bool | addEntry (const InterpolatorEntry &entry) |
Adds an entry to the graph. | |
bool | addEntry (float x, float y) |
Adds an entry to the graph. | |
bool | addEntry (float x, float y0, float y1) |
Adds an entry to the graph. | |
void | clearGraph () |
Clears the graph (removes all the entries). | |
void | generateSinCurve (float period, float amplitudeMin, float amplitudeMax, float offsetX, float offsetY, float startX, unsigned int length, unsigned int nbSamples) |
Generates a sinusoidal curve. | |
void | generatePolyCurve (float constant, float linear, float quadratic, float cubic, float startX, float endX, unsigned int nbSamples) |
Generates a polynomial curve. |
An interpolator that offers flexible control over particle parameters.
An interpolator is created for each parameter of a model which is set as interpolated.
The user can get the interpolator of a parameter for a given model by calling Model::getInterpolator(ModelParam).
An interpolator can use several types of value to interpolate a given parameter :
Here is a description of how an interpolator works :
Internally an interpolator holds a list of entries which defines a 2D graph. The entries are sorted internally along the x axis.
Each entry have a unique x value and 2 y values (although both y can have the same value).
The x defines the value that will be used to interpolate the parameter value. This value depends on the type set of the interpolator.
For instance, if the type is INTERPOLATOR_AGE, the current x value will be the age of the particle.
Knowing the current x value, the interpolator interpolates the y value in function of the entries y values.
An interpolator holds 2 curves : the y0 one and the y1 one.
Each particle is given a random value between 0 and 1 which defines where between the y0 and the y1 curve the interpolated y value will be.
The final interpolated y value will be the value of the interpolated particle parameter for this frame.
Moreover the graph can loop or not :
Finally, it is possible to set a variation in the offset and the scale of the current x computed :
Each particle is given an offset and a scale to compute its current x depending on the variations set. The formula to compute the final current x is the following :
final current x = (current x + offset) * scale
offset being randomly generated per particle in [-offsetXVariation,+offsetXVariation]
scale being randomly generated per particle in 1.0 + [-scaleXVariation,+scaleXVariation]
The default values of the interpolator are the following :
Definition at line 130 of file SPK_Interpolator.h.
bool addEntry | ( | float | x, | |
float | y0, | |||
float | y1 | |||
) |
Adds an entry to the graph.
x | : the x of the entry to add | |
y0 | : the y0 of the entry to add | |
y1 | : the y1 of the entry to add |
Definition at line 371 of file SPK_Interpolator.h.
bool addEntry | ( | float | x, | |
float | y | |||
) |
Adds an entry to the graph.
x | : the x of the entry to add | |
y | : the y of the entry to add (y0 and y1 are set to y) |
Definition at line 366 of file SPK_Interpolator.h.
bool addEntry | ( | const InterpolatorEntry & | entry | ) |
Adds an entry to the graph.
entry | : the entry to add to the graph |
Definition at line 361 of file SPK_Interpolator.h.
void clearGraph | ( | ) |
Clears the graph (removes all the entries).
Definition at line 376 of file SPK_Interpolator.h.
void enableLooping | ( | bool | loop | ) |
Enables or disables the looping of the graph.
The range of the graph is defined between the entry with the minimum x and the entry with the maximum y.
If the looping is disabled, the x are clamped to the range.
If the looping is enabled, the value of x is reported in the range. It is better that the xmin and xmax have the same y values so that the graph tiles perfectly.
loop | : true to enabled the looping, false to disable it |
Definition at line 311 of file SPK_Interpolator.h.
void generatePolyCurve | ( | float | constant, | |
float | linear, | |||
float | quadratic, | |||
float | cubic, | |||
float | startX, | |||
float | endX, | |||
unsigned int | nbSamples | |||
) |
Generates a polynomial curve.
Note that the graph is previously cleared from all its entries
void generateSinCurve | ( | float | period, | |
float | amplitudeMin, | |||
float | amplitudeMax, | |||
float | offsetX, | |||
float | offsetY, | |||
float | startX, | |||
unsigned int | length, | |||
unsigned int | nbSamples | |||
) |
Generates a sinusoidal curve.
Note that the graph is previously cleared from all its entries
const std::set< InterpolatorEntry > & getGraph | ( | ) | const |
Gets the graph of the interpolator (constant version).
Definition at line 356 of file SPK_Interpolator.h.
std::set< InterpolatorEntry > & getGraph | ( | ) |
Gets the graph of the interpolator.
Definition at line 351 of file SPK_Interpolator.h.
ModelParam getInterpolatorParam | ( | ) | const |
Gets the parameter used to interpolate.
Note that the parameter is only used if the type is INTERPOLATOR_PARAM
Definition at line 331 of file SPK_Interpolator.h.
float getOffsetXVariation | ( | ) | const |
Gets the offset variation along x.
Definition at line 346 of file SPK_Interpolator.h.
float getScaleXVariation | ( | ) | const |
Gets the scale variation along x.
Definition at line 341 of file SPK_Interpolator.h.
InterpolationType getType | ( | ) | const |
Gets the type of value used to interpolate.
Definition at line 326 of file SPK_Interpolator.h.
bool isLoopingEnabled | ( | ) | const |
Tells whether the looping is enabled or not.
Definition at line 336 of file SPK_Interpolator.h.
void setOffsetXVariation | ( | float | offsetXVariation | ) |
Sets the offset variation in x.
See the class description for more information
offsetXVariation | : the offset variation in x |
Definition at line 321 of file SPK_Interpolator.h.
void setScaleXVariation | ( | float | scaleXVariation | ) |
Sets the scale variation in x.
See the class description for more information
scaleXVariation | : the scale variation in x |
Definition at line 316 of file SPK_Interpolator.h.
void setType | ( | InterpolationType | type, | |
ModelParam | param = PARAM_SIZE | |||
) |
Sets the value used to interpolate.
See the class description for more information.
Note that the argument param is only used when the type is INTERPOLATOR_PARAM.
type | : the type of value used to interpolate | |
param | : the parameter used to interpolate when the type is INTERPOLATOR_PARAM. |
Definition at line 305 of file SPK_Interpolator.h.