From Martin Scheffler, "osgParticle: method to set start and end tile for particle texture (for animated particles). I also updated examples/osgParticle to show the feature.

The texture in data/Images should be copied to osg-data. I created the texture myself with the help of an explosion generator, so no license issues there.
"
This commit is contained in:
Robert Osfield
2009-11-24 15:00:11 +00:00
parent f79f465467
commit a3adc3d07c
3 changed files with 156 additions and 17 deletions

View File

@@ -154,7 +154,7 @@ namespace osgParticle
inline int getTileT() const;
/// Get number of texture tiles
inline int getNumTiles() const { return _num_tile; }
inline int getNumTiles() const { return _end_tile - _start_tile + 1; }
/** Kill the particle on next update
NOTE: after calling this function, the <CODE>isAlive()</CODE> method will still
@@ -246,8 +246,13 @@ namespace osgParticle
/// Get the current (interpolated) polygon size. Valid only after the first call to update().
inline float getCurrentSize() const;
/// Specify how the particle texture is tiled
inline void setTextureTile(int sTile, int tTile, int numTiles = 0);
/// Specify how the particle texture is tiled.
/// All tiles in the given range are sequentially displayed during the lifetime
/// of the particle. When no range is given, all tiles are displayed during the lifetime.
inline void setTextureTileRange(int sTile, int tTile, int startTile, int endTile);
/// Same as above, range starts at 0 and ends at end
inline void setTextureTile(int sTile, int tTile, int end = -1);
/// Set the previous particle
inline void setPreviousParticle(int previous) { _previousParticle = previous; }
@@ -299,7 +304,8 @@ namespace osgParticle
float _s_tile;
float _t_tile;
int _num_tile;
int _start_tile;
int _end_tile;
int _cur_tile;
float _s_coord;
float _t_coord;
@@ -566,20 +572,35 @@ namespace osgParticle
return _current_size;
}
inline void Particle::setTextureTile(int sTile, int tTile, int numTiles)
inline void Particle::setTextureTile(int sTile, int tTile, int end)
{
_s_tile = (sTile>0) ? 1.0f / static_cast<float>(sTile) : 1.0f;
_t_tile = (tTile>0) ? 1.0f / static_cast<float>(tTile) : 1.0f;
if (numTiles <= 0)
{
_num_tile = sTile * tTile;
}
else
{
_num_tile = numTiles;
}
setTextureTileRange(sTile, tTile, -1, end);
}
inline void Particle::setTextureTileRange(int sTile, int tTile, int startTile, int endTile)
{
_s_tile = (sTile>0) ? 1.0f / static_cast<float>(sTile) : 1.0f;
_t_tile = (tTile>0) ? 1.0f / static_cast<float>(tTile) : 1.0f;
if(startTile == -1)
{
_start_tile = 0;
}
else
{
_start_tile = startTile;
}
if(endTile == -1)
{
_end_tile = sTile * tTile;
}
else
{
_end_tile = endTile;
}
}
}