Revision 25508
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/src/test/java/com/iver/cit/gvsig/animation/CreateKeyFrame3DTest.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.animation; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.animation.keyFrame.AnimationKeyFrame3DFlatFactory; |
|
4 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
|
5 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
|
6 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
|
7 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
|
8 |
|
|
9 |
import junit.framework.TestCase; |
|
10 |
|
|
11 |
public class CreateKeyFrame3DTest extends TestCase { |
|
12 |
|
|
13 |
|
|
14 |
public void test1() { |
|
15 |
|
|
16 |
AnimationKeyFrame3DFlatFactory.register(); |
|
17 |
|
|
18 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
|
19 |
System.out.println("Getting extension point..."); |
|
20 |
ExtensionPoint extPoint = ((ExtensionPoint) extensionPoints.get("Animation")); |
|
21 |
|
|
22 |
//System.out.println("Creating ..."); |
|
23 |
try { |
|
24 |
System.out.println("Creating ..."); |
|
25 |
IKeyFrame keyframe = (IKeyFrame) extPoint.create("KeyFrame3DFlat"); |
|
26 |
keyframe.getName(); |
|
27 |
} catch (InstantiationException e) { |
|
28 |
// TODO Auto-generated catch block |
|
29 |
e.printStackTrace(); |
|
30 |
} catch (IllegalAccessException e) { |
|
31 |
// TODO Auto-generated catch block |
|
32 |
e.printStackTrace(); |
|
33 |
} |
|
34 |
System.out.println("Done "); |
|
35 |
} |
|
36 |
} |
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/src/test/java/com/iver/cit/gvsig/animation/AppTest.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.animation; |
|
2 |
|
|
3 |
import junit.framework.Test; |
|
4 |
import junit.framework.TestCase; |
|
5 |
import junit.framework.TestSuite; |
|
6 |
|
|
7 |
/** |
|
8 |
* Unit test for simple App. |
|
9 |
*/ |
|
10 |
public class AppTest |
|
11 |
extends TestCase |
|
12 |
{ |
|
13 |
/** |
|
14 |
* Create the test case |
|
15 |
* |
|
16 |
* @param testName name of the test case |
|
17 |
*/ |
|
18 |
public AppTest( String testName ) |
|
19 |
{ |
|
20 |
super( testName ); |
|
21 |
} |
|
22 |
|
|
23 |
/** |
|
24 |
* @return the suite of tests being tested |
|
25 |
*/ |
|
26 |
public static Test suite() |
|
27 |
{ |
|
28 |
return new TestSuite( AppTest.class ); |
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* Rigourous Test :-) |
|
33 |
*/ |
|
34 |
public void testApp() |
|
35 |
{ |
|
36 |
assertTrue( true ); |
|
37 |
} |
|
38 |
} |
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/animatedObject/AnimationObject3DFlat.java | ||
---|---|---|
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 |
|
|
20 |
package com.iver.cit.gvsig.animation.animatedObject; |
|
21 |
|
|
22 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
|
23 |
|
|
24 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
|
25 |
|
|
26 |
|
|
27 |
public class AnimationObject3DFlat extends AnimatedObjectBase { |
|
28 |
|
|
29 |
private Object view; |
|
30 |
|
|
31 |
public String getClassName() { |
|
32 |
return this.getClass().getName(); |
|
33 |
} |
|
34 |
|
|
35 |
public void setClassName(String className) { |
|
36 |
} |
|
37 |
|
|
38 |
public IViewerContainer getAnimatedCanvas3D() { |
|
39 |
return (IViewerContainer) this.getAnimatedObject("canvas"); |
|
40 |
} |
|
41 |
|
|
42 |
public void setAnimatedCanvas3D(IViewerContainer canvas3d) { |
|
43 |
this.addAnimatedObject("canvas", canvas3d); |
|
44 |
} |
|
45 |
|
|
46 |
public Object getAnimatedView() { |
|
47 |
return this.getAnimatedObject("view"); |
|
48 |
} |
|
49 |
|
|
50 |
public void setAnimatedView(Object object) { |
|
51 |
this.addAnimatedObject("view", object); |
|
52 |
} |
|
53 |
|
|
54 |
public String getNameView() { |
|
55 |
return ((BaseView)view).getName(); |
|
56 |
|
|
57 |
} |
|
58 |
|
|
59 |
} |
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/animationType/AnimationTypeFactoryLayer3DFlat.java | ||
---|---|---|
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 |
|
|
20 |
package com.iver.cit.gvsig.animation.animationType; |
|
21 |
|
|
22 |
import com.iver.cit.gvsig.animation.AnimationFactory; |
|
23 |
|
|
24 |
public class AnimationTypeFactoryLayer3DFlat extends AnimationFactory { |
|
25 |
|
|
26 |
public static String registerName = "AnimationLayer3DFlat"; |
|
27 |
|
|
28 |
|
|
29 |
public static AnimationLayer3DFlat animationLayer3DFlat; |
|
30 |
|
|
31 |
static { |
|
32 |
if (animationLayer3DFlat == null) { |
|
33 |
animationLayer3DFlat = new AnimationLayer3DFlat(); |
|
34 |
animationLayer3DFlat.setClassName("AnimationLayer3DFlat"); |
|
35 |
animationLayer3DFlat.setName("AnimationLayer3DFlat"); |
|
36 |
animationLayer3DFlat.setDescription("Animacion basada en encuadres para vista 3D plana"); |
|
37 |
} |
|
38 |
} |
|
39 |
|
|
40 |
/** |
|
41 |
* Creating a new animation type. |
|
42 |
*/ |
|
43 |
|
|
44 |
public Object create() { |
|
45 |
|
|
46 |
AnimationLayer3DFlat animationLayer3DFlatAux = new AnimationLayer3DFlat(); |
|
47 |
animationLayer3DFlatAux.setClassName("AnimationLayer3DFlat"); |
|
48 |
animationLayer3DFlatAux.setName("AnimationLayer3DFlat"); |
|
49 |
animationLayer3DFlatAux.setDescription("Animacion basada en encuadres para vista 3D plana"); |
|
50 |
|
|
51 |
return animationLayer3DFlatAux; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Registers in the points of extension the Factory with alias. |
|
56 |
* |
|
57 |
*/ |
|
58 |
public static void register() { |
|
59 |
register(registerName, new AnimationTypeFactoryLayer3DFlat(), "com.iver.cit.gvsig.animation.AnimationLayer3DFlat"); |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Return the register name of this animation type. |
|
64 |
*/ |
|
65 |
|
|
66 |
public String getRegisterName() { |
|
67 |
return registerName; |
|
68 |
} |
|
69 |
|
|
70 |
} |
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/animationType/AnimationLayer3DFlat.java | ||
---|---|---|
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 |
|
|
20 |
|
|
21 |
package com.iver.cit.gvsig.animation.animationType; |
|
22 |
|
|
23 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
|
24 |
|
|
25 |
import com.iver.ai2.gvsig3d.camera.ProjectCamera; |
|
26 |
import com.iver.andami.PluginServices; |
|
27 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
28 |
import com.iver.cit.gvsig.animation.IAnimationType; |
|
29 |
import com.iver.cit.gvsig.animation.animatedObject.AnimationObject3DFlat; |
|
30 |
import com.iver.cit.gvsig.animation.animatedObject.IAnimatedObject; |
|
31 |
import com.iver.cit.gvsig.animation.interpolator.Interpolator3DFlat; |
|
32 |
import com.iver.cit.gvsig.animation.keyFrame.KeyFrame3DFlat; |
|
33 |
import com.iver.cit.gvsig.animation.keyframe.IAnimationTypeKeyFrame; |
|
34 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.FuntionFactory; |
|
35 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
|
36 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion; |
|
37 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
|
38 |
import com.iver.utiles.IPersistence; |
|
39 |
import com.iver.utiles.XMLEntity; |
|
40 |
|
|
41 |
public class AnimationLayer3DFlat implements IAnimationTypeKeyFrame { |
|
42 |
|
|
43 |
private String className = this.getClass().getName(); |
|
44 |
private String description = "Animacion basada en encuadres para vista 3D plana"; |
|
45 |
private String name = "Animacion vista 3D plana"; |
|
46 |
private int typeTrack = IAnimationType.TIME_TYPE_TRACK; |
|
47 |
private IInterpolator interpolator; |
|
48 |
|
|
49 |
private IAnimatedObject animationObject3DFlat = new AnimationObject3DFlat() ; |
|
50 |
private String titleWindow; |
|
51 |
|
|
52 |
private IViewerContainer m_canvas3d; |
|
53 |
|
|
54 |
public AnimationLayer3DFlat() { |
|
55 |
this.interpolator = new Interpolator3DFlat(); |
|
56 |
} |
|
57 |
|
|
58 |
public String getClassName() { |
|
59 |
return className; |
|
60 |
} |
|
61 |
|
|
62 |
public String getDescription() { |
|
63 |
return description; |
|
64 |
} |
|
65 |
|
|
66 |
public String getName() { |
|
67 |
return name; |
|
68 |
} |
|
69 |
|
|
70 |
public void setClassName(String className) { |
|
71 |
this.className = className; |
|
72 |
} |
|
73 |
|
|
74 |
public void setDescription(String description) { |
|
75 |
this.description = description; |
|
76 |
} |
|
77 |
|
|
78 |
public void setName(String name) { |
|
79 |
this.name = name; |
|
80 |
} |
|
81 |
|
|
82 |
public void AppliesToObject(Object animated) { |
|
83 |
|
|
84 |
KeyFrame3DFlat keyf = (KeyFrame3DFlat) animated; |
|
85 |
ProjectCamera projectCamera = (ProjectCamera) keyf.getAnimatedObject(); |
|
86 |
|
|
87 |
m_canvas3d = (IViewerContainer) ((AnimationObject3DFlat)animationObject3DFlat).getAnimatedCanvas3D(); |
|
88 |
m_canvas3d.getOSGViewer().setCamera(projectCamera.getCamera()); |
|
89 |
|
|
90 |
m_canvas3d.repaint(); |
|
91 |
} |
|
92 |
|
|
93 |
public int getTypeTrack() { |
|
94 |
return typeTrack; |
|
95 |
} |
|
96 |
|
|
97 |
public void setTypeTrack(int typeTrack) { |
|
98 |
this.typeTrack = typeTrack; |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
public IInterpolator getInterpolator() { |
|
103 |
return this.interpolator; |
|
104 |
} |
|
105 |
|
|
106 |
public void setInterpolator(IInterpolator interpolator) { |
|
107 |
this.interpolator = interpolator; |
|
108 |
|
|
109 |
} |
|
110 |
|
|
111 |
public Object getAnimatedObject() { |
|
112 |
// if animated object is null. |
|
113 |
if(this.animationObject3DFlat != null){ |
|
114 |
// getting all objects. |
|
115 |
try{ |
|
116 |
IWindow[] viewArray = PluginServices.getMDIManager().getAllWindows(); |
|
117 |
for (int i = 0; i < viewArray.length; i++) { |
|
118 |
IWindow window = viewArray[i]; |
|
119 |
if(window.getWindowInfo().getTitle().equals(this.titleWindow)){ |
|
120 |
BaseView newView = (BaseView)window;// Working with base view |
|
121 |
((AnimationObject3DFlat) this.animationObject3DFlat).setAnimatedView(newView); |
|
122 |
this.setAnimatedObject(this.animationObject3DFlat); |
|
123 |
IInterpolatorTimeFuntion function = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion"); |
|
124 |
this.interpolator.setFuntion(function); |
|
125 |
} |
|
126 |
//} |
|
127 |
} |
|
128 |
}catch(Exception e) { |
|
129 |
e.printStackTrace(); |
|
130 |
} |
|
131 |
} |
|
132 |
return this.animationObject3DFlat; |
|
133 |
} |
|
134 |
|
|
135 |
public void setAnimatedObject(Object object) { |
|
136 |
if (object instanceof AnimationObject3DFlat) |
|
137 |
this.animationObject3DFlat = (IAnimatedObject) object; |
|
138 |
} |
|
139 |
|
|
140 |
public XMLEntity getXMLEntity() { |
|
141 |
|
|
142 |
XMLEntity xml = new XMLEntity(); |
|
143 |
xml.putProperty("className", this.getClassName()); |
|
144 |
xml.putProperty("description", description); |
|
145 |
xml.putProperty("animationTrackTipe", typeTrack); |
|
146 |
|
|
147 |
BaseView myActualView = (BaseView) animationObject3DFlat.getAnimatedObject("view"); |
|
148 |
|
|
149 |
titleWindow = myActualView.getWindowInfo().getTitle(); |
|
150 |
xml.putProperty("titleWindow", titleWindow); |
|
151 |
xml.addChild(((IPersistence)this.interpolator).getXMLEntity()); |
|
152 |
return xml; |
|
153 |
} |
|
154 |
|
|
155 |
public void setXMLEntity(XMLEntity xml) { |
|
156 |
if (xml.contains("className")) |
|
157 |
this.className= xml.getStringProperty("className"); |
|
158 |
if (xml.contains("animationTrackTipe")) |
|
159 |
this.typeTrack = xml.getIntProperty("animationTrackTipe"); |
|
160 |
if (xml.contains("titleWindow")) |
|
161 |
this.titleWindow = xml.getStringProperty("titleWindow"); |
|
162 |
|
|
163 |
XMLEntity xmlInterpolator = xml.getChild(0); |
|
164 |
|
|
165 |
try { |
|
166 |
String class_name = xmlInterpolator.getStringProperty("className"); |
|
167 |
Class<?> classInterpolator = Class.forName(class_name); |
|
168 |
Object obj = classInterpolator .newInstance(); |
|
169 |
IPersistence objPersist = (IPersistence) obj; |
|
170 |
objPersist.setXMLEntity(xmlInterpolator); |
|
171 |
this.interpolator = (IInterpolator) obj; |
|
172 |
this.setInterpolator(interpolator); |
|
173 |
|
|
174 |
} catch (Exception e) { |
|
175 |
e.printStackTrace(); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/interpolator/Interpolator3DFlat.java | ||
---|---|---|
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 |
} |
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/interpolator/Interpolator3DSpherical.java | ||
---|---|---|
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 |
|
|
20 |
package com.iver.cit.gvsig.animation.interpolator; |
|
21 |
|
|
22 |
import java.util.List; |
|
23 |
|
|
24 |
import org.gvsig.osgvp.Matrix; |
|
25 |
import org.gvsig.osgvp.Quat; |
|
26 |
import org.gvsig.osgvp.Vec3; |
|
27 |
import org.gvsig.osgvp.viewer.Camera; |
|
28 |
|
|
29 |
import com.iver.ai2.gvsig3d.camera.ProjectCamera; |
|
30 |
import com.iver.cit.gvsig.animation.keyFrame.KeyFrame3DFlat; |
|
31 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
|
32 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolator; |
|
33 |
import com.iver.cit.gvsig.animation.keyframe.interpolator.IInterpolatorTimeFuntion; |
|
34 |
import com.iver.utiles.XMLEntity; |
|
35 |
|
|
36 |
public class Interpolator3DSpherical implements IInterpolator { |
|
37 |
|
|
38 |
private IInterpolatorTimeFuntion function; |
|
39 |
private String description = "Interpolaci?n basada en encuadres"; |
|
40 |
private String name = "Interpolator3DSpherical"; |
|
41 |
|
|
42 |
public IKeyFrame interpolate(List<IKeyFrame> kfList, int index, double time) { |
|
43 |
KeyFrame3DFlat KF = new KeyFrame3DFlat(); |
|
44 |
|
|
45 |
if (kfList == null) |
|
46 |
return null; |
|
47 |
|
|
48 |
|
|
49 |
/*Interpolaci?n por quaterniones.*/ |
|
50 |
|
|
51 |
double newTime = this.getFuntion().interpolate(time); |
|
52 |
|
|
53 |
switch (kfList.size()) { |
|
54 |
// this case when there are only has 2 keyframes |
|
55 |
case 2: |
|
56 |
// getting the keyframes |
|
57 |
KeyFrame3DFlat kf1 = (KeyFrame3DFlat) kfList.get(0); |
|
58 |
KeyFrame3DFlat kf2 = (KeyFrame3DFlat) kfList.get(1); |
|
59 |
|
|
60 |
if (index == 1) { |
|
61 |
KeyFrame3DFlat kaux = kf1; |
|
62 |
kf1 = kf2; |
|
63 |
kf2 = kaux; |
|
64 |
} |
|
65 |
|
|
66 |
if ((kf1 == null) ||(kf2 == null)) |
|
67 |
return null; |
|
68 |
|
|
69 |
ProjectCamera vp1 = (ProjectCamera) kf1.getAnimatedObject(); |
|
70 |
ProjectCamera vp2 = (ProjectCamera) kf2.getAnimatedObject(); |
|
71 |
|
|
72 |
Camera cam1 = vp1.getCamera(); |
|
73 |
Camera cam2 = vp2.getCamera(); |
|
74 |
double time1 = kf1.getTime(); |
|
75 |
double time2 = kf2.getTime(); |
|
76 |
|
|
77 |
newTime = (newTime-time1)/(time2-time1);//normalize time 0..1 |
|
78 |
|
|
79 |
Quat from = cam1.getViewMatrix().getRotate(); |
|
80 |
Quat to = cam2.getViewMatrix().getRotate(); |
|
81 |
|
|
82 |
Vec3 trans1 = cam1.getViewMatrix().getTrans(); |
|
83 |
Vec3 trans2 = cam2.getViewMatrix().getTrans(); |
|
84 |
|
|
85 |
Vec3 new_trans = vec3LinearInterpolate(trans1, trans2, newTime); |
|
86 |
Matrix m1 = Matrix.translate(new_trans); |
|
87 |
Quat q = sphericalInterpolate(from, to, newTime); |
|
88 |
Matrix m = Matrix.rotate(q); |
|
89 |
Matrix m2 = m.prod(m1); |
|
90 |
|
|
91 |
Camera c = new Camera(); |
|
92 |
c.setViewMatrix(m2); |
|
93 |
|
|
94 |
ProjectCamera pe = new ProjectCamera(); |
|
95 |
pe.setCamera(c); |
|
96 |
KF.setName("temporal_keyframe"); |
|
97 |
KF.setAnimatedObject(pe); |
|
98 |
break; |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
return KF; |
|
104 |
} |
|
105 |
|
|
106 |
private Quat sphericalInterpolate(Quat from, Quat to, double time) { |
|
107 |
|
|
108 |
Quat fromQuat = new Quat(); |
|
109 |
|
|
110 |
return fromQuat.slerp(time, from, to); |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
// private double doubleInterpolate(double from, double to, double time) { |
|
115 |
// if (from == to) |
|
116 |
// return from; |
|
117 |
// return from + (to - from) * time; |
|
118 |
// } |
|
119 |
|
|
120 |
private Vec3 vec3LinearInterpolate(Vec3 from, Vec3 to, double time) { |
|
121 |
if (from.equals(to)) |
|
122 |
return new Vec3(from); |
|
123 |
return from.sum(to.sub(from).escalarProduct(time)); |
|
124 |
} |
|
125 |
|
|
126 |
public IInterpolatorTimeFuntion getFuntion() { |
|
127 |
return this.function; |
|
128 |
} |
|
129 |
|
|
130 |
public void setFuntion(IInterpolatorTimeFuntion function) { |
|
131 |
this.function = function; |
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
public String getClassName() { |
|
136 |
return this.getClass().getName(); |
|
137 |
} |
|
138 |
|
|
139 |
public String getDescription() { |
|
140 |
return this.description; |
|
141 |
} |
|
142 |
|
|
143 |
public String getName() { |
|
144 |
return this.name; |
|
145 |
} |
|
146 |
|
|
147 |
/* |
|
148 |
* IPersistence methods. |
|
149 |
*/ |
|
150 |
|
|
151 |
public XMLEntity getXMLEntity() { |
|
152 |
XMLEntity xml = new XMLEntity(); |
|
153 |
xml.putProperty("className", this.getClassName()); |
|
154 |
xml.putProperty("description", this.description); |
|
155 |
return xml; |
|
156 |
} |
|
157 |
|
|
158 |
public void setXMLEntity(XMLEntity xml) { |
|
159 |
if (xml.contains("description")) |
|
160 |
this.description = xml.getStringProperty("description"); |
|
161 |
|
|
162 |
} |
|
163 |
} |
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/keyFrame/AnimationKeyFrame3DFlatFactory.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.animation.keyFrame; |
|
2 |
|
|
3 |
import com.iver.cit.gvsig.animation.AnimationFactory; |
|
4 |
|
|
5 |
|
|
6 |
public class AnimationKeyFrame3DFlatFactory extends AnimationFactory { |
|
7 |
|
|
8 |
public static String registerName = "KeyFrame3DFlat"; |
|
9 |
|
|
10 |
|
|
11 |
/** |
|
12 |
* Creating a new keyFrmame 3DFlat in the factory. |
|
13 |
*/ |
|
14 |
public Object create() { |
|
15 |
KeyFrame3DFlat keyFrameFlat = new KeyFrame3DFlat(); |
|
16 |
return keyFrameFlat; |
|
17 |
} |
|
18 |
|
|
19 |
/** |
|
20 |
* Registers in the points of extension the Factory with alias. |
|
21 |
*/ |
|
22 |
public static void register() { |
|
23 |
register(registerName, new AnimationKeyFrame3DFlatFactory(), "com.iver.cit.gvsig.animation.KeyFrame3DFlat"); |
|
24 |
} |
|
25 |
|
|
26 |
public String getRegisterName() { |
|
27 |
return registerName; |
|
28 |
} |
|
29 |
|
|
30 |
} |
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/keyFrame/KeyFrame3DFlat.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.animation.keyFrame; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import com.iver.ai2.gvsig3d.camera.ProjectCamera; |
|
6 |
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame; |
|
7 |
import com.iver.utiles.IPersistence; |
|
8 |
import com.iver.utiles.XMLEntity; |
|
9 |
|
|
10 |
public class KeyFrame3DFlat implements IKeyFrame { |
|
11 |
|
|
12 |
private String name; |
|
13 |
private double time; |
|
14 |
|
|
15 |
private String aliasKeyFrame = "KeyFrame3DFlat"; |
|
16 |
|
|
17 |
ProjectCamera projectCamera = null; |
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
public void CapturesProperties() { |
|
22 |
// TODO Auto-generated method stub |
|
23 |
|
|
24 |
} |
|
25 |
|
|
26 |
public String getName() { |
|
27 |
return this.name; |
|
28 |
} |
|
29 |
|
|
30 |
public List<IKeyFrame> getPropertiesList() { |
|
31 |
return null; |
|
32 |
} |
|
33 |
|
|
34 |
public void setName(String name) { |
|
35 |
this.name = name; |
|
36 |
|
|
37 |
} |
|
38 |
|
|
39 |
public void setPropertiesList(List<IKeyFrame> list) { |
|
40 |
// TODO Auto-generated method stub |
|
41 |
} |
|
42 |
|
|
43 |
public String toString() { |
|
44 |
String result; |
|
45 |
result = " keyframe3DFlats:\n"; |
|
46 |
result += " tiempo: " + this.time; |
|
47 |
result += " nombre del extent: " + this.projectCamera.getDescription(); |
|
48 |
return result; |
|
49 |
} |
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
public Object getAnimatedObject() { |
|
54 |
return projectCamera; |
|
55 |
} |
|
56 |
public void setAnimatedObject(Object object) { |
|
57 |
this.projectCamera = (ProjectCamera) object; |
|
58 |
} |
|
59 |
|
|
60 |
public double getTime() { |
|
61 |
return time; |
|
62 |
} |
|
63 |
|
|
64 |
public void setTime(double time) { |
|
65 |
this.time = time; |
|
66 |
} |
|
67 |
|
|
68 |
public String getClassName() { |
|
69 |
return this.getClass().getName(); |
|
70 |
} |
|
71 |
|
|
72 |
public XMLEntity getXMLEntity() { |
|
73 |
XMLEntity xml = new XMLEntity(); |
|
74 |
|
|
75 |
xml.putProperty("className", this.getClassName()); |
|
76 |
xml.putProperty("keyFrameAlias", aliasKeyFrame); |
|
77 |
// xml.putProperty("keyFrameName", name); |
|
78 |
xml.putProperty("time", time); |
|
79 |
|
|
80 |
xml.addChild(((IPersistence)projectCamera).getXMLEntity()); |
|
81 |
|
|
82 |
return xml; |
|
83 |
} |
|
84 |
|
|
85 |
public void setXMLEntity(XMLEntity xml) { |
|
86 |
|
|
87 |
if (xml.contains("time")) |
|
88 |
this.time = xml.getDoubleProperty("time"); |
|
89 |
if (xml.contains("keyFrameAlias")) |
|
90 |
this.aliasKeyFrame = xml.getStringProperty("keyFrameAlias"); |
|
91 |
|
|
92 |
// Get camera |
|
93 |
XMLEntity xmlProp = xml.getChild(0); |
|
94 |
if (xmlProp.contains("eyeX")) { |
|
95 |
try { |
|
96 |
String className = xmlProp.getStringProperty("className"); |
|
97 |
Class<?> classProp = Class.forName(className); |
|
98 |
Object obj = classProp.newInstance(); |
|
99 |
IPersistence objPersist = (IPersistence) obj; |
|
100 |
objPersist.setXMLEntity(xmlProp); |
|
101 |
projectCamera = (ProjectCamera) obj; |
|
102 |
} catch (Exception e) { |
|
103 |
|
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
} |
tags/3D_Animation_v1_0alpha_Build_5/libraries/libAnimation3D/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
2 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>libAnimation3D</artifactId> |
|
6 |
<packaging>jar</packaging> |
|
7 |
<version>1.0-SNAPSHOT</version> |
|
8 |
<name>libAnimation3D</name> |
|
9 |
<url>http://maven.apache.org</url> |
|
10 |
<parent> |
|
11 |
<groupId>org.gvsig</groupId> |
|
12 |
<artifactId>gvsig-library-base-pom</artifactId> |
|
13 |
<version>1.0-SNAPSHOT</version> |
|
14 |
</parent> |
|
15 |
<dependencies> |
|
16 |
<dependency> |
|
17 |
<groupId>org.gvsig</groupId> |
|
18 |
<artifactId>lib3DMap</artifactId> |
|
19 |
<version>1.0-SNAPSHOT</version> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>lib3DMap-share</artifactId> |
|
24 |
<version>1.0-SNAPSHOT</version> |
|
25 |
</dependency> |
|
26 |
<dependency> |
|
27 |
<groupId>org.gvsig</groupId> |
|
28 |
<artifactId>libAnimation</artifactId> |
|
29 |
<version>1.0-SNAPSHOT</version> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.gvsig</groupId> |
|
33 |
<artifactId>appgvSIG</artifactId> |
|
34 |
<version>2.1-SNAPSHOT</version> |
|
35 |
</dependency> |
|
36 |
</dependencies> |
|
37 |
</project> |
|
0 | 38 |
Also available in: Unified diff