Revision 32150

View differences:

tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/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/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/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/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/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
/**
28
 * @author ?ngel Fraile Gri??n  e-mail: angel.fraile@iver.es
29
 * @since 1.1
30
 * 
31
 */
32
public class AnimationObject3DFlat extends AnimatedObjectBase {
33
	
34
	private Object view;
35
	
36
	public String getClassName() {
37
		return this.getClass().getName();
38
	}
39
	
40
	public void setClassName(String className) {
41
	}
42
	
43
	public IViewerContainer getAnimatedCanvas3D() {
44
		return (IViewerContainer) this.getAnimatedObject("canvas");
45
	}
46
	
47
	public void setAnimatedCanvas3D(IViewerContainer canvas3d) {
48
		this.addAnimatedObject("canvas", canvas3d);
49
	}
50
	
51
	public Object getAnimatedView() {
52
		return this.getAnimatedObject("view");
53
	}
54
	
55
	public void setAnimatedView(Object object) {
56
		this.addAnimatedObject("view", object);
57
	}
58
	
59
	public String getNameView() {
60
		return ((BaseView)view).getName();
61
		
62
	}
63
	
64
}
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/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

  
25
/**
26
 * @author ?ngel Fraile Gri??n  e-mail: angel.fraile@iver.es
27
 * @since 1.1
28
 * 
29
 */
30
public class AnimationTypeFactoryLayer3DFlat extends AnimationFactory {
31

  
32
	public static String registerName = "AnimationLayer3DFlat";
33
	
34
	
35
	public static AnimationLayer3DFlat animationLayer3DFlat;
36
	
37
	static {
38
		if (animationLayer3DFlat == null) {
39
			animationLayer3DFlat = new AnimationLayer3DFlat();
40
			animationLayer3DFlat.setClassName("AnimationLayer3DFlat");
41
			animationLayer3DFlat.setName("AnimationLayer3DFlat");
42
			animationLayer3DFlat.setDescription("Animacion basada en encuadres para vista 3D plana");
43
		}
44
	}
45
	
46
	/**
47
	 * Creating a new animation type.
48
	 */
49
	
50
	public Object create() {
51
		
52
		AnimationLayer3DFlat animationLayer3DFlatAux = new AnimationLayer3DFlat();
53
		animationLayer3DFlatAux.setClassName("AnimationLayer3DFlat");
54
		animationLayer3DFlatAux.setName("AnimationLayer3DFlat");
55
		animationLayer3DFlatAux.setDescription("Animacion basada en encuadres para vista 3D plana");
56
		
57
       return animationLayer3DFlatAux;
58
	}
59
	
60
	/**
61
	 * Registers in the points of extension the Factory with alias.
62
	 * 
63
	 */
64
	public static void register() {
65
		register(registerName, new AnimationTypeFactoryLayer3DFlat(), "com.iver.cit.gvsig.animation.AnimationLayer3DFlat");
66
	}
67

  
68
	/**
69
	 * Return the register name of this animation type.
70
	 */
71
	
72
	public String getRegisterName() {
73
		return registerName;
74
	}
75

  
76
}
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/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
/**
42
 * @author ?ngel Fraile Gri??n  e-mail: angel.fraile@iver.es
43
 * @since 1.1
44
 * 
45
 */
