svn-gvsig-desktop / trunk / libraries / libAnimation2D / src / main / java / com / iver / cit / gvsig / animation / interpolator / Interpolator2D.java @ 23224
History | View | Annotate | Download (3.41 KB)
1 |
package com.iver.cit.gvsig.animation.interpolator; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.util.List; |
5 |
|
6 |
import com.iver.cit.gvsig.animation.keyFrame.KeyFrame2D; |
7 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
8 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
9 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion; |
10 |
import com.iver.cit.gvsig.project.ProjectExtent; |
11 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
12 |
import com.iver.utiles.XMLEntity; |
13 |
|
14 |
public class Interpolator2D implements IInterpolator { |
15 |
|
16 |
private String description = "Interpolaci?n basada en encuadres"; |
17 |
private String name = "Interpolator2D"; |
18 |
|
19 |
private IInterpolatorTimeFuntion funtion;
|
20 |
|
21 |
public IKeyFrame interpolate(List kfList, int index, double time) { |
22 |
KeyFrame2D KF = new KeyFrame2D();
|
23 |
|
24 |
if (kfList == null) |
25 |
return null; |
26 |
|
27 |
// if (this.view == null)
|
28 |
// return null;
|
29 |
|
30 |
switch (kfList.size()) {
|
31 |
// this case when there are only has 2 keyframes
|
32 |
case 2: |
33 |
// getting the keyframes
|
34 |
KeyFrame2D kf1 = (KeyFrame2D) kfList.get(0);
|
35 |
KeyFrame2D kf2 = (KeyFrame2D) kfList.get(1);
|
36 |
|
37 |
if (index == 1) { |
38 |
KeyFrame2D kaux = kf1; |
39 |
kf1 = kf2; |
40 |
kf2 = kaux; |
41 |
} |
42 |
|
43 |
ProjectExtent vp1 = (ProjectExtent) kf1.getAnimatedObject(); |
44 |
ProjectExtent vp2 = (ProjectExtent) kf2.getAnimatedObject(); |
45 |
|
46 |
// ViewPort vp = view.getMapControl().getViewPort();
|
47 |
|
48 |
double min1 = vp1.getExtent().getMinX();
|
49 |
double time1 = kf1.getTime();
|
50 |
double min2 = vp2.getExtent().getMinX();
|
51 |
double time2 = kf2.getTime();
|
52 |
double left = linearInterpolate(min1, min2, time1, time2, time);
|
53 |
min1 = vp1.getExtent().getMinY(); |
54 |
min2 = vp2.getExtent().getMinY(); |
55 |
double top = linearInterpolate(min1, min2, time1, time2, time);
|
56 |
min1 = vp1.getExtent().getWidth(); |
57 |
min2 = vp2.getExtent().getWidth(); |
58 |
double right = linearInterpolate(min1, min2, time1, time2, time);
|
59 |
min1 = vp1.getExtent().getHeight(); |
60 |
min2 = vp2.getExtent().getHeight(); |
61 |
double bottom = linearInterpolate(min1, min2, time1, time2, time);
|
62 |
|
63 |
Rectangle2D newExtent = new Rectangle2D.Double(left, top, right, |
64 |
bottom); |
65 |
ProjectExtent pe = new ProjectExtent();
|
66 |
pe.setExtent(newExtent); |
67 |
// pe.setEncuadre("temporal_keyframe");
|
68 |
// vp.setExtent(newExtent);
|
69 |
KF.setAnimatedObject(pe); |
70 |
break;
|
71 |
|
72 |
} |
73 |
|
74 |
return KF;
|
75 |
} |
76 |
|
77 |
private double linearInterpolate(double minX, double minX2, double timePos, |
78 |
double timePos2, double time) { |
79 |
// P1 + (P2-P1)*((t-t1)/(t2-t1))
|
80 |
return (minX + (minX2 - minX)
|
81 |
* ((time - timePos) / (timePos2 - timePos))); |
82 |
} |
83 |
|
84 |
public IInterpolatorTimeFuntion getFuntion() {
|
85 |
return this.funtion; |
86 |
} |
87 |
|
88 |
public void setFuntion(IInterpolatorTimeFuntion funtion) { |
89 |
this.funtion = funtion;
|
90 |
} |
91 |
|
92 |
public String getClassName() { |
93 |
return this.getClass().getName(); |
94 |
} |
95 |
|
96 |
public String getDescription() { |
97 |
return this.description; |
98 |
} |
99 |
|
100 |
public String getName() { |
101 |
return this.name; |
102 |
} |
103 |
|
104 |
public XMLEntity getXMLEntity() {
|
105 |
XMLEntity xml = new XMLEntity();
|
106 |
xml.putProperty("className", this.getClassName()); |
107 |
xml.putProperty("description", this.description); |
108 |
return xml;
|
109 |
} |
110 |
|
111 |
public void setXMLEntity(XMLEntity xml) { |
112 |
// if (xml.contains("className"))
|
113 |
// this.className= xml.getStringProperty("className");
|
114 |
if (xml.contains("description")) |
115 |
this.description = xml.getStringProperty("description"); |
116 |
|
117 |
} |
118 |
} |