Revision 20900 trunk/extensions/ext3Dgui/src/com/iver/ai2/gvsig3dgui/ProjectView3D.java
ProjectView3D.java | ||
---|---|---|
9 | 9 |
import java.util.Map.Entry; |
10 | 10 |
import java.util.prefs.Preferences; |
11 | 11 |
|
12 |
import org.apache.log4j.Logger; |
|
12 | 13 |
import org.gvsig.cacheservice.CacheService; |
14 |
import org.gvsig.osgvp.Vec3; |
|
15 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
|
16 |
import org.gvsig.osgvp.planets.Planet; |
|
17 |
import org.gvsig.osgvp.planets.PlanetViewer; |
|
18 |
import org.gvsig.osgvp.viewer.Camera; |
|
19 |
import org.gvsig.osgvp.viewer.CanvasViewer; |
|
20 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
|
21 |
import org.gvsig.osgvp.viewer.ViewerFactory; |
|
22 |
import org.gvsig.osgvp.viewer.ViewerStateListener; |
|
13 | 23 |
|
14 | 24 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
15 | 25 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
16 | 26 |
import com.iver.ai2.gvsig3d.camera.ProjectCamera; |
17 | 27 |
import com.iver.ai2.gvsig3d.gui.FeatureFactory; |
18 | 28 |
import com.iver.ai2.gvsig3d.gui.Hud; |
29 |
import com.iver.ai2.gvsig3d.map3d.GraphicLayer3D; |
|
19 | 30 |
import com.iver.ai2.gvsig3d.map3d.MapContext3D; |
20 | 31 |
import com.iver.ai2.gvsig3d.map3d.layers.FLayers3D; |
21 | 32 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
... | ... | |
43 | 54 |
import com.iver.utiles.StringUtilities; |
44 | 55 |
import com.iver.utiles.XMLEntity; |
45 | 56 |
|
46 |
import es.upv.ai2.osgvp.Vec3; |
|
47 |
import es.upv.ai2.osgvp.planets.Planet; |
|
48 |
import es.upv.ai2.osgvp.planets.PlanetViewer; |
|
49 |
import es.upv.ai2.osgvp.viewer.Camera; |
|
50 |
import es.upv.ai2.osgvp.viewer.CanvasViewer; |
|
51 |
import es.upv.ai2.osgvp.viewer.IViewerContainer; |
|
52 |
import es.upv.ai2.osgvp.viewer.ViewerFactory; |
|
53 |
import es.upv.ai2.osgvp.viewer.ViewerStateListener; |
|
54 |
|
|
55 | 57 |
/** |
56 | 58 |
* Clase que representa una vista del proyecto |
57 | 59 |
* |
... | ... | |
68 | 70 |
|
69 | 71 |
private ProjectCamera projectCamera = null; |
70 | 72 |
|
71 |
private int m_planetType = Planet.CoordinateSystemType.GEOCENTRIC; // spheric or plane |
|
73 |
private int m_planetType = Planet.CoordinateSystemType.GEOCENTRIC; // spheric |
|
74 |
// or |
|
75 |
// plane |
|
72 | 76 |
|
73 | 77 |
private Color backgroundColor; |
74 | 78 |
|
... | ... | |
77 | 81 |
private FeatureFactory g; |
78 | 82 |
|
79 | 83 |
private View3D m_view = null; |
80 |
|
|
81 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.configuration.3D" ); |
|
82 |
|
|
84 |
|
|
85 |
private static Preferences prefs = Preferences.userRoot().node( |
|
86 |
"gvsig.configuration.3D"); |
|
87 |
|
|
83 | 88 |
private boolean prespectiveMode = true; |
84 | 89 |
|
90 |
private static Logger logger = Logger.getLogger(ProjectView3D.class |
|
91 |
.getName()); |
|
92 |
|
|
85 | 93 |
// private Satelite runnable; |
86 | 94 |
|
87 | 95 |
public ProjectView3D() { |
... | ... | |
263 | 271 |
// create libJOSG objects |
264 | 272 |
if (m_canvas3d == null) { |
265 | 273 |
// AI2 objects |
266 |
m_planetViewer = new PlanetViewer(); |
|
267 |
|
|
274 |
try { |
|
275 |
m_planetViewer = new PlanetViewer(); |
|
276 |
} catch (NodeException e1) { |
|
277 |
logger.error("Command: " + "Error creating planer viewer.", e1); |
|
278 |
} |
|
279 |
|
|
268 | 280 |
// Getting 3D preferences |
269 | 281 |
boolean compatibilitySwing = false; |
270 |
compatibilitySwing = prefs.getBoolean("compatibilitySwing", compatibilitySwing); |
|
271 |
|
|
272 |
if (compatibilitySwing){ |
|
273 |
m_canvas3d = ViewerFactory.getInstance().createViewer( |
|
274 |
ViewerFactory.VIEWER_TYPE.JPANEL_VIEWER, m_planetViewer); |
|
275 |
}else{ |
|
276 |
m_canvas3d = ViewerFactory.getInstance().createViewer( |
|
277 |
ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, m_planetViewer); |
|
282 |
compatibilitySwing = prefs.getBoolean("compatibilitySwing", |
|
283 |
compatibilitySwing); |
|
284 |
|
|
285 |
if (compatibilitySwing) { |
|
286 |
m_canvas3d = ViewerFactory.getInstance() |
|
287 |
.createViewer(ViewerFactory.VIEWER_TYPE.JPANEL_VIEWER, |
|
288 |
m_planetViewer); |
|
289 |
} else { |
|
290 |
m_canvas3d = ViewerFactory.getInstance() |
|
291 |
.createViewer(ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, |
|
292 |
m_planetViewer); |
|
278 | 293 |
} |
279 |
|
|
294 |
|
|
280 | 295 |
this.configureProjectionViewMode(); |
281 |
// m_canvas3d = ViewerFactory.getInstance().createViewer( |
|
282 |
// ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, m_planetViewer); |
|
283 |
m_canvas3d.addKeyListener(new ViewerStateListener(m_canvas3d.getOSGViewer())); |
|
296 |
// m_canvas3d = ViewerFactory.getInstance().createViewer( |
|
297 |
// ViewerFactory.VIEWER_TYPE.CANVAS_VIEWER, m_planetViewer); |
|
298 |
m_canvas3d.addKeyListener(new ViewerStateListener(m_canvas3d |
|
299 |
.getOSGViewer())); |
|
284 | 300 |
|
285 | 301 |
// ViewerFactory.getInstance().startAnimator(); |
286 | 302 |
|
... | ... | |
308 | 324 |
m_planet.setExtent(extent); |
309 | 325 |
} |
310 | 326 |
|
311 |
// canvasListener lis = new canvasListener();
|
|
312 |
// lis.setCanvas(m_canvas3d);
|
|
313 |
// m_canvas3d.addKeyListener(lis);
|
|
327 |
// canvasListener lis = new canvasListener();
|
|
328 |
// lis.setCanvas(m_canvas3d);
|
|
329 |
// m_canvas3d.addKeyListener(lis);
|
|
314 | 330 |
/* |
315 | 331 |
* CODIGO DE PRUEBA PARA LA INCLUSION DE TEXTOS, POLIGONOS, LINEAS, |
316 | 332 |
* ETC... |
... | ... | |
359 | 375 |
// root.addChild(rot2); |
360 | 376 |
/* ************************************************************************* */ |
361 | 377 |
|
362 |
// m_planetViewer.addSpecialNode(g); |
|
363 |
// List posi = new ArrayList(); |
|
364 |
// for (int i = 0; i < 10; i++) { |
|
365 |
// Vec3 pos1 = m_planet.convertLatLongHeightToXYZ(new Vec3(0, Math |
|
366 |
// .toRadians(i * 10), 0)); |
|
367 |
// |
|
368 |
// // Vec3 pos1 = new Vec3(0, i * 10, 0); |
|
369 |
// posi.add(pos1); |
|
370 |
// } |
|
371 |
// Vec4 rgba = new Vec4(1.0, 1.0, 1.0, 1.0); |
|
372 |
// float lineWidth = 8; |
|
373 |
// g.addChild(FeatureFactory.insertLine(posi, rgba, lineWidth)); |
|
374 |
|
|
378 |
// m_planetViewer.addSpecialNode(g); |
|
379 |
// List posi = new ArrayList(); |
|
380 |
// for (int i = 0; i < 10; i++) { |
|
381 |
// Vec3 pos1 = m_planet.convertLatLongHeightToXYZ(new Vec3(0, Math |
|
382 |
// .toRadians(i * 10), 0)); |
|
383 |
// |
|
384 |
// // Vec3 pos1 = new Vec3(0, i * 10, 0); |
|
385 |
// posi.add(pos1); |
|
386 |
// } |
|
387 |
// Vec4 rgba = new Vec4(1.0, 1.0, 1.0, 1.0); |
|
388 |
// float lineWidth = 8; |
|
389 |
// g.addChild(FeatureFactory.insertLine(posi, rgba, lineWidth)); |
|
375 | 390 |
// m_planetViewer.addSpecialNode(FeatureFactory.insertLine(posi, |
376 | 391 |
// rgba, |
377 | 392 |
// lineWidth)); |
378 |
|
|
379 | 393 |
// m_planetViewer.addSpecialNode(osgDB.readNodeFile(ResourcesFactory |
380 | 394 |
// .getResourcesPath() |
381 | 395 |
// + "../images/flag.ive")); |
382 | 396 |
// m_canvas3d.getOSGViewer().addSpecialNode(root); |
383 | 397 |
// Cargando el satelite |
384 | 398 |
// m_canvas3d.addSpecialNode(sat); |
385 |
|
|
386 |
m_planetViewer.addPlanet(m_planet); |
|
399 |
try { |
|
400 |
m_planetViewer.addPlanet(m_planet); |
|
401 |
} catch (NodeException e1) { |
|
402 |
logger.error("Command: " + "Error adding new child node.", e1); |
|
403 |
} |
|
387 | 404 |
|
388 | 405 |
Camera cam; |
389 | 406 |
cam = new Camera(); |
... | ... | |
408 | 425 |
.setMinCameraDistance(10); |
409 | 426 |
m_planetViewer.getCustomTerrainManipulator() |
410 | 427 |
.setMaxCameraDistance(5000000 * 10); |
411 |
// m_planet.setSubdivisionFactor((float) 0.45);
|
|
428 |
// m_planet.setSubdivisionFactor((float) 0.45);
|
|
412 | 429 |
} else { |
413 |
// cam.setViewByLookAt(m_planet.getRadiusEquatorial() * 3.0,
|
|
414 |
// 0, 0, 0, 0, 0, 0, 0, 1);
|
|
430 |
// cam.setViewByLookAt(m_planet.getRadiusEquatorial() * 3.0,
|
|
431 |
// 0, 0, 0, 0, 0, 0, 0, 1);
|
|
415 | 432 |
cam.setViewByLookAt(m_planet.getRadiusEquatorial() * 8.0, |
416 | 433 |
0, 0, 0, 0, 0, 0, 0, 1); |
417 | 434 |
m_planetViewer.getCustomTerrainManipulator() |
418 | 435 |
.setMinCameraDistance(100); |
419 |
// m_planetViewer.getCustomTerrainManipulator()
|
|
420 |
// .setMaxCameraDistance(
|
|
421 |
// m_planet.getRadiusEquatorial() * 3.0);
|
|
436 |
// m_planetViewer.getCustomTerrainManipulator()
|
|
437 |
// .setMaxCameraDistance(
|
|
438 |
// m_planet.getRadiusEquatorial() * 3.0);
|
|
422 | 439 |
m_planetViewer.getCustomTerrainManipulator() |
423 |
.setMaxCameraDistance( |
|
424 |
m_planet.getRadiusEquatorial() * 10.0); |
|
440 |
.setMaxCameraDistance(
|
|
441 |
m_planet.getRadiusEquatorial() * 10.0);
|
|
425 | 442 |
// cam.setViewByLookAt(100 * 2.0, |
426 | 443 |
// 0, 0, 0, 0, 0, 0, 0, 1); |
427 | 444 |
// m_planet.setSubdivisionFactor((float) 0.65); |
... | ... | |
434 | 451 |
// m_canvas3d.getOSGViewer().setCameraManipulator(new |
435 | 452 |
// TrackballManipulator()); |
436 | 453 |
|
437 |
m_planetViewer.setCamera(cam);
|
|
454 |
m_planetViewer.setCamera(cam); |
|
438 | 455 |
|
439 | 456 |
Hud hud = new Hud(m_canvas3d, m_planet); |
440 |
m_planetViewer.addNodeToHUD(hud); |
|
457 |
try { |
|
458 |
m_planetViewer.addNodeToHUD(hud); |
|
459 |
} catch (NodeException e) { |
|
460 |
logger.error("Command: " + "Error adding node to hud.", e); |
|
461 |
} |
|
441 | 462 |
|
442 | 463 |
m_planetViewer.setEnabledLighting(true); |
443 | 464 |
} |
... | ... | |
689 | 710 |
return prespectiveMode; |
690 | 711 |
} |
691 | 712 |
|
692 |
|
|
693 | 713 |
/** |
694 |
* Active the prespective mode. If we disable the prespective mode, the ortho mode will be active |
|
714 |
* Active the prespective mode. If we disable the prespective mode, the |
|
715 |
* ortho mode will be active |
|
695 | 716 |
* |
696 |
* @param prespectiveMode enable/disable |
|
717 |
* @param prespectiveMode |
|
718 |
* enable/disable |
|
697 | 719 |
*/ |
698 | 720 |
public void setActivePrespectiveMode(boolean prespectiveMode) { |
699 | 721 |
this.prespectiveMode = prespectiveMode; |
700 | 722 |
} |
701 |
|
|
702 |
private void configureProjectionViewMode(){ |
|
703 |
if (prespectiveMode){ |
|
723 |
|
|
724 |
private void configureProjectionViewMode() {
|
|
725 |
if (prespectiveMode) {
|
|
704 | 726 |
System.out.println("Setting up prespective projection"); |
705 |
// this.m_canvas3d.getOSGViewer().setProjectionMatrixAsPerspective( |
|
706 |
// arg0, arg1, arg2, arg3); |
|
707 |
} |
|
708 |
else { |
|
727 |
// this.m_canvas3d.getOSGViewer().setProjectionMatrixAsPerspective( |
|
728 |
// arg0, arg1, arg2, arg3); |
|
729 |
} else { |
|
709 | 730 |
System.out.println("Setting up prespective projection"); |
710 |
this.m_canvas3d.getOSGViewer().setProjectionMatrixAsOrtho(-10, 10, -10, 10, 1, 1000); |
|
731 |
this.m_canvas3d.getOSGViewer().setProjectionMatrixAsOrtho(-10, 10, |
|
732 |
-10, 10, 1, 1000); |
|
711 | 733 |
} |
712 | 734 |
} |
713 |
|
|
714 | 735 |
|
715 | 736 |
} |
Also available in: Unified diff