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