root / trunk / libraries / libAnimation3D / src / main / java / com / iver / cit / gvsig / animation / interpolator / Interpolator3DFlat.java @ 20162
History | View | Annotate | Download (4.26 KB)
1 |
package com.iver.cit.gvsig.animation.interpolator; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
|
5 |
import com.iver.ai2.gvsig3d.camera.ProjectCamera; |
6 |
import com.iver.cit.gvsig.animation.keyFrame.KeyFrame3DFlat; |
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.utiles.XMLEntity; |
11 |
|
12 |
import es.upv.ai2.osgvp.Vec3; |
13 |
import es.upv.ai2.osgvp.viewer.Camera; |
14 |
|
15 |
public class Interpolator3DFlat implements IInterpolator { |
16 |
|
17 |
private IInterpolatorTimeFuntion funtion;
|
18 |
private String description = "Interpolaci?n basada en encuadres"; |
19 |
private String name = "Interpolator3DFlat"; |
20 |
|
21 |
public IKeyFrame interpolate(List kfList, int index, double time) { |
22 |
KeyFrame3DFlat KF = new KeyFrame3DFlat();
|
23 |
|
24 |
if (kfList == null) |
25 |
return null; |
26 |
|
27 |
// convert the time in the new time using funtion
|
28 |
double newTime = this.getFuntion().interpolate(time); |
29 |
|
30 |
switch (kfList.size()) {
|
31 |
// this case when there are only has 2 keyframes
|
32 |
case 2: |
33 |
// getting the keyframes
|
34 |
KeyFrame3DFlat kf1 = (KeyFrame3DFlat) kfList.get(0);
|
35 |
KeyFrame3DFlat kf2 = (KeyFrame3DFlat) kfList.get(1);
|
36 |
|
37 |
if (index == 1) { |
38 |
KeyFrame3DFlat kaux = kf1; |
39 |
kf1 = kf2; |
40 |
kf2 = kaux; |
41 |
} |
42 |
|
43 |
if ((kf1 == null) ||(kf2 == null)) |
44 |
return null; |
45 |
ProjectCamera vp1 = (ProjectCamera) kf1.getAnimatedObject(); |
46 |
ProjectCamera vp2 = (ProjectCamera) kf2.getAnimatedObject(); |
47 |
|
48 |
// ViewPort vp = view.getMapControl().getViewPort();
|
49 |
|
50 |
Camera cam1 = vp1.getCamera(); |
51 |
Camera cam2 = vp2.getCamera(); |
52 |
double time1 = kf1.getTime();
|
53 |
double time2 = kf2.getTime();
|
54 |
|
55 |
Vec3 eye = linearInterpolate(cam1.getEye(), cam2.getEye(), time1, time2, newTime); |
56 |
Vec3 center = linearInterpolate(cam1.getCenter(), cam2.getCenter(), time1, time2, newTime); |
57 |
Vec3 up = linearInterpolate(cam1.getUp(), cam2.getUp(), time1, time2, newTime); |
58 |
|
59 |
Camera newCamera = new Camera();
|
60 |
// newCamera.setViewByLookAt(eye, center, cam1.getUp());
|
61 |
newCamera.setViewByLookAt(eye, center, up); |
62 |
|
63 |
ProjectCamera pe = new ProjectCamera();
|
64 |
pe.setCamera(newCamera); |
65 |
KF.setName("temporal_keyframe");
|
66 |
KF.setAnimatedObject(pe); |
67 |
break;
|
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 |
private Vec3 linearInterpolate(Vec3 minX, Vec3 minX2, double timePos, |
80 |
double timePos2, double time) { |
81 |
|
82 |
Vec3 result = new Vec3();
|
83 |
|
84 |
double ele1 = linearInterpolate(minX.x(), minX2.x(), timePos, timePos2,
|
85 |
time); |
86 |
double ele2 = linearInterpolate(minX.y(), minX2.y(), timePos, timePos2,
|
87 |
time); |
88 |
double ele3 = linearInterpolate(minX.z(), minX2.z(), timePos, timePos2,
|
89 |
time); |
90 |
|
91 |
result.setX(ele1); |
92 |
result.setY(ele2); |
93 |
result.setZ(ele3); |
94 |
return result;
|
95 |
} |
96 |
|
97 |
// public Object getAnimatedObject() {
|
98 |
//// return this.animationObject3DFlat;
|
99 |
// //return this.view;
|
100 |
// return null;
|
101 |
// }
|
102 |
//
|
103 |
//
|
104 |
// public void setAnimatedObject(Object object) {
|
105 |
//// this.animationObject3DFlat = (AnimationObject3DFlat) object;
|
106 |
//// this.view = (View3D) animationObject3DFlat.getAnimatedView();
|
107 |
// }
|
108 |
|
109 |
|
110 |
|
111 |
// public void setAnimatedObject(Object ani) {
|
112 |
// this.view = (View3D) ani;
|
113 |
//
|
114 |
// }
|
115 |
|
116 |
public IInterpolatorTimeFuntion getFuntion() {
|
117 |
return this.funtion; |
118 |
} |
119 |
|
120 |
public void setFuntion(IInterpolatorTimeFuntion funtion) { |
121 |
this.funtion = funtion;
|
122 |
|
123 |
} |
124 |
|
125 |
public String getClassName() { |
126 |
return this.getClass().getName(); |
127 |
} |
128 |
|
129 |
public String getDescription() { |
130 |
return this.description; |
131 |
} |
132 |
|
133 |
public String getName() { |
134 |
return this.name; |
135 |
} |
136 |
|
137 |
/*
|
138 |
* IPersistence methods.
|
139 |
*/
|
140 |
|
141 |
public XMLEntity getXMLEntity() {
|
142 |
XMLEntity xml = new XMLEntity();
|
143 |
xml.putProperty("className", this.getClassName()); |
144 |
xml.putProperty("description", this.description); |
145 |
return xml;
|
146 |
} |
147 |
|
148 |
public void setXMLEntity(XMLEntity xml) { |
149 |
// if (xml.contains("className"))
|
150 |
// this.className= xml.getStringProperty("className");
|
151 |
if (xml.contains("description")) |
152 |
this.description = xml.getStringProperty("description"); |
153 |
|
154 |
} |
155 |
} |