Show
Ignore:
Timestamp:
11/24/09 16:00:11 (4 years ago)
Author:
robert
Message:

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.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgParticle/Particle

    r10660 r10827  
    155155         
    156156        /// Get number of texture tiles 
    157         inline int getNumTiles() const { return _num_tile; } 
     157        inline int getNumTiles() const { return _end_tile - _start_tile + 1; } 
    158158         
    159159        /** Kill the particle on next update 
     
    247247        inline float getCurrentSize() const; 
    248248         
    249         /// Specify how the particle texture is tiled 
    250         inline void setTextureTile(int sTile, int tTile, int numTiles = 0); 
     249        /// Specify how the particle texture is tiled. 
     250        /// All tiles in the given range are sequentially displayed during the lifetime 
     251        /// of the particle. When no range is given, all tiles are displayed during the lifetime. 
     252        inline void setTextureTileRange(int sTile, int tTile, int startTile, int endTile); 
     253 
     254        /// Same as above, range starts at 0 and ends at end 
     255        inline void setTextureTile(int sTile, int tTile, int end = -1); 
    251256 
    252257        /// Set the previous particle 
     
    300305        float _s_tile; 
    301306        float _t_tile; 
    302         int _num_tile; 
     307        int _start_tile; 
     308        int _end_tile; 
    303309        int _cur_tile; 
    304310        float _s_coord; 
     
    567573    } 
    568574 
    569     inline void Particle::setTextureTile(int sTile, int tTile, int numTiles) 
    570     { 
    571         _s_tile = (sTile>0) ? 1.0f / static_cast<float>(sTile) : 1.0f; 
    572         _t_tile = (tTile>0) ? 1.0f / static_cast<float>(tTile) : 1.0f; 
    573         if (numTiles <= 0) 
    574         { 
    575             _num_tile = sTile * tTile; 
    576         } 
    577         else 
    578         { 
    579             _num_tile = numTiles; 
    580         } 
    581     } 
    582  
     575 
     576    inline void Particle::setTextureTile(int sTile, int tTile, int end) 
     577    { 
     578        setTextureTileRange(sTile, tTile, -1, end); 
     579    } 
     580 
     581    inline void Particle::setTextureTileRange(int sTile, int tTile, int startTile, int endTile) 
     582    { 
     583       _s_tile = (sTile>0) ? 1.0f / static_cast<float>(sTile) : 1.0f; 
     584       _t_tile = (tTile>0) ? 1.0f / static_cast<float>(tTile) : 1.0f; 
     585        
     586       if(startTile == -1) 
     587       { 
     588          _start_tile = 0; 
     589       } 
     590       else 
     591       { 
     592          _start_tile = startTile; 
     593       } 
     594 
     595       if(endTile == -1) 
     596       { 
     597          _end_tile = sTile * tTile; 
     598       } 
     599       else 
     600       { 
     601          _end_tile = endTile; 
     602       } 
     603    } 
    583604 
    584605}