gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / camera / ProjectCamera.java @ 311
History | View | Annotate | Download (3.92 KB)
1 |
package org.gvsig.gvsig3d.app.camera; |
---|---|
2 |
|
3 |
import org.gvsig.osgvp.core.osg.Vec3; |
4 |
import org.gvsig.osgvp.viewer.Camera; |
5 |
import org.gvsig.tools.ToolsLocator; |
6 |
import org.gvsig.tools.dynobject.DynStruct; |
7 |
import org.gvsig.tools.persistence.PersistenceManager; |
8 |
import org.gvsig.tools.persistence.Persistent; |
9 |
import org.gvsig.tools.persistence.PersistentState; |
10 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
11 |
import org.gvsig.tools.util.Callable; |
12 |
|
13 |
/**
|
14 |
* This class is used to manage the cameras that the "herramienta de encuadres"
|
15 |
* needs like a data model
|
16 |
*
|
17 |
* @author AI2
|
18 |
*/
|
19 |
public class ProjectCamera implements Persistent { |
20 |
|
21 |
public static final String PARAMETERS_DEFINITION_NAME = "ProjectCamera"; |
22 |
|
23 |
public static final String CAMERA = "camera"; |
24 |
|
25 |
public static final String EYEX = "eyex"; |
26 |
|
27 |
public static final String EYEY = "eyey"; |
28 |
|
29 |
public static final String EYEZ = "eyez"; |
30 |
|
31 |
public static final String CENTERX = "centerx"; |
32 |
|
33 |
public static final String CENTERY = "centery"; |
34 |
|
35 |
public static final String CENTERZ = "centerz"; |
36 |
|
37 |
public static final String UPX = "upx"; |
38 |
|
39 |
public static final String UPY = "upy"; |
40 |
|
41 |
public static final String UPZ = "upz"; |
42 |
|
43 |
private Camera _camera;
|
44 |
|
45 |
private String description; |
46 |
|
47 |
/**
|
48 |
* Return the description
|
49 |
*
|
50 |
* @return description of the camera
|
51 |
*/
|
52 |
public String getDescription() { |
53 |
return description;
|
54 |
} |
55 |
|
56 |
/**
|
57 |
* Set the description
|
58 |
*
|
59 |
* @param the
|
60 |
* description of the camera
|
61 |
*/
|
62 |
public void setDescription(String string) { |
63 |
description = string; |
64 |
} |
65 |
|
66 |
/**
|
67 |
* @see java.lang.Object#toString()
|
68 |
*/
|
69 |
public String toString() { |
70 |
return description;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Return the camera object
|
75 |
*
|
76 |
* @return camera object
|
77 |
*/
|
78 |
public Camera getCamera() {
|
79 |
return _camera;
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* Set the camera object
|
84 |
*
|
85 |
* @param the
|
86 |
* camera object
|
87 |
*/
|
88 |
public void setCamera(Camera camera) { |
89 |
this._camera = camera;
|
90 |
} |
91 |
|
92 |
/*
|
93 |
* (non-Javadoc)
|
94 |
*
|
95 |
* @see com.iver.utiles.IPersistence#getClassName()
|
96 |
*/
|
97 |
public String getClassName() { |
98 |
return this.getClass().getName(); |
99 |
} |
100 |
|
101 |
public void saveToState(PersistentState state) throws PersistenceException { |
102 |
|
103 |
state.set(EYEX, _camera.getEye().x()); |
104 |
state.set(EYEY, _camera.getEye().y()); |
105 |
state.set(EYEZ, _camera.getEye().z()); |
106 |
state.set(CENTERX, _camera.getCenter().x()); |
107 |
state.set(CENTERY, _camera.getCenter().y()); |
108 |
state.set(CENTERZ, _camera.getCenter().z()); |
109 |
state.set(UPX, _camera.getUp().x()); |
110 |
state.set(UPY, _camera.getUp().y()); |
111 |
state.set(UPZ, _camera.getUp().z()); |
112 |
|
113 |
} |
114 |
|
115 |
public void loadFromState(PersistentState state) |
116 |
throws PersistenceException {
|
117 |
|
118 |
_camera = new Camera();
|
119 |
Vec3 eye = new Vec3(state.getDouble(EYEX), state.getDouble(EYEY),
|
120 |
state.getDouble(EYEZ)); |
121 |
Vec3 center = new Vec3(state.getDouble(CENTERX),
|
122 |
state.getDouble(CENTERY), state.getDouble(CENTERZ)); |
123 |
Vec3 up = new Vec3(state.getDouble(UPX), state.getDouble(UPY),
|
124 |
state.getDouble(UPZ)); |
125 |
|
126 |
_camera.setViewByLookAt(eye, center, up); |
127 |
|
128 |
} |
129 |
|
130 |
public static class RegisterPersistence implements Callable { |
131 |
|
132 |
public Object call() throws Exception { |
133 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
134 |
if (manager.getDefinition(PARAMETERS_DEFINITION_NAME) == null) { |
135 |
DynStruct definition = manager.addDefinition( |
136 |
ProjectCamera.class, PARAMETERS_DEFINITION_NAME, |
137 |
PARAMETERS_DEFINITION_NAME + " Persistence definition",
|
138 |
null, null); |
139 |
// Description
|
140 |
definition.addDynFieldDouble(EYEX).setMandatory(true);
|
141 |
definition.addDynFieldDouble(EYEY).setMandatory(true);
|
142 |
definition.addDynFieldDouble(EYEZ).setMandatory(true);
|
143 |
definition.addDynFieldDouble(CENTERX).setMandatory(true);
|
144 |
definition.addDynFieldDouble(CENTERY).setMandatory(true);
|
145 |
definition.addDynFieldDouble(CENTERZ).setMandatory(true);
|
146 |
definition.addDynFieldDouble(UPX).setMandatory(true);
|
147 |
definition.addDynFieldDouble(UPY).setMandatory(true);
|
148 |
definition.addDynFieldDouble(UPZ).setMandatory(true);
|
149 |
|
150 |
} |
151 |
return Boolean.TRUE; |
152 |
} |
153 |
|
154 |
} |
155 |
|
156 |
} |