Revision 318 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

View differences:

Viewport3DImpl.java
23 23

  
24 24
import java.awt.Color;
25 25
import java.awt.geom.Point2D;
26
import java.awt.geom.Rectangle2D;
27 26

  
28 27
import org.cresques.cts.IProjection;
29 28
import org.gvsig.fmap.geom.GeometryLocator;
30 29
import org.gvsig.fmap.geom.GeometryManager;
31
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
32
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
33
import org.gvsig.fmap.geom.primitive.Envelope;
34
import org.gvsig.fmap.mapcontext.ViewPort;
35 30
import org.gvsig.gvsig3d.map3d.ViewPort3D;
36 31
import org.gvsig.osgvp.core.osg.Matrix;
37 32
import org.gvsig.osgvp.core.osg.Vec3;
38 33
import org.gvsig.osgvp.terrain.Terrain;
39 34
import org.gvsig.osgvp.viewer.IViewerContainer;
35
import org.gvsig.osgvp.viewer.Intersections;
40 36

  
41

  
42 37
/**
43 38
 * @author gvSIG Team
44 39
 * @version $Id$
45
 *
40
 * 
46 41
 */
47 42
public class Viewport3DImpl extends ViewPort3D {
48
	
43

  
49 44
	private Terrain _terrain;
50
    private IViewerContainer _canvas3d;
51
    private boolean _dirty = false;
52
    
53
    private static final GeometryManager geomManager =
54
        GeometryLocator.getGeometryManager();
45
	private IViewerContainer _canvas3d;
46
	private boolean _dirty = false;
55 47

  
56
    public Viewport3DImpl(){
57
    	
58
    	super();
59
    }
60
    
48
	private static final GeometryManager geomManager = GeometryLocator
49
			.getGeometryManager();
50

  
51
	public Viewport3DImpl() {
52

  
53
		super();
54
	}
55

  
61 56
	public Viewport3DImpl(IProjection proj) {
62 57
		super(proj);
63 58
		setBackColor(Color.WHITE);
64 59
		// TODO Auto-generated constructor stub
65 60
	}
66
    
67
    public boolean getDirty() {
68
        return _dirty;
69
    }
70 61

  
71
    public Terrain getTerrain() {
72
        return _terrain;
73
    }
62
	public boolean getDirty() {
63
		return _dirty;
64
	}
74 65

  
75
    public void setDirty(boolean isDirty) {
76
        _dirty = isDirty;
66
	public Terrain getTerrain() {
67
		return _terrain;
68
	}
77 69

  
78
    }
70
	public void setDirty(boolean isDirty) {
71
		_dirty = isDirty;
79 72

  
80
    public void setEnvelope(Rectangle2D r) {
81
        extent = r;
73
	}
82 74

  
83
        _dirty = true;
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
	// }
84 83

  
85
    }
84
	public void setTerrain(Terrain terrain) {
85
		_terrain = terrain;
86 86

  
87
    public void setTerrain(Terrain terrain) {
88
        _terrain = terrain;
87
	}
89 88

  
90
    }
89
	public void setViewer(IViewerContainer canvas) {
90
		_canvas3d = canvas;
91 91

  
92
    public void setViewer(IViewerContainer canvas) {
93
        _canvas3d = canvas;
92
	}
94 93

  
95
    }
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
	
96 186

  
97 187
}

Also available in: Unified diff