gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / map3d / Viewport3DImpl.java @ 318
History | View | Annotate | Download (4.9 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.gvsig3d.impl.map3d; |
23 |
|
24 |
import java.awt.Color; |
25 |
import java.awt.geom.Point2D; |
26 |
|
27 |
import org.cresques.cts.IProjection; |
28 |
import org.gvsig.fmap.geom.GeometryLocator; |
29 |
import org.gvsig.fmap.geom.GeometryManager; |
30 |
import org.gvsig.gvsig3d.map3d.ViewPort3D; |
31 |
import org.gvsig.osgvp.core.osg.Matrix; |
32 |
import org.gvsig.osgvp.core.osg.Vec3; |
33 |
import org.gvsig.osgvp.terrain.Terrain; |
34 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
35 |
import org.gvsig.osgvp.viewer.Intersections; |
36 |
|
37 |
/**
|
38 |
* @author gvSIG Team
|
39 |
* @version $Id$
|
40 |
*
|
41 |
*/
|
42 |
public class Viewport3DImpl extends ViewPort3D { |
43 |
|
44 |
private Terrain _terrain;
|
45 |
private IViewerContainer _canvas3d;
|
46 |
private boolean _dirty = false; |
47 |
|
48 |
private static final GeometryManager geomManager = GeometryLocator |
49 |
.getGeometryManager(); |
50 |
|
51 |
public Viewport3DImpl() {
|
52 |
|
53 |
super();
|
54 |
} |
55 |
|
56 |
public Viewport3DImpl(IProjection proj) {
|
57 |
super(proj);
|
58 |
setBackColor(Color.WHITE);
|
59 |
// TODO Auto-generated constructor stub
|
60 |
} |
61 |
|
62 |
public boolean getDirty() { |
63 |
return _dirty;
|
64 |
} |
65 |
|
66 |
public Terrain getTerrain() {
|
67 |
return _terrain;
|
68 |
} |
69 |
|
70 |
public void setDirty(boolean isDirty) { |
71 |
_dirty = isDirty; |
72 |
|
73 |
} |
74 |
|
75 |
// public void setEnvelope(Envelope e) {
|
76 |
// super.setEnvelope(e);
|
77 |
// _canvas3d.getOSGViewer().setViewport((int)e.getMinimum(0),
|
78 |
// (int)e.getMinimum(1),
|
79 |
// (int)e.getMaximum(0) - (int)e.getMinimum(0),
|
80 |
// (int)e.getMaximum(1) - (int)e.getMinimum(1));
|
81 |
//
|
82 |
// }
|
83 |
|
84 |
public void setTerrain(Terrain terrain) { |
85 |
_terrain = terrain; |
86 |
|
87 |
} |
88 |
|
89 |
public void setViewer(IViewerContainer canvas) { |
90 |
_canvas3d = canvas; |
91 |
|
92 |
} |
93 |
|
94 |
// @Override
|
95 |
// public Point2D fromMapPoint(double x, double y) {
|
96 |
//
|
97 |
// Matrix viewM = _canvas3d.getOSGViewer().getCamera().getViewMatrix();
|
98 |
// Matrix projM = _canvas3d.getOSGViewer().getCamera()
|
99 |
// .getProjectionMatrix();
|
100 |
//
|
101 |
// Vec3 geoPt;
|
102 |
//
|
103 |
// if (getProjection().getAbrev().compareToIgnoreCase("EPSG:4326") == 0) {
|
104 |
// geoPt = _terrain.convertLatLongHeightToXYZ(new Vec3(x, y, 0.0));
|
105 |
//
|
106 |
// } else {
|
107 |
// geoPt = new Vec3(x, y, 0);
|
108 |
// }
|
109 |
//
|
110 |
// Matrix finalM = viewM.prod(projM);
|
111 |
//
|
112 |
// Vec3 projP = finalM.prod(geoPt, finalM);
|
113 |
//
|
114 |
// Vec3 windowP = new Vec3();
|
115 |
// windowP.setX((projP.x() + 1) * (_canvas3d.getWidth() * 0.5));
|
116 |
// windowP.setY((projP.y() + 1) * (_canvas3d.getHeight() * 0.5));
|
117 |
//
|
118 |
// System.out.println(windowP.x() + " " + windowP.y());
|
119 |
//
|
120 |
// return new Point2D.Double(windowP.x(), windowP.y());
|
121 |
// }
|
122 |
//
|
123 |
// @Override
|
124 |
// public Point2D toMapPoint(Point2D pScreen) {
|
125 |
//
|
126 |
// // System.err.println("Coordenadas de pantalla " + pScreen.getX() + ","+
|
127 |
// // pScreen.getY());
|
128 |
// Intersections hits = _canvas3d.getOSGViewer().rayPick(
|
129 |
// (int) pScreen.getX(), (int) pScreen.getY());
|
130 |
// Point2D pWorld = new Point2D.Double();
|
131 |
// if (hits.containsIntersections()) {
|
132 |
// // get XYZ coordinates on terrain
|
133 |
// Vec3 hit = hits.getFirstIntersection().getIntersectionPoint();
|
134 |
// // convert to geo coordinates
|
135 |
// if (getProjection().getAbrev().compareToIgnoreCase("EPSG:4326") == 0) {
|
136 |
// Vec3 geoPt = _terrain.convertXYZToLatLongHeight(hit);
|
137 |
//
|
138 |
// // if (Math.abs(heigth - geoPt.z()) <= 1000) {
|
139 |
// pWorld.setLocation(geoPt.y(), geoPt.x());
|
140 |
// // } else {
|
141 |
// // pWorld.setLocation(360, 120);
|
142 |
// // }
|
143 |
//
|
144 |
// } else {
|
145 |
// // if (Math.abs(heigth - hit.z()) <= 100) {
|
146 |
// pWorld.setLocation(hit.x(), hit.y());
|
147 |
// // } else {
|
148 |
// // pWorld.setLocation(360, 120);
|
149 |
// // }
|
150 |
//
|
151 |
// }
|
152 |
// } else {
|
153 |
// if (getProjection().getAbrev().compareToIgnoreCase("EPSG:4326") == 0) {
|
154 |
// pWorld.setLocation(360, 120);
|
155 |
// } else
|
156 |
// pWorld.setLocation(1e100, 1e100);
|
157 |
// }
|
158 |
//
|
159 |
// return pWorld;
|
160 |
// }
|
161 |
//
|
162 |
// public Point2D toMapPoint(int x, int y)
|
163 |
// {
|
164 |
// return toMapPoint(new Point2D.Double(x,y));
|
165 |
// }
|
166 |
//
|
167 |
// /**
|
168 |
// * Returns geographic distance from pixel distance
|
169 |
// * @param d distance in pixels
|
170 |
// *
|
171 |
// * @return distance equivalent in <i>map coordinates</i>
|
172 |
// */
|
173 |
// public double toMapDistance(int d) {
|
174 |
// Point2D p1 = toMapPoint(0, 0);
|
175 |
// Point2D p2 = toMapPoint(1, 0);
|
176 |
//
|
177 |
// double scaleX = p2.distance(p1) ;
|
178 |
//
|
179 |
// double dist = d * scaleX;
|
180 |
//
|
181 |
// if(dist <= 0) dist = 0.1;
|
182 |
//
|
183 |
// return dist;
|
184 |
// }
|
185 |
|
186 |
|
187 |
} |