Use an enumeration type rather than unnamed integers to specify the different types...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Sat, 8 Sep 2007 23:12:50 +0000 (23:12 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Sat, 8 Sep 2007 23:12:50 +0000 (23:12 +0000)
git-svn-id: http://svn.voria.com/code@636 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/src/modules/mod_particle/plant.cpp
synfig-core/trunk/src/modules/mod_particle/random.cpp
synfig-core/trunk/src/modules/mod_particle/random.h

index 2a93935..fe9a8b3 100644 (file)
@@ -131,10 +131,10 @@ Plant::branch(int n,int depth,float t, float stunt_growth, synfig::Point positio
        synfig::Real sin_v=synfig::Angle::cos(split_angle).get();
        synfig::Real cos_v=synfig::Angle::sin(split_angle).get();
 
-       synfig::Vector velocity1(vel[0]*sin_v - vel[1]*cos_v + random_factor*random(2, 30+n+depth, t*splits, 0.0f, 0.0f),
-                                                        vel[0]*cos_v + vel[1]*sin_v + random_factor*random(2, 32+n+depth, t*splits, 0.0f, 0.0f));
-       synfig::Vector velocity2(vel[0]*sin_v + vel[1]*cos_v + random_factor*random(2, 31+n+depth, t*splits, 0.0f, 0.0f),
-                                                       -vel[0]*cos_v + vel[1]*sin_v + random_factor*random(2, 33+n+depth, t*splits, 0.0f, 0.0f));
+       synfig::Vector velocity1(vel[0]*sin_v - vel[1]*cos_v + random_factor*random(Random::SMOOTH_COSINE, 30+n+depth, t*splits, 0.0f, 0.0f),
+                                                        vel[0]*cos_v + vel[1]*sin_v + random_factor*random(Random::SMOOTH_COSINE, 32+n+depth, t*splits, 0.0f, 0.0f));
+       synfig::Vector velocity2(vel[0]*sin_v + vel[1]*cos_v + random_factor*random(Random::SMOOTH_COSINE, 31+n+depth, t*splits, 0.0f, 0.0f),
+                                                       -vel[0]*cos_v + vel[1]*sin_v + random_factor*random(Random::SMOOTH_COSINE, 33+n+depth, t*splits, 0.0f, 0.0f));
 
        Plant::branch(n,depth+1,t,stunt_growth,position,velocity1);
        Plant::branch(n,depth+1,t,stunt_growth,position,velocity2);
@@ -223,13 +223,13 @@ Plant::sync()const
 
                        bounding_rect.expand(point);
 
-                       Real stunt_growth(random(2,i,f+seg,0.0f,0.0f)/2.0+0.5);
+                       Real stunt_growth(random(Random::SMOOTH_COSINE,i,f+seg,0.0f,0.0f)/2.0+0.5);
                        stunt_growth*=stunt_growth;
 
                        Vector branch_velocity(deriv(f).norm()*velocity);
 
-                       branch_velocity[0]+=random_factor*random(2,1,f*splits,0.0f,0.0f);
-                       branch_velocity[1]+=random_factor*random(2,2,f*splits,0.0f,0.0f);
+                       branch_velocity[0]+=random_factor*random(Random::SMOOTH_COSINE,1,f*splits,0.0f,0.0f);
+                       branch_velocity[1]+=random_factor*random(Random::SMOOTH_COSINE,2,f*splits,0.0f,0.0f);
 
                        if(i%b==0)
                                branch(
index ad2e896..c72c763 100644 (file)
@@ -70,7 +70,7 @@ Random::operator()(const int salt,const int x,const int y,const int t)const
 }
 
 float
-Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const
+Random::operator()(SmoothType smooth,int subseed,float xf,float yf,float tf)const
 {
        int x((int)floor(xf));
        int y((int)floor(yf));
@@ -78,10 +78,11 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const
 
        switch(smooth)
        {
-       case 4: // cubic
+       case SMOOTH_CUBIC:      // cubic
                {
                        #define f(j,i,k)        ((*this)(subseed,i,j,k))
                        //Using catmull rom interpolation because it doesn't blur at all
+                       // ( http://www.gamedev.net/reference/articles/article1497.asp )
                        //bezier curve with intermediate ctrl pts: 0.5/3(p(i+1) - p(i-1)) and similar
                        float xfa [4], tfa[4];
 
@@ -138,7 +139,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const
                break;
 
 
-       case 5: // Fast Spline (non-animated)
+       case SMOOTH_FAST_SPLINE:        // Fast Spline (non-animated)
                {
 #define P(x)   (((x)>0)?((x)*(x)*(x)):0.0f)
 #define R(x)   ( P(x+2) - 4.0f*P(x+1) + 6.0f*P(x) - 4.0f*P(x-1) )*(1.0f/6.0f)
@@ -161,7 +162,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const
                return ret;
        }
 
-       case 3: // Spline (animated)
+       case SMOOTH_SPLINE:     // Spline (animated)
                {
                        float a(xf-x), b(yf-y), c(tf-t);
 
@@ -211,7 +212,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const
 #undef P
 #undef R
 
-       case 2: // Cosine
+       case SMOOTH_COSINE:
        if((float)t==tf)
        {
                int x((int)floor(xf));
@@ -258,7 +259,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const
                        (*this)(subseed,x,y2,t2)*(d*b*c)+
                        (*this)(subseed,x2,y2,t2)*(a*b*c);
        }
-       case 1: // Linear
+       case SMOOTH_LINEAR:
        if((float)t==tf)
        {
                int x((int)floor(xf));
@@ -298,7 +299,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const
                        (*this)(subseed,x2,y2,t2)*(a*b*c);
        }
        default:
-       case 0:
+       case SMOOTH_DEFAULT:
                return (*this)(subseed,x,y,t);
        }
 }
index 672fb9a..5ab0632 100644 (file)
@@ -48,8 +48,18 @@ public:
        void set_seed(int x);
        int get_seed()const { return seed_; }
 
-       float operator()(int subseed,int x,int y=0, int t=0)const;
-       float operator()(int smooth,int subseed,float x,float y=0, float t=0)const;
+       enum SmoothType
+       {
+               SMOOTH_DEFAULT          = 0,
+               SMOOTH_LINEAR           = 1,
+               SMOOTH_COSINE           = 2,
+               SMOOTH_SPLINE           = 3,
+               SMOOTH_CUBIC            = 4,
+               SMOOTH_FAST_SPLINE      = 5,
+       };
+
+       float operator()(int salt,int x,int y=0, int t=0)const;
+       float operator()(SmoothType smooth,int subseed,float x,float y=0, float t=0)const;
 };
 
 /* === E N D =============================================================== */