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);
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(
}
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));
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];
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)
return ret;
}
- case 3: // Spline (animated)
+ case SMOOTH_SPLINE: // Spline (animated)
{
float a(xf-x), b(yf-y), c(tf-t);
#undef P
#undef R
- case 2: // Cosine
+ case SMOOTH_COSINE:
if((float)t==tf)
{
int x((int)floor(xf));
(*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));
(*this)(subseed,x2,y2,t2)*(a*b*c);
}
default:
- case 0:
+ case SMOOTH_DEFAULT:
return (*this)(subseed,x,y,t);
}
}
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 =============================================================== */