46
public class AnimationLayer3DFlat implements IAnimationTypeKeyFrame {
47

  
48
	private String className = this.getClass().getName();
49
	private String description = "Animacion basada en encuadres para vista 3D plana";
50
	private String name = "Animacion vista 3D plana";
51
	private int typeTrack = IAnimationType.TIME_TYPE_TRACK;
52
	private IInterpolator interpolator;
53
	
54
	private IAnimatedObject animationObject3DFlat = new AnimationObject3DFlat() ;
55
	private String titleWindow;
56
	
57
	private IViewerContainer m_canvas3d;
58

  
59
	public AnimationLayer3DFlat() {
60
		this.interpolator = new Interpolator3DFlat();
61
	}
62

  
63
	public String getClassName() {
64
		return className;
65
	}
66

  
67
	public String getDescription() {
68
		return description;
69
	}
70

  
71
	public String getName() {
72
		return name;
73
	}
74

  
75
	public void setClassName(String className) {
76
		this.className = className;
77
	}
78

  
79
	public void setDescription(String description) {
80
		this.description = description;
81
	}
82

  
83
	public void setName(String name) {
84
		this.name = name;
85
	}
86

  
87
	/**
88
	 * Repainting the canvas
89
	 */
90
	public void AppliesToObject(Object animated) {
91

  
92
		KeyFrame3DFlat keyf = (KeyFrame3DFlat) animated;
93
		ProjectCamera projectCamera = (ProjectCamera) keyf.getAnimatedObject();
94
		
95
		m_canvas3d = (IViewerContainer) ((AnimationObject3DFlat)animationObject3DFlat).getAnimatedCanvas3D();
96
		m_canvas3d.getOSGViewer().setCamera(projectCamera.getCamera());
97
	
98
		m_canvas3d.repaint();
99
	}
100

  
101
	public int getTypeTrack() {
102
		return typeTrack;
103
	}
104

  
105
	public void setTypeTrack(int typeTrack) {
106
		this.typeTrack = typeTrack;
107

  
108
	}
109

  
110
	public IInterpolator getInterpolator() {
111
		return this.interpolator;
112
	}
113

  
114
	public void setInterpolator(IInterpolator interpolator) {
115
		this.interpolator = interpolator;
116

  
117
	}
118

  
119
	/**
120
	 * Getting the animated object, in movement track animation; the view
121
	 */
122
	public Object getAnimatedObject() {
123
		// if animated object is null.
124
		if(this.animationObject3DFlat != null){
125
			// getting all objects.
126
			try{
127
				IWindow[] viewArray = PluginServices.getMDIManager().getAllWindows();
128
				for (int i = 0; i < viewArray.length; i++) {
129
					IWindow window = viewArray[i];
130
						if(window.getWindowInfo().getTitle().equals(this.titleWindow)){
131
							BaseView newView = (BaseView)window;// Working with base view
132
							((AnimationObject3DFlat) this.animationObject3DFlat).setAnimatedView(newView);
133
							this.setAnimatedObject(this.animationObject3DFlat);
134
							IInterpolatorTimeFuntion function = FuntionFactory.createObject("com.iver.cit.gvsig.animation.keyframe.interpolator.LinearFuntion");
135
							this.interpolator.setFuntion(function);
136
							
137
						}
138
				}
139
			}catch(Exception e) {
140
				e.printStackTrace();
141
			}
142
		}
143
		return this.animationObject3DFlat;
144
	}
145
	
146

  
147
	public void setAnimatedObject(Object object) {
148
		if (object instanceof AnimationObject3DFlat)
149
			this.animationObject3DFlat = (IAnimatedObject) object;
150
	}
151

  
152
	public XMLEntity getXMLEntity() {
153
		
154
		XMLEntity xml = new XMLEntity();
155
		xml.putProperty("className", this.getClassName());
156
		xml.putProperty("description", description);
157
		xml.putProperty("animationTrackTipe", typeTrack);
158
		
159
		BaseView myActualView = (BaseView) animationObject3DFlat.getAnimatedObject("view");
160
		
161
		titleWindow = myActualView.getWindowInfo().getTitle();
162
		xml.putProperty("titleWindow", titleWindow);
163
		xml.addChild(((IPersistence)this.interpolator).getXMLEntity());
164
		return xml;
165
	}
166

  
167
	public void setXMLEntity(XMLEntity xml) {
168
		if (xml.contains("className"))
169
			this.className=	xml.getStringProperty("className");
170
		if (xml.contains("animationTrackTipe"))
171
			this.typeTrack = xml.getIntProperty("animationTrackTipe");
172
		if (xml.contains("titleWindow"))
173
			this.titleWindow = xml.getStringProperty("titleWindow");
174
		
175
		XMLEntity xmlInterpolator = xml.getChild(0);
176
		
177
		try {
178
			String class_name = xmlInterpolator.getStringProperty("className");
179
			Class<?> classInterpolator = Class.forName(class_name);
180
			Object obj = classInterpolator .newInstance();
181
			IPersistence objPersist = (IPersistence) obj;
182
			objPersist.setXMLEntity(xmlInterpolator);
183
			this.interpolator = (IInterpolator) obj;
184
			this.setInterpolator(interpolator);
185
			
186
		} catch (Exception e) {
187
			e.printStackTrace();
188
		}
189
	}
190
}
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/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.core.osg.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
/**
34
 * @author �ngel Fraile Gri��n  e-mail: angel.fraile@iver.es
35
 * @since 1.1
36
 * 
37
 */
