root / trunk / libraries / libAnimationCommon / src / main / java / com / iver / cit / gvsig / animation / interpolator / InterpolatorTransparency.java @ 20153
History | View | Annotate | Download (4.24 KB)
1 |
package com.iver.cit.gvsig.animation.interpolator; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
|
5 |
import com.iver.ai2.gvsig3dgui.view.View3D; |
6 |
import com.iver.cit.gvsig.animation.animatedObject.AnimationObjectTransparency; |
7 |
import com.iver.cit.gvsig.animation.keyFrame.KeyFrameTransparency; |
8 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
9 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
10 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion; |
11 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
12 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
13 |
import com.iver.utiles.XMLEntity; |
14 |
|
15 |
|
16 |
/**
|
17 |
* Class to interpolate the transparency of a activated layer.
|
18 |
*/
|
19 |
|
20 |
public class InterpolatorTransparency implements IInterpolator { |
21 |
|
22 |
public BaseView view;
|
23 |
private String className;// = this.getClass().getName(); |
24 |
private String description = "Interpolaci?n basada en Transparencias"; |
25 |
private String name = "InterpolatorTransparency"; |
26 |
|
27 |
private AnimationObjectTransparency animationObjectTransparency = new AnimationObjectTransparency() ; |
28 |
|
29 |
public IKeyFrame interpolate(List kfList, int index, double time) { |
30 |
KeyFrameTransparency KF = new KeyFrameTransparency();
|
31 |
|
32 |
// if the list of keyframes is empty.
|
33 |
if (kfList == null) |
34 |
return null; |
35 |
|
36 |
if (this.view == null) |
37 |
return null; |
38 |
|
39 |
|
40 |
|
41 |
switch (kfList.size()) {
|
42 |
// this case when there are only has 2 keyframes
|
43 |
case 2: |
44 |
|
45 |
KeyFrameTransparency kf1 = (KeyFrameTransparency) kfList.get(0);
|
46 |
KeyFrameTransparency kf2 = (KeyFrameTransparency) kfList.get(1);
|
47 |
|
48 |
if (index == 1) { |
49 |
KeyFrameTransparency kaux = kf1; |
50 |
kf1 = kf2; |
51 |
kf2 = kaux; |
52 |
} |
53 |
|
54 |
if ((kf1 == null) ||(kf2 == null)) |
55 |
return null; |
56 |
//initial transparency level.
|
57 |
double transparencia1 = kf1.getLevelTransparency();
|
58 |
//final transparency level.
|
59 |
double transparencia2 = kf2.getLevelTransparency();
|
60 |
|
61 |
// Object to animate getting the keyframe.
|
62 |
FLyrDefault fd1 = (FLyrDefault) kf1.getAnimatedObject(); |
63 |
//FLyrDefault fd2 = (FLyrDefault) kf2.getAnimatedObject();
|
64 |
|
65 |
double time1 = kf1.getTime();//initial time. |
66 |
double time2 = kf2.getTime();//final time. |
67 |
double valorTrans = linearInterpolate(transparencia1, transparencia2, time1, time2, time);
|
68 |
System.out.println("valor interpolado " + valorTrans); |
69 |
|
70 |
//Creating the keyframe KF to return.
|
71 |
try {
|
72 |
KF.setLevelTransparency((int)valorTrans);
|
73 |
KF.setAnimatedObject(fd1);// keyframe with the layer and the new transparecy to apply.
|
74 |
} catch (Exception e) { |
75 |
// TODO Auto-generated catch block
|
76 |
e.printStackTrace(); |
77 |
} |
78 |
} |
79 |
return KF;
|
80 |
} |
81 |
|
82 |
|
83 |
private double linearInterpolate(double minX, double minX2, double timePos, |
84 |
double timePos2, double time) { |
85 |
// P1 + (P2-P1)*((t-t1)/(t2-t1))
|
86 |
return (minX + (minX2 - minX)
|
87 |
* ((time - timePos) / (timePos2 - timePos))); |
88 |
} |
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
public Object getAnimatedObject() { |
95 |
return this.animationObjectTransparency; |
96 |
//return this.view;
|
97 |
} |
98 |
|
99 |
|
100 |
public void setAnimatedObject(Object object) { |
101 |
this.animationObjectTransparency = (AnimationObjectTransparency) object;
|
102 |
this.view = (View3D) animationObjectTransparency.getAnimatedView();
|
103 |
} |
104 |
// public Object getAnimatedObject() {
|
105 |
//
|
106 |
// return this.view;
|
107 |
// }
|
108 |
//
|
109 |
// public void setAnimatedObject(Object ani) {
|
110 |
// this.view = (View3D) ani;
|
111 |
// }
|
112 |
|
113 |
public IInterpolatorTimeFuntion getFuntion() {
|
114 |
// TODO Auto-generated method stub
|
115 |
return null; |
116 |
} |
117 |
|
118 |
|
119 |
public void setFuntion(IInterpolatorTimeFuntion arg0) { |
120 |
// TODO Auto-generated method stub
|
121 |
|
122 |
} |
123 |
|
124 |
public String getClassName() { |
125 |
return this.getClass().getName(); |
126 |
} |
127 |
|
128 |
public String getDescription() { |
129 |
return this.description; |
130 |
} |
131 |
|
132 |
public String getName() { |
133 |
return this.name; |
134 |
} |
135 |
|
136 |
/*
|
137 |
* IPersistence methods.
|
138 |
*/
|
139 |
|
140 |
public XMLEntity getXMLEntity() {
|
141 |
XMLEntity xml = new XMLEntity();
|
142 |
xml.putProperty("className", this.getClassName()); |
143 |
xml.putProperty("description", this.description); |
144 |
return xml;
|
145 |
} |
146 |
|
147 |
public void setXMLEntity(XMLEntity xml) { |
148 |
if (xml.contains("className")) |
149 |
this.className= xml.getStringProperty("className"); |
150 |
if (xml.contains("description")) |
151 |
this.description = xml.getStringProperty("description"); |
152 |
|
153 |
} |
154 |
|
155 |
} |