Thanks Rosme and Skylark,

I've modified the Particle class to allow me to specify start and end tiles for 
a particle. I am uploading a patch for the class with this post, maybe you 
could include it (or the functionality it describes) in the distro?

I can now shoot particles with different animations from the same particle 
system. Neat! I've looked into the premultiplied alpha stuff, and it seems to 
work OK. Thanks for the tip!

Cheers,
Martin

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=15702#15702



Index: include/osgParticle/Particle
===================================================================
--- include/osgParticle/Particle        (revision 10517)
+++ include/osgParticle/Particle        (working copy)
@@ -153,7 +153,7 @@
         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 
@@ -245,9 +245,14 @@
         /// 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; }
 
@@ -298,7 +303,8 @@
         
         float _s_tile;
         float _t_tile;
-        int _num_tile;
+        int _start_tile;
+        int _end_tile;
         int _cur_tile;
         float _s_coord;
         float _t_coord;
@@ -565,21 +571,36 @@
         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;
+       }
+    }
+
 }
 
 #endif
Index: src/osgParticle/Particle.cpp
===================================================================
--- src/osgParticle/Particle.cpp        (revision 10517)
+++ src/osgParticle/Particle.cpp        (working copy)
@@ -45,7 +45,8 @@
     _current_alpha(0),
     _s_tile(1.0f),
     _t_tile(1.0f),
-    _num_tile(1),
+    _start_tile(0),
+    _end_tile(0),
     _cur_tile(-1),
     _s_coord(0.0f),
     _t_coord(0.0f),
@@ -79,7 +80,7 @@
     }
 
     //Compute the current texture tile based on our normalized age
-    int currentTile = static_cast<int>(x * _num_tile);
+    int currentTile = _start_tile + static_cast<int>(x * getNumTiles());
     
     //If the current texture tile is different from previous, then compute new 
texture coords
     if(currentTile != _cur_tile)
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to