svn-gvsig-desktop / trunk / libraries / libAnimation3D / src / main / java / com / iver / cit / gvsig / animation / interpolator / Interpolator3DFlat.java @ 23595
History | View | Annotate | Download (4.57 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package com.iver.cit.gvsig.animation.interpolator; |
20 |
|
21 |
import java.util.List; |
22 |
|
23 |
import org.gvsig.osgvp.Vec3; |
24 |
import org.gvsig.osgvp.viewer.Camera; |
25 |
|
26 |
import com.iver.ai2.gvsig3d.camera.ProjectCamera; |
27 |
import com.iver.cit.gvsig.animation.keyFrame.KeyFrame3DFlat; |
28 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
29 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
30 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion; |
31 |
import com.iver.utiles.XMLEntity; |
32 |
|
33 |
public class Interpolator3DFlat implements IInterpolator { |
34 |
|
35 |
private IInterpolatorTimeFuntion funtion;
|
36 |
private String description = "Interpolaci?n basada en encuadres"; |
37 |
private String name = "Interpolator3DFlat"; |
38 |
|
39 |
public IKeyFrame interpolate(List<IKeyFrame> kfList, int index, double time) { |
40 |
KeyFrame3DFlat KF = new KeyFrame3DFlat();
|
41 |
|
42 |
if (kfList == null) |
43 |
return null; |
44 |
|
45 |
/* Interpolacion lineal.*/
|
46 |
|
47 |
// convert the time in the new time using funtion
|
48 |
double newTime = this.getFuntion().interpolate(time); |
49 |
|
50 |
switch (kfList.size()) {
|
51 |
// this case when there are only has 2 keyframes
|
52 |
case 2: |
53 |
// getting the keyframes
|
54 |
KeyFrame3DFlat kf1 = (KeyFrame3DFlat) kfList.get(0);
|
55 |
KeyFrame3DFlat kf2 = (KeyFrame3DFlat) kfList.get(1);
|
56 |
|
57 |
if (index == 1) { |
58 |
KeyFrame3DFlat kaux = kf1; |
59 |
kf1 = kf2; |
60 |
kf2 = kaux; |
61 |
} |
62 |
|
63 |
if ((kf1 == null) ||(kf2 == null)) |
64 |
return null; |
65 |
ProjectCamera vp1 = (ProjectCamera) kf1.getAnimatedObject(); |
66 |
ProjectCamera vp2 = (ProjectCamera) kf2.getAnimatedObject(); |
67 |
|
68 |
Camera cam1 = vp1.getCamera(); |
69 |
Camera cam2 = vp2.getCamera(); |
70 |
double time1 = kf1.getTime();
|
71 |
double time2 = kf2.getTime();
|
72 |
|
73 |
Vec3 eye = linearInterpolate(cam1.getEye(), cam2.getEye(), time1, time2, newTime); |
74 |
Vec3 center = linearInterpolate(cam1.getCenter(), cam2.getCenter(), time1, time2, newTime); |
75 |
Vec3 up = linearInterpolate(cam1.getUp(), cam2.getUp(), time1, time2, newTime); |
76 |
|
77 |
Camera newCamera = new Camera();
|
78 |
// newCamera.setViewByLookAt(eye, center, cam1.getUp());
|
79 |
newCamera.setViewByLookAt(eye, center, up); |
80 |
|
81 |
ProjectCamera pe = new ProjectCamera();
|
82 |
pe.setCamera(newCamera); |
83 |
KF.setName("temporal_keyframe");
|
84 |
KF.setAnimatedObject(pe); |
85 |
break;
|
86 |
} |
87 |
|
88 |
return KF;
|
89 |
} |
90 |
|
91 |
private double linearInterpolate(double minX, double minX2, double timePos, |
92 |
double timePos2, double time) { |
93 |
// P1 + (P2-P1)*((t-t1)/(t2-t1))
|
94 |
return (minX + (minX2 - minX)
|
95 |
* ((time - timePos) / (timePos2 - timePos))); |
96 |
} |
97 |
|
98 |
private Vec3 linearInterpolate(Vec3 minX, Vec3 minX2, double timePos, |
99 |
double timePos2, double time) { |
100 |
|
101 |
Vec3 result = new Vec3();
|
102 |
|
103 |
double ele1 = linearInterpolate(minX.x(), minX2.x(), timePos, timePos2,
|
104 |
time); |
105 |
double ele2 = linearInterpolate(minX.y(), minX2.y(), timePos, timePos2,
|
106 |
time); |
107 |
double ele3 = linearInterpolate(minX.z(), minX2.z(), timePos, timePos2,
|
108 |
time); |
109 |
|
110 |
result.setX(ele1); |
111 |
result.setY(ele2); |
112 |
result.setZ(ele3); |
113 |
return result;
|
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("description")) |
150 |
this.description = xml.getStringProperty("description"); |
151 |
|
152 |
} |
153 |
} |