svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / extAnimationCommon / src / com / iver / cit / gvsig / animation / InterpolatorTransparency.java @ 15498
History | View | Annotate | Download (2.62 KB)
1 |
package com.iver.cit.gvsig.animation; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
|
5 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
6 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
7 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorFuntion; |
8 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
9 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
10 |
|
11 |
|
12 |
/**
|
13 |
* Class to interpolate the transparency of a activated layer.
|
14 |
*/
|
15 |
|
16 |
public class InterpolatorTransparency implements IInterpolator { |
17 |
|
18 |
public BaseView view;
|
19 |
|
20 |
public IKeyFrame interpolate(List kfList, int index, double time) { |
21 |
KeyFrameTransparency KF = new KeyFrameTransparency();
|
22 |
|
23 |
// if the list of keyframes is empty.
|
24 |
if (kfList == null) |
25 |
return null; |
26 |
|
27 |
|
28 |
switch (kfList.size()) {
|
29 |
// this case when there are only has 2 keyframes
|
30 |
case 2: |
31 |
|
32 |
KeyFrameTransparency kf1 = (KeyFrameTransparency) kfList.get(0);
|
33 |
KeyFrameTransparency kf2 = (KeyFrameTransparency) kfList.get(1);
|
34 |
|
35 |
if (index == 1) { |
36 |
KeyFrameTransparency kaux = kf1; |
37 |
kf1 = kf2; |
38 |
kf2 = kaux; |
39 |
} |
40 |
|
41 |
if ((kf1 == null) ||(kf2 == null)) |
42 |
return null; |
43 |
//initial transparency level.
|
44 |
double transparencia1 = kf1.getLevelTransparency();
|
45 |
//final transparency level.
|
46 |
double transparencia2 = kf2.getLevelTransparency();
|
47 |
|
48 |
// Object to animate getting the keyframe.
|
49 |
FLyrDefault fd1 = (FLyrDefault) kf1.getAnimatedObject(); |
50 |
//FLyrDefault fd2 = (FLyrDefault) kf2.getAnimatedObject();
|
51 |
|
52 |
double time1 = kf1.getTime();//initial time. |
53 |
double time2 = kf2.getTime();//final time. |
54 |
double valorTrans = linearInterpolate(transparencia1, transparencia2, time1, time2, time);
|
55 |
System.out.println("valor interpolado " + valorTrans); |
56 |
|
57 |
//Creating the keyframe KF to return.
|
58 |
try {
|
59 |
KF.setLevelTransparency((int)valorTrans);
|
60 |
KF.setAnimatedObject(fd1);// keyframe with the layer and the new transparecy to apply.
|
61 |
} catch (Exception e) { |
62 |
// TODO Auto-generated catch block
|
63 |
e.printStackTrace(); |
64 |
} |
65 |
} |
66 |
return KF;
|
67 |
} |
68 |
|
69 |
|
70 |
private double linearInterpolate(double minX, double minX2, double timePos, |
71 |
double timePos2, double time) { |
72 |
// P1 + (P2-P1)*((t-t1)/(t2-t1))
|
73 |
return (minX + (minX2 - minX)
|
74 |
* ((time - timePos) / (timePos2 - timePos))); |
75 |
} |
76 |
|
77 |
public Object getAnimatedObject() { |
78 |
return null; |
79 |
} |
80 |
|
81 |
public void setAnimatedObject(Object ani) { |
82 |
} |
83 |
|
84 |
public IInterpolatorFuntion getFuntion() {
|
85 |
// TODO Auto-generated method stub
|
86 |
return null; |
87 |
} |
88 |
|
89 |
|
90 |
public void setFuntion(IInterpolatorFuntion arg0) { |
91 |
// TODO Auto-generated method stub
|
92 |
|
93 |
} |
94 |
} |