svn-gvsig-desktop / import / ext3D / branches / ext3D_v1.1 / ext3D / src / com / iver / ai2 / gvsig3d / map3d / GraphicLayer3D.java @ 15441
History | View | Annotate | Download (3.37 KB)
1 |
package com.iver.ai2.gvsig3d.map3d; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
|
5 |
import com.iver.ai2.gvsig3d.gui.FeatureFactory; |
6 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
7 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
8 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
9 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
10 |
import com.iver.cit.gvsig.fmap.rendering.FGraphicLabel; |
11 |
|
12 |
import es.upv.ai2.libjosg.AutoTransform; |
13 |
import es.upv.ai2.libjosg.Group; |
14 |
import es.upv.ai2.libjosg.Node; |
15 |
import es.upv.ai2.libjosg.Vec3; |
16 |
import es.upv.ai2.libjosg.Vec4; |
17 |
import es.upv.ai2.libjosg.osgDB; |
18 |
import es.upv.ai2.libjosg.features.Text; |
19 |
import es.upv.ai2.libjosg.planets.Planet; |
20 |
import es.upv.ai2.libjosg.planets.PlanetViewer; |
21 |
|
22 |
public class GraphicLayer3D extends GraphicLayer { |
23 |
|
24 |
private Node especialNode;
|
25 |
|
26 |
private Planet planet;
|
27 |
|
28 |
private PlanetViewer planetViewer;
|
29 |
|
30 |
public GraphicLayer3D(PlanetViewer planetViewer, Planet planet) {
|
31 |
super();
|
32 |
this.planetViewer = planetViewer;
|
33 |
this.especialNode = planetViewer.getSpecialNode(0); |
34 |
this.planet = planet;
|
35 |
} |
36 |
|
37 |
public void clearAllGraphics() { |
38 |
// codigo de borrado de busquedas
|
39 |
Group grupo = (Group) planetViewer.getSpecialNode(0); |
40 |
|
41 |
while (grupo.getNumChildren()>0) { |
42 |
Node node = grupo.getChild(0);
|
43 |
grupo.removeChild(node); |
44 |
} |
45 |
} |
46 |
|
47 |
public void addGraphic(FGraphic g) { |
48 |
// a?adir la etiqueta aki
|
49 |
|
50 |
FGraphicLabel label = (FGraphicLabel) g; |
51 |
|
52 |
FLabel lab = label.getLabel(); |
53 |
Point2D p = lab.getOrig();
|
54 |
|
55 |
System.out.println("etiqueta ::: " + label.getLabel().getString()); |
56 |
|
57 |
// Variable declaration
|
58 |
Vec3 posI = null, posE = null, posT = null; |
59 |
Vec3 posIni = null, posEnd = null, posText = null, pos1 = null, pos2 = null; |
60 |
|
61 |
// search for Gazetteer
|
62 |
// There are two gazetteer modes SPHERICAL and PLANE mode
|
63 |
if (planet.getType() == Planet.PlanetType.SPHERICAL_MODE) {
|
64 |
// For spheriacl mode
|
65 |
|
66 |
// Geodesical coordinates
|
67 |
posI = new Vec3(p.getY(), p.getX(), 0); |
68 |
posE = new Vec3(p.getY(), p.getX(), 10000); |
69 |
posT = new Vec3(p.getY(), p.getX(), 50000); // Text position |
70 |
|
71 |
// To convert coordinate to cartesian
|
72 |
posIni = planet.convertLatLongHeightToXYZ(posI); |
73 |
posEnd = planet.convertLatLongHeightToXYZ(posE); |
74 |
|
75 |
posText = planet.convertLatLongHeightToXYZ(posT); |
76 |
|
77 |
} else if (planet.getType() == Planet.PlanetType.PLANE_MODE) { |
78 |
|
79 |
// For plane mode
|
80 |
posIni = new Vec3(p.getX(), p.getY(), 0); |
81 |
posText = new Vec3(p.getX(), p.getY(), 50000); // Text position |
82 |
} |
83 |
// To display text in gazetteer
|
84 |
Text text = (Text) FeatureFactory.insertTextoS( |
85 |
label.getLabel().getString(), posText, new Vec4(1.0, 0.0, 0.0, |
86 |
1.0), 30, true); |
87 |
|
88 |
Group grupo = (Group) planetViewer.getSpecialNode(0); |
89 |
String name = ResourcesFactory.getResourcePath("flag.ive"); |
90 |
Node flag = osgDB.readNodeFile(name); |
91 |
|
92 |
// Con autotransform
|
93 |
AutoTransform trans = new AutoTransform();
|
94 |
trans.addChild(flag); |
95 |
int scale = (int) ((20 / 4.5) * 1000); |
96 |
trans.setScale(new Vec3(scale, scale, scale));
|
97 |
trans.setPosition(posIni); |
98 |
trans.setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA); |
99 |
|
100 |
// Add nodes to graph
|
101 |
// grupo.setNodeName("gazetteer");
|
102 |
grupo.addChild(trans); |
103 |
grupo.addChild(text); |
104 |
|
105 |
} |
106 |
|
107 |
public Node getEspecialNode() {
|
108 |
return especialNode;
|
109 |
} |
110 |
|
111 |
public void setEspecialNode(Node especialNode) { |
112 |
this.especialNode = especialNode;
|
113 |
} |
114 |
|
115 |
} |