Author: Carlos Lopez <[email protected]>
Date: Wed Mar 16 21:46:50 2011 +0100
Add new parameter to control the interpolation smoothness.
---
synfig-core/src/synfig/valuenode_wplist.cpp | 29 +++++++++++++++++++++++---
synfig-core/src/synfig/valuenode_wplist.h | 3 +-
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/synfig-core/src/synfig/valuenode_wplist.cpp
b/synfig-core/src/synfig/valuenode_wplist.cpp
index 565fefb..22fdd6d 100644
--- a/synfig-core/src/synfig/valuenode_wplist.cpp
+++ b/synfig-core/src/synfig/valuenode_wplist.cpp
@@ -36,6 +36,7 @@
#include "general.h"
#include "exception.h"
#include "widthpoint.h"
+#include <ETL/hermite>
#include <vector>
#include <list>
@@ -95,7 +96,7 @@ synfig::convert_bline_to_wplist(const ValueBase& bline)
}
Real
-synfig::widthpoint_interpolate(const WidthPoint& prev, const WidthPoint& next,
Real p)
+synfig::widthpoint_interpolate(const WidthPoint& prev, const WidthPoint& next,
Real p, Real smoothness)
{
WidthPoint::SideType side_int(WidthPoint::TYPE_INTERPOLATE);
int nsb, nsa, psb, psa;
@@ -110,6 +111,7 @@ synfig::widthpoint_interpolate(const WidthPoint& prev,
const WidthPoint& next, R
nsa=next.get_side_type_after();
psb=prev.get_side_type_before();
psa=prev.get_side_type_after();
+
if(p==np)
return nw;
if(p==pp)
@@ -128,7 +130,14 @@ synfig::widthpoint_interpolate(const WidthPoint& prev,
const WidthPoint& next, R
q=0.5;
else
q=(p-pp)/(np-pp);
- rw=pw+(nw-pw)*q;
+ hermite<Vector> curve(
+ Vector(pp, pw),
+ Vector(np, nw),
+ Vector(0.0,0.0),
+ Vector(0.0,0.0)
+ );
+ rw=curve(q)[0];
+
//rw=(pw+(nw-pw)*q)*(1.0-smoothness)+curve(q)[1]*smoothness;
}
else if(p < pp)
{
@@ -161,7 +170,13 @@ synfig::widthpoint_interpolate(const WidthPoint& prev,
const WidthPoint& next, R
if(np > p)
q=(p+1.0-pp)/(np+1.0-pp);
}
- rw=pw+(nw-pw)*q;
+ hermite<Vector> curve(
+ Vector(pp, pw),
+ Vector(np, nw),
+ Vector(0.0,0.0),
+ Vector(0.0,0.0)
+ );
+ rw=(pw+(nw-pw)*q)*(1.0-smoothness)+curve(q)[1]*smoothness;
}
else
if(p > np && p < pp)
@@ -175,7 +190,13 @@ synfig::widthpoint_interpolate(const WidthPoint& prev,
const WidthPoint& next, R
q=0.5;
else
q=(p-np)/(pp-np);
- rw=nw+(pw-nw)*q;
+ hermite<Vector> curve(
+ Vector(np, nw),
+ Vector(pp, pw),
+ Vector(0.0,0.0),
+ Vector(0.0,0.0)
+ );
+ rw=(nw+(pw-nw)*q)*(1.0-smoothness)+curve(q)[1]*smoothness;
}
return rw;
}
diff --git a/synfig-core/src/synfig/valuenode_wplist.h
b/synfig-core/src/synfig/valuenode_wplist.h
index c2593e7..56a0976 100644
--- a/synfig-core/src/synfig/valuenode_wplist.h
+++ b/synfig-core/src/synfig/valuenode_wplist.h
@@ -49,8 +49,9 @@ synfig::ValueBase convert_bline_to_wplist(const ValueBase&
bline);
//! \param prev the previous width point to evaluate the width
//! \param next the next width point to evaluate the width
//! \param position the position to interpolate between prev and next
+//! \param smoothness a [0,1] value that defines how is calculated the
interpolation
//! \return the interpolated width based on surrounding width points and its
values
-synfig::Real widthpoint_interpolate(const WidthPoint& prev, const WidthPoint&
next, Real position);
+synfig::Real widthpoint_interpolate(const WidthPoint& prev, const WidthPoint&
next, Real position, Real smoothness=0.0);
/*! \class ValueNode_WPList
** \brief This class implements a list of Width Points
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl