Statistics
| Revision:

svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / ExtAnimation2D / src / com / iver / cit / gvsig / animation / Interpolator2D.java @ 15437

History | View | Annotate | Download (2.46 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.IInterpolator;
7
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame;
8
import com.iver.cit.gvsig.fmap.ViewPort;
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
        public View view;
15

    
16
        public IKeyFrame interpolate(List kfList, int index, double time) {
17
                KeyFrame2D KF = new KeyFrame2D();
18

    
19
                if (kfList == null)
20
                        return null;
21

    
22
                if (this.view == null)
23
                        return null;
24

    
25
                switch (kfList.size()) {
26
                // this case when there are only has 2 keyframes
27
                case 2:
28
                        // getting the keyframes
29
                        KeyFrame2D kf1 = (KeyFrame2D) kfList.get(0);
30
                        KeyFrame2D kf2 = (KeyFrame2D) kfList.get(1);
31

    
32
                        if (index == 1) {
33
                                KeyFrame2D kaux = kf1;
34
                                kf1 = kf2;
35
                                kf2 = kaux;
36
                        }
37

    
38
                        ProjectExtent vp1 = (ProjectExtent) kf1.getAnimatedObject();
39
                        ProjectExtent vp2 = (ProjectExtent) kf2.getAnimatedObject();
40

    
41
                        // ViewPort vp = view.getMapControl().getViewPort();
42

    
43
                        double min1 = vp1.getExtent().getMinX();
44
                        double time1 = kf1.getTime();
45
                        double min2 = vp2.getExtent().getMinX();
46
                        double time2 = kf2.getTime();
47
                        double left = linearInterpolate(min1, min2, time1, time2, time);
48
                        min1 = vp1.getExtent().getMinY();
49
                        min2 = vp2.getExtent().getMinY();
50
                        double top = linearInterpolate(min1, min2, time1, time2, time);
51
                        min1 = vp1.getExtent().getWidth();
52
                        min2 = vp2.getExtent().getWidth();
53
                        double right = linearInterpolate(min1, min2, time1, time2, time);
54
                        min1 = vp1.getExtent().getHeight();
55
                        min2 = vp2.getExtent().getHeight();
56
                        double bottom = linearInterpolate(min1, min2, time1, time2, time);
57

    
58
                        Rectangle2D newExtent = new Rectangle2D.Double(left, top, right,
59
                                        bottom);
60
                        ProjectExtent pe = new ProjectExtent();
61
                        pe.setExtent(newExtent);
62
                        // pe.setEncuadre("temporal_keyframe");
63
                        // vp.setExtent(newExtent);
64
                        KF.setAnimatedObject(pe);
65
                        break;
66

    
67
                }
68

    
69
                return KF;
70
        }
71

    
72
        private double linearInterpolate(double minX, double minX2, double timePos,
73
                        double timePos2, double time) {
74
                // P1 + (P2-P1)*((t-t1)/(t2-t1))
75
                return (minX + (minX2 - minX)
76
                                * ((time - timePos) / (timePos2 - timePos)));
77
        }
78

    
79
        public Object getAnimatedObject() {
80

    
81
                return this.view;
82
        }
83

    
84
        public void setAnimatedObject(Object ani) {
85
                this.view = (View) ani;
86

    
87
        }
88
}