diff options
author | kitfox | 2012-09-29 08:49:32 +0200 |
---|---|---|
committer | kitfox | 2012-09-29 08:49:32 +0200 |
commit | b85982e025ee1d45a7a9873f5809ed45f3412201 (patch) | |
tree | 4e0c7024a6e9a761523e2f3726e20f9383b528bf | |
parent | Now avoiding reentering XML parser when USE tags reference other documents. (diff) | |
download | svg-salamander-core-b85982e025ee1d45a7a9873f5809ed45f3412201.tar.gz svg-salamander-core-b85982e025ee1d45a7a9873f5809ed45f3412201.tar.xz svg-salamander-core-b85982e025ee1d45a7a9873f5809ed45f3412201.zip |
AnimateTransform can now handle short parameter lists.
git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@127 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b
-rw-r--r-- | src/main/java/com/kitfox/svg/SVGElement.java | 5 | ||||
-rw-r--r-- | src/main/java/com/kitfox/svg/animation/AnimateTransform.java | 29 |
2 files changed, 25 insertions, 9 deletions
diff --git a/src/main/java/com/kitfox/svg/SVGElement.java b/src/main/java/com/kitfox/svg/SVGElement.java index 4375a89..5f849a4 100644 --- a/src/main/java/com/kitfox/svg/SVGElement.java +++ b/src/main/java/com/kitfox/svg/SVGElement.java @@ -897,4 +897,9 @@ abstract public class SVGElement implements Serializable return (SVGElement)children.get(i);
}
+ public double lerp(double t0, double t1, double alpha)
+ {
+ return (1 - alpha) * t0 + alpha * t1;
+ }
+
}
diff --git a/src/main/java/com/kitfox/svg/animation/AnimateTransform.java b/src/main/java/com/kitfox/svg/animation/AnimateTransform.java index 61d73b2..14e39c2 100644 --- a/src/main/java/com/kitfox/svg/animation/AnimateTransform.java +++ b/src/main/java/com/kitfox/svg/animation/AnimateTransform.java @@ -182,8 +182,14 @@ public class AnimateTransform extends AnimateXform {
case TR_TRANSLATE:
{
- double x = (1.0 - interp) * fromValue[0] + interp * toValue[0];
- double y = (1.0 - interp) * fromValue[1] + interp * toValue[1];
+ double x0 = fromValue.length > 1 ? fromValue[0] : 0;
+ double x1 = toValue.length > 1 ? toValue[0] : 0;
+ double y0 = fromValue.length > 2 ? fromValue[1] : 0;
+ double y1 = toValue.length > 2 ? toValue[1] : 0;
+
+ double x = lerp(x0, x1, interp);
+ double y = lerp(y0, y1, interp);
+
xform.setToTranslation(x, y);
break;
}
@@ -194,28 +200,33 @@ public class AnimateTransform extends AnimateXform double x2 = toValue.length == 3 ? toValue[1] : 0;
double y2 = toValue.length == 3 ? toValue[2] : 0;
- double theta = (1.0 - interp) * fromValue[0] + interp * toValue[0];
- double x = (1.0 - interp) * x1 + interp * x2;
- double y = (1.0 - interp) * y1 + interp * y2;
+ double theta = lerp(fromValue[0], toValue[0], interp);
+ double x = lerp(x1, x2, interp);
+ double y = lerp(y1, y2, interp);
xform.setToRotation(Math.toRadians(theta), x, y);
break;
}
case TR_SCALE:
{
- double x = (1.0 - interp) * fromValue[0] + interp * toValue[0];
- double y = (1.0 - interp) * fromValue[1] + interp * toValue[1];
+ double x0 = fromValue.length > 1 ? fromValue[0] : 1;
+ double x1 = toValue.length > 1 ? toValue[0] : 1;
+ double y0 = fromValue.length > 2 ? fromValue[1] : 1;
+ double y1 = toValue.length > 2 ? toValue[1] : 1;
+
+ double x = lerp(x0, x1, interp);
+ double y = lerp(y0, y1, interp);
xform.setToScale(x, y);
break;
}
case TR_SKEWX:
{
- double x = (1.0 - interp) * fromValue[0] + interp * toValue[0];
+ double x = lerp(fromValue[0], toValue[0], interp);
xform.setToShear(Math.toRadians(x), 0.0);
break;
}
case TR_SKEWY:
{
- double y = (1.0 - interp) * fromValue[0] + interp * toValue[0];
+ double y = lerp(fromValue[0], toValue[0], interp);
xform.setToShear(0.0, Math.toRadians(y));
break;
}
|