38
public class Interpolator3DFlat implements IInterpolator {
39

  
40
	private IInterpolatorTimeFuntion funtion;
41
	private String description = "Interpolaci�n basada en encuadres";
42
	private String name = "Interpolator3DFlat";
43
	
44
	
45
	/**
46
	 * 	Calculating the new positions in the movement animation
47
	 */
48
	public IKeyFrame interpolate(List<IKeyFrame> kfList, int index, double time) {
49
		KeyFrame3DFlat KF = new KeyFrame3DFlat();
50

  
51
		if (kfList == null)
52
			return null;
53

  
54
		// convert the time in the new time using funtion
55
		double newTime = this.getFuntion().interpolate(time);
56
		
57
		switch (kfList.size()) {
58
		// this case when there are only has 2 keyframes
59
		case 2:
60
			// getting the keyframes
61
			KeyFrame3DFlat kf1 = (KeyFrame3DFlat) kfList.get(0);
62
			KeyFrame3DFlat kf2 = (KeyFrame3DFlat) kfList.get(1);
63

  
64
			if (index == 1) {
65
				KeyFrame3DFlat kaux = kf1;
66
				kf1 = kf2;
67
				kf2 = kaux;
68
			}
69

  
70
			if ((kf1 == null) ||(kf2 == null))
71
				return null;
72
			ProjectCamera vp1 = (ProjectCamera) kf1.getAnimatedObject();
73
			ProjectCamera vp2 = (ProjectCamera) kf2.getAnimatedObject();
74

  
75
			Camera cam1 = vp1.getCamera();
76
			Camera cam2 = vp2.getCamera();
77
			double time1 = kf1.getTime();
78
			double time2 = kf2.getTime();
79
			
80
			Vec3 eye = linearInterpolate(cam1.getEye(), cam2.getEye(), time1, time2, newTime);
81
			Vec3 center = linearInterpolate(cam1.getCenter(), cam2.getCenter(), time1, time2, newTime);
82
			Vec3 up = linearInterpolate(cam1.getUp(), cam2.getUp(), time1, time2, newTime);
83
		
84
			Camera newCamera = new Camera();
85
//			newCamera.setViewByLookAt(eye, center, cam1.getUp());
86
			newCamera.setViewByLookAt(eye, center, up);
87

  
88
			ProjectCamera pe = new ProjectCamera();
89
			pe.setCamera(newCamera);
90
			KF.setName("temporal_keyframe");
91
			KF.setAnimatedObject(pe);
92
			break;
93
		}		
94
		
95
		return KF;
96
	}
97

  
98
	/**
99
	 * Return a value interpolate 
100
	 * 
101
	 * @param minX: initial x value in the 2D extent
102
	 * @param minX2: final x value in the 2D extent
103
	 * @param timePos: initial time value
104
	 * @param timePos2: final time value
105
	 * @param time: total time
106
	 * @return
107
	 */
108
	private double linearInterpolate(double minX, double minX2, double timePos,
109
			double timePos2, double time) {
110
		// P1 + (P2-P1)*((t-t1)/(t2-t1))
111
		return (minX + (minX2 - minX)
112
				* ((time - timePos) / (timePos2 - timePos)));
113
	}
114

  
115
	private Vec3 linearInterpolate(Vec3 minX, Vec3 minX2, double timePos,
116
			double timePos2, double time) {
117

  
118
		Vec3 result = new Vec3();
119

  
120
		double ele1 = linearInterpolate(minX.x(), minX2.x(), timePos, timePos2,
121
				time);
122
		double ele2 = linearInterpolate(minX.y(), minX2.y(), timePos, timePos2,
123
				time);
124
		double ele3 = linearInterpolate(minX.z(), minX2.z(), timePos, timePos2,
125
				time);
126

  
127
		result.setX(ele1);
128
		result.setY(ele2);
129
		result.setZ(ele3);
130
		return result;
131
	}
132
	
133
	public IInterpolatorTimeFuntion getFuntion() {
134
		return this.funtion;
135
	}
136

  
137
	public void setFuntion(IInterpolatorTimeFuntion funtion) {
138
		this.funtion = funtion;
139
		
140
	}
141

  
142
	public String getClassName() {
143
		return this.getClass().getName();
144
	}
145

  
146
	public String getDescription() {
147
		return this.description;
148
	}
149

  
150
	public String getName() {
151
		return this.name;
152
	}
153

  
154
	/*
155
	 * IPersistence methods.
156
	 */
157
	
158
	public XMLEntity getXMLEntity() {
159
		XMLEntity xml = new XMLEntity();	
160
		xml.putProperty("className", this.getClassName());
161
		xml.putProperty("description", this.description);
162
		return xml;
163
	}
164
	
165
	public void setXMLEntity(XMLEntity xml) {
166
		if (xml.contains("description"))
167
			this.description = xml.getStringProperty("description");
168
		
169
	}
170
}
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/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.core.osg.Matrix;
25
import org.gvsig.osgvp.core.osg.Quat;
26
import org.gvsig.osgvp.core.osg.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

  
37
/**
38
 * @author �ngel Fraile Gri��n  e-mail: angel.fraile@iver.es
39
 * @since 1.1
40
 * 
41
 */
