Statistics
| Revision:

svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / ext3Dgui / src / com / iver / ai2 / gvsig3dgui / camera / ProjectCamera.java @ 15478

History | View | Annotate | Download (3.96 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.ai2.gvsig3dgui.camera;
42

    
43
import com.iver.utiles.IPersistence;
44
import com.iver.utiles.XMLEntity;
45

    
46
import es.upv.ai2.libjosg.Vec3;
47
import es.upv.ai2.libjosg.viewer.Camera;
48

    
49
/**
50
 * DOCUMENT ME!
51
 * 
52
 * @author 
53
 */
54
public class ProjectCamera implements IPersistence {
55
        // private Object camera;
56

    
57
        private Camera camera;
58

    
59
        private String description;
60

    
61
        /**
62
         * DOCUMENT ME!
63
         * 
64
         * @return
65
         */
66
        public String getDescription() {
67
                return description;
68
        }
69

    
70
        /**
71
         * DOCUMENT ME!
72
         * 
73
         * @param string
74
         */
75
        public void setDescription(String string) {
76
                description = string;
77
        }
78

    
79
        /**
80
         * @see java.lang.Object#toString()
81
         */
82
        public String toString() {
83
                return description;
84
        }
85

    
86
        public Camera getCamera() {
87
                return camera;
88
        }
89

    
90
        public void setCamera(Camera camera) {
91
                this.camera = camera;
92
        }
93

    
94
        public String getClassName() {
95
                return this.getClass().getName();
96
        }
97

    
98
        public XMLEntity getXMLEntity() {
99
                XMLEntity xml = new XMLEntity();
100
                xml.putProperty("className", this.getClassName());
101

    
102
                xml.putProperty("description", this.getDescription());
103
                // Saving camera propeties
104
                
105
                // Eye
106
                xml.putProperty("eyeX", this.camera.getEye().x());
107
                xml.putProperty("eyeY", this.camera.getEye().y());
108
                xml.putProperty("eyeZ", this.camera.getEye().z());
109
                // Center
110
                xml.putProperty("centerX", this.camera.getCenter().x());
111
                xml.putProperty("centerY", this.camera.getCenter().y());
112
                xml.putProperty("centerZ", this.camera.getCenter().z());
113
                // Up
114
                xml.putProperty("upX", this.camera.getUp().x());
115
                xml.putProperty("upY", this.camera.getUp().y());
116
                xml.putProperty("upZ", this.camera.getUp().z());
117

    
118
                return xml;
119
        }
120

    
121
        public void setXMLEntity(XMLEntity xml) {
122
                if (xml.contains("description"))
123
                        this.setDescription(xml.getStringProperty("description"));
124

    
125
                // Getting camera properties 
126
                camera = new Camera();
127
                
128
                // Variables auxiliares
129
                Vec3 center = new Vec3(),
130
                eye = new Vec3(),
131
                up = new Vec3();
132

    
133
                // Eye
134
                if (xml.contains("eyeX"))
135
                        eye.setX(xml.getDoubleProperty("eyeX"));
136
                if (xml.contains("eyeY"))
137
                        eye.setY(xml.getDoubleProperty("eyeY"));
138
                if (xml.contains("eyeZ"))
139
                        eye.setZ(xml.getDoubleProperty("eyeZ"));
140

    
141
                // Center
142
                if (xml.contains("centerX"))
143
                        center.setX(xml.getDoubleProperty("centerX"));
144
                if (xml.contains("centerY"))
145
                        center.setY(xml.getDoubleProperty("centerY"));
146
                if (xml.contains("centerZ"))
147
                        center.setZ(xml.getDoubleProperty("centerZ"));
148

    
149
                // Up
150
                if (xml.contains("upX"))
151
                        up.setX(xml.getDoubleProperty("upX"));
152
                if (xml.contains("upY"))
153
                        up.setY(xml.getDoubleProperty("upY"));
154
                if (xml.contains("upZ"))
155
                        up.setZ(xml.getDoubleProperty("upZ"));
156
                
157
                this.camera.setViewByLookAt(eye, center, up);
158

    
159
        }
160
}