svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / extAnimation2D / src / com / iver / cit / gvsig / animation / Interpolator2D.java @ 15471
History | View | Annotate | Download (2.71 KB)
1 |
package com.iver.cit.gvsig.animation; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.util.List; |
5 |
|
6 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
7 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
8 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorFuntion; |
9 |
import com.iver.cit.gvsig.project.ProjectExtent; |
10 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
11 |
|
12 |
public class Interpolator2D implements IInterpolator { |
13 |
|
14 |
private View view; |
15 |
|
16 |
private IInterpolatorFuntion funtion;
|
17 |
|
18 |
public IKeyFrame interpolate(List kfList, int index, double time) { |
19 |
KeyFrame2D KF = new KeyFrame2D();
|
20 |
|
21 |
if (kfList == null) |
22 |
return null; |
23 |
|
24 |
if (this.view == null) |
25 |
return null; |
26 |
|
27 |
switch (kfList.size()) {
|
28 |
// this case when there are only has 2 keyframes
|
29 |
case 2: |
30 |
// getting the keyframes
|
31 |
KeyFrame2D kf1 = (KeyFrame2D) kfList.get(0);
|
32 |
KeyFrame2D kf2 = (KeyFrame2D) kfList.get(1);
|
33 |
|
34 |
if (index == 1) { |
35 |
KeyFrame2D kaux = kf1; |
36 |
kf1 = kf2; |
37 |
kf2 = kaux; |
38 |
} |
39 |
|
40 |
ProjectExtent vp1 = (ProjectExtent) kf1.getAnimatedObject(); |
41 |
ProjectExtent vp2 = (ProjectExtent) kf2.getAnimatedObject(); |
42 |
|
43 |
// ViewPort vp = view.getMapControl().getViewPort();
|
44 |
|
45 |
double min1 = vp1.getExtent().getMinX();
|
46 |
double time1 = kf1.getTime();
|
47 |
double min2 = vp2.getExtent().getMinX();
|
48 |
double time2 = kf2.getTime();
|
49 |
double left = linearInterpolate(min1, min2, time1, time2, time);
|
50 |
min1 = vp1.getExtent().getMinY(); |
51 |
min2 = vp2.getExtent().getMinY(); |
52 |
double top = linearInterpolate(min1, min2, time1, time2, time);
|
53 |
min1 = vp1.getExtent().getWidth(); |
54 |
min2 = vp2.getExtent().getWidth(); |
55 |
double right = linearInterpolate(min1, min2, time1, time2, time);
|
56 |
min1 = vp1.getExtent().getHeight(); |
57 |
min2 = vp2.getExtent().getHeight(); |
58 |
double bottom = linearInterpolate(min1, min2, time1, time2, time);
|
59 |
|
60 |
Rectangle2D newExtent = new Rectangle2D.Double(left, top, right, |
61 |
bottom); |
62 |
ProjectExtent pe = new ProjectExtent();
|
63 |
pe.setExtent(newExtent); |
64 |
// pe.setEncuadre("temporal_keyframe");
|
65 |
// vp.setExtent(newExtent);
|
66 |
KF.setAnimatedObject(pe); |
67 |
break;
|
68 |
|
69 |
} |
70 |
|
71 |
return KF;
|
72 |
} |
73 |
|
74 |
private double linearInterpolate(double minX, double minX2, double timePos, |
75 |
double timePos2, double time) { |
76 |
// P1 + (P2-P1)*((t-t1)/(t2-t1))
|
77 |
return (minX + (minX2 - minX)
|
78 |
* ((time - timePos) / (timePos2 - timePos))); |
79 |
} |
80 |
|
81 |
public Object getAnimatedObject() { |
82 |
|
83 |
return this.view; |
84 |
} |
85 |
|
86 |
public void setAnimatedObject(Object ani) { |
87 |
this.view = (View) ani; |
88 |
|
89 |
} |
90 |
|
91 |
public IInterpolatorFuntion getFuntion() {
|
92 |
return this.funtion; |
93 |
} |
94 |
|
95 |
public void setFuntion(IInterpolatorFuntion funtion) { |
96 |
this.funtion = funtion;
|
97 |
} |
98 |
} |