42
public class Interpolator3DSpherical implements IInterpolator {
43

  
44
	private IInterpolatorTimeFuntion function;
45
	private String description = "Interpolaci�n basada en encuadres";
46
	private String name = "Interpolator3DSpherical";
47
	
48
	
49
	/**
50
	 * 	Calculating the new positions in the movement animation
51
	 */
52
	
53
	public IKeyFrame interpolate(List<IKeyFrame> kfList, int index, double time) {
54
		KeyFrame3DFlat KF = new KeyFrame3DFlat();
55

  
56
		if (kfList == null)
57
			return null;
58

  
59
				
60
		/*Interpolaci�n por quaterniones.*/
61
		
62
		double newTime = this.getFuntion().interpolate(time);
63
		
64
		switch (kfList.size()) {
65
		// this case when there are only has 2 keyframes
66
		case 2:
67
			// getting the keyframes
68
			KeyFrame3DFlat kf1 = (KeyFrame3DFlat) kfList.get(0);
69
			KeyFrame3DFlat kf2 = (KeyFrame3DFlat) kfList.get(1);
70

  
71
			if (index == 1) {
72
				KeyFrame3DFlat kaux = kf1;
73
				kf1 = kf2;
74
				kf2 = kaux;
75
			}
76

  
77
			if ((kf1 == null) ||(kf2 == null))
78
				return null;
79
			
80
			ProjectCamera vp1 = (ProjectCamera) kf1.getAnimatedObject();
81
			ProjectCamera vp2 = (ProjectCamera) kf2.getAnimatedObject();
82

  
83
			Camera cam1 = vp1.getCamera();
84
			Camera cam2 = vp2.getCamera();
85
			double time1 = kf1.getTime();
86
			double time2 = kf2.getTime();	
87
			
88
			newTime = (newTime-time1)/(time2-time1);//normalize time 0..1
89
			
90
			Quat from = cam1.getViewMatrix().getRotate();
91
			Quat to = cam2.getViewMatrix().getRotate();
92

  
93
			Vec3 trans1 = cam1.getViewMatrix().getTrans();
94
			Vec3 trans2 = cam2.getViewMatrix().getTrans();
95

  
96
			Vec3 new_trans = vec3LinearInterpolate(trans1, trans2, newTime);
97
			Matrix m1 = Matrix.translate(new_trans);
98
			Quat q = sphericalInterpolate(from, to, newTime);
99
			Matrix m = Matrix.rotate(q);
100
			Matrix m2 = m.prod(m1);
101
			
102
			Camera c = new Camera();
103
			c.setViewMatrix(m2);
104
		
105
			ProjectCamera pe = new ProjectCamera();
106
			pe.setCamera(c);
107
			KF.setName("temporal_keyframe");
108
			KF.setAnimatedObject(pe);
109
			break;
110

  
111
		}
112
		
113
		
114
		return KF;
115
	}
116
	
117
	/**
118
	 * Spherical interpolation based in quaternions
119
	 * @param from: initial position 
120
	 * @param to: final position
121
	 * @param time: total time
122
	 * @return the actual position of the earth movement 
123
	 */
124
	private Quat sphericalInterpolate(Quat from, Quat to, double time) {
125

  
126
		Quat fromQuat = new Quat();
127

  
128
		return fromQuat.slerp(time, from, to);
129

  
130
	}
131

  
132
//	private double doubleInterpolate(double from, double to, double time) {
133
//		if (from == to)
134
//			return from;
135
//		return from + (to - from) * time;
136
//	}
137

  
138
	private Vec3 vec3LinearInterpolate(Vec3 from, Vec3 to, double time) {
139
		if (from.equals(to))
140
			return new Vec3(from);
141
		return from.sum(to.sub(from).escalarProduct(time));
142
	}
143
	
144
	public IInterpolatorTimeFuntion getFuntion() {
145
		return this.function;
146
	}
147

  
148
	public void setFuntion(IInterpolatorTimeFuntion function) {
149
		this.function = function;
150
		
151
	}
152

  
153
	public String getClassName() {
154
		return this.getClass().getName();
155
	}
156

  
157
	public String getDescription() {
158
		return this.description;
159
	}
160

  
161
	public String getName() {
162
		return this.name;
163
	}
164

  
165
	/**
166
	 * IPersistence methods.
167
	 */
168
	
169
	public XMLEntity getXMLEntity() {
170
		XMLEntity xml = new XMLEntity();	
171
		xml.putProperty("className", this.getClassName());
172
		xml.putProperty("description", this.description);
173
		return xml;
174
	}
175
	
176
	public void setXMLEntity(XMLEntity xml) {
177
		if (xml.contains("description"))
178
			this.description = xml.getStringProperty("description");
179
		
180
	}
181
}
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/keyFrame/AnimationKeyFrame3DFlatFactory.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.keyFrame;
21

  
22
import com.iver.cit.gvsig.animation.AnimationFactory;
23

  
24
/**
25
 * @author ?ngel Fraile Gri??n  e-mail: angel.fraile@iver.es
26
 * @since 1.1
27
 * 
28
 */
29
public class AnimationKeyFrame3DFlatFactory extends AnimationFactory {
30

  
31
	public static String registerName = "KeyFrame3DFlat";
32
	
33
	
34
	/**
35
	 * Creating a new keyFrmame 3DFlat in the factory.
36
	 */
37
	public Object create() {
38
		KeyFrame3DFlat keyFrameFlat = new KeyFrame3DFlat();
39
        return keyFrameFlat;
40
	}
41
	
42
	/**
43
	 * Registers in the points of extension the Factory with alias.
44
	 */
45
	public static void register() {
46
		register(registerName, new AnimationKeyFrame3DFlatFactory(), "com.iver.cit.gvsig.animation.KeyFrame3DFlat");
47
	}
48

  
49
	public String getRegisterName() {
50
		return registerName;
51
	}
52

  
53
}
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/libraries/libAnimation3D/src/main/java/com/iver/cit/gvsig/animation/keyFrame/KeyFrame3DFlat.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.keyFrame;
21

  
22
import java.util.List;
23

  
24
import com.iver.ai2.gvsig3d.camera.ProjectCamera;
25
import com.iver.cit.gvsig.animation.keyframe.IKeyFrame;
26
import com.iver.utiles.IPersistence;
27
import com.iver.utiles.XMLEntity;
28

  
29
/**
30
 * @author ?ngel Fraile Gri??n  e-mail: angel.fraile@iver.es
31
 * @since 1.1
32
 * 
33
 */
34
public class KeyFrame3DFlat implements IKeyFrame {
35

  
36
	private String name;
37
	private double time;
38
	
39
	private  String aliasKeyFrame = "KeyFrame3DFlat";
40

  
41
	ProjectCamera projectCamera = null;
42

  
43
	
44

  
45
	public void CapturesProperties() {
46
		// TODO Auto-generated method stub
47

  
48
	}
49

  
50
	public String getName() {
51
		return this.name;
52
	}
53

  
54
	public List<IKeyFrame> getPropertiesList() {
55
		return null;
56
	}
57

  
58
	public void setName(String name) {
59
		this.name = name;
60

  
61
	}
62

  
63
	public void setPropertiesList(List<IKeyFrame> list) {
64
		// TODO Auto-generated method stub
65
	}
66

  
67
	public String toString() {
68
		String result;
69
		result = " keyframe3DFlats:\n";
70
		result += " tiempo: " + this.time;
71
		result += " nombre del extent: " + this.projectCamera.getDescription();
72
		return result;
73
	}
74

  
75
	
76

  
77
	public Object getAnimatedObject() {
78
		return projectCamera;
79
	}
80
	public void setAnimatedObject(Object object) {
81
		this.projectCamera = (ProjectCamera) object;
82
	}
83

  
84
	public double getTime() {
85
		return time;
86
	}
87

  
88
	public void setTime(double time) {
89
		this.time = time;
90
	}
91

  
92
	public String getClassName() {
93
		return this.getClass().getName();
94
	}
95

  
96
	public XMLEntity getXMLEntity() {
97
		XMLEntity xml = new XMLEntity();
98
		
99
		xml.putProperty("className", this.getClassName());
100
		xml.putProperty("keyFrameAlias", aliasKeyFrame);
101
//		xml.putProperty("keyFrameName", name);
102
		xml.putProperty("time", time);
103
		
104
		xml.addChild(((IPersistence)projectCamera).getXMLEntity());
105
		
106
		return xml;
107
	}
108

  
109
	public void setXMLEntity(XMLEntity xml) {
110
		
111
		if (xml.contains("time"))
112
			this.time = xml.getDoubleProperty("time");
113
		if (xml.contains("keyFrameAlias"))
114
			this.aliasKeyFrame = xml.getStringProperty("keyFrameAlias");
115
		
116
		// Get camera
117
		XMLEntity xmlProp = xml.getChild(0);
118
		if (xmlProp.contains("eyeX")) {
119
			try {
120
				String className = xmlProp.getStringProperty("className");
121
				Class<?> classProp = Class.forName(className);
122
				Object obj = classProp.newInstance();
123
				IPersistence objPersist = (IPersistence) obj;
124
				objPersist.setXMLEntity(xmlProp);
125
				projectCamera = (ProjectCamera) obj;
126
			} catch (Exception e) {
127

  
128
			}
129
		}
130
	}
131
}
tags/gvSIG_3D_Animation_1_9_SNAPSHOT_build_12/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.9-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.9-SNAPSHOT</version>
14
	</parent>
15
    <properties>
16
        <build-dir>${basedir}/../build</build-dir>
17
    </properties>
18
	<dependencies>
19
		<dependency>
20
			<groupId>org.gvsig</groupId>
21
			<artifactId>lib3DMap</artifactId>
22
			<version>1.9-SNAPSHOT</version>
23
		</dependency>
24
		<dependency>
25
			<groupId>org.gvsig</groupId>
26
			<artifactId>lib3DMap-share</artifactId>
27
			<version>1.9-SNAPSHOT</version>
28
		</dependency>
29
		<dependency>
30
			<groupId>org.gvsig</groupId>
31
			<artifactId>libAnimation</artifactId>
32
			<version>1.9-SNAPSHOT</version>
33
		</dependency>
34
		<dependency>
35
			<groupId>org.gvsig</groupId>
36
			<artifactId>appgvSIG</artifactId>
37
			<version>1.9-SNAPSHOT</version>
38
		</dependency>
39
	</dependencies>
40
</project>
0 41

  

Also available in: Unified diff