Revision 15236
import/ext3D/trunk/ext3D/src/com/iver/ai2/gvsig3d/utils/UtilCoord.java | ||
---|---|---|
1 | 1 |
package com.iver.ai2.gvsig3d.utils; |
2 | 2 |
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
|
|
3 | 5 |
import es.upv.ai2.libjosg.Vec3; |
6 |
import es.upv.ai2.libjosg.planets.Planet; |
|
4 | 7 |
import es.upv.ai2.libjosg.viewer.Camera; |
5 | 8 |
|
6 | 9 |
public class UtilCoord { |
... | ... | |
129 | 132 |
System.out.println("UP : X " + u.x() + " Y " + u.y() + "Z " + u.z()); |
130 | 133 |
System.out.println("*************************************************"); |
131 | 134 |
} |
135 |
|
|
136 |
public static Rectangle2D getExtendGeo(double longi, double lati, double size,double radius){ |
|
132 | 137 |
|
138 |
double with = size / radius; |
|
139 |
double heigth = size / ( radius * Math.cos(lati)); |
|
140 |
Rectangle2D extend = new Rectangle2D.Double(longi,lati,with,heigth); |
|
141 |
|
|
142 |
return extend; |
|
143 |
} |
|
144 |
|
|
133 | 145 |
} |
import/ext3D/trunk/ext3D/src/com/iver/ai2/gvsig3d/map3d/MapContext3D.java | ||
---|---|---|
6 | 6 |
import com.iver.cit.gvsig.fmap.MapContext; |
7 | 7 |
import com.iver.cit.gvsig.fmap.ViewPort; |
8 | 8 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
9 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
|
9 | 10 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
10 | 11 |
import com.iver.utiles.XMLEntity; |
11 | 12 |
|
... | ... | |
63 | 64 |
|
64 | 65 |
return fmap; |
65 | 66 |
} |
67 |
|
|
68 |
public GraphicLayer getGraphicsLayer() { |
|
69 |
FLayers3D f = (FLayers3D)layers; |
|
70 |
GraphicLayer3D gra3D = new GraphicLayer3D(f.getCanvas3d(),f.getPlanet()); |
|
71 |
return gra3D; |
|
72 |
} |
|
73 |
|
|
66 | 74 |
|
67 | 75 |
} |
import/ext3D/trunk/ext3D/src/com/iver/ai2/gvsig3d/map3d/layers/FLayers3D.java | ||
---|---|---|
142 | 142 |
} |
143 | 143 |
} |
144 | 144 |
|
145 |
public Planet getPlanet() { |
|
146 |
return m_planet; |
|
147 |
} |
|
148 |
|
|
145 | 149 |
public void setViewer(IViewerContainer canvas) { |
146 | 150 |
m_canvas3d = canvas; |
147 | 151 |
} |
... | ... | |
631 | 635 |
double maxLat = geoExtent.getMaxY(); |
632 | 636 |
double cenLon = geoExtent.getCenterX(); |
633 | 637 |
double cenLat = geoExtent.getCenterY(); |
634 |
// Disable gazetteer |
|
635 |
boolean gazetteer = false; |
|
636 | 638 |
|
637 |
// search for Gazetteer |
|
638 |
if ((geoExtent.getHeight() == 0) && (geoExtent.getWidth() == 0)) { |
|
639 |
cenLon = geoExtent.getX(); |
|
640 |
cenLat = geoExtent.getY(); |
|
641 |
gazetteer = true; |
|
642 |
// TODO: Insercion de un simbolo para situar al objeto buscado en |
|
643 |
// Nomenglator |
|
644 |
|
|
645 |
// Variable declaration |
|
646 |
Vec3 posI = null, posE = null, posT = null, pos1aux = null, pos2aux = null; |
|
647 |
Vec3 posIni = null, posEnd = null, posText = null, pos1 = null, pos2 = null; |
|
648 |
|
|
649 |
// There are two gazetteer modes SPHERICAL and PLANE mode |
|
650 |
if (m_planet.getType() == Planet.PlanetType.SPHERICAL_MODE) { |
|
651 |
// For spheriacl mode |
|
652 |
|
|
653 |
// Geodesical coordinates |
|
654 |
posI = new Vec3(cenLat, cenLon, 0); |
|
655 |
posE = new Vec3(cenLat, cenLon, 10000); |
|
656 |
posT = new Vec3(cenLat, cenLon, 11500); // Text position |
|
657 |
|
|
658 |
pos1aux = new Vec3(cenLat, cenLon + 0.05, 7500); |
|
659 |
pos2aux = new Vec3(cenLat, cenLon, 6000); |
|
660 |
|
|
661 |
// To convert coordinate to cartesian |
|
662 |
posIni = m_planet.convertLatLongHeightToXYZ(posI); |
|
663 |
posEnd = m_planet.convertLatLongHeightToXYZ(posE); |
|
664 |
pos1 = m_planet.convertLatLongHeightToXYZ(pos1aux); |
|
665 |
pos2 = m_planet.convertLatLongHeightToXYZ(pos2aux); |
|
666 |
|
|
667 |
posText = m_planet.convertLatLongHeightToXYZ(posT); |
|
668 |
|
|
669 |
} else if (m_planet.getType() == Planet.PlanetType.PLANE_MODE) { |
|
670 |
|
|
671 |
// For plane mode |
|
672 |
posIni = new Vec3(cenLon, cenLat, 0); |
|
673 |
posEnd = new Vec3(cenLon, cenLat, 50000); |
|
674 |
posText = new Vec3(cenLon, cenLat, 60000); |
|
675 |
|
|
676 |
// System.out.println("posicion del zoom plano, longitud: " |
|
677 |
// + cenLon + "latitud: " + cenLat); |
|
678 |
} |
|
679 |
// To display text in gazetteer |
|
680 |
// Text text = (Text) VectorTest.insertTextoS("Gazetteer", posText, |
|
681 |
// new Vec4(1.0, 1.0, 1.0, 1.0), 30, true); |
|
682 |
|
|
683 |
Group grupo = (Group) this.m_canvas3d.getOSGViewer() |
|
684 |
.getSpecialNode(0); |
|
685 |
String name = ResourcesFactory.getResourcePath("flag.ive"); |
|
686 |
Node flag = this.m_canvas3d.getOSGViewer().readNodeFile(name); |
|
687 |
|
|
688 |
// Con autotransform |
|
689 |
AutoTransform trans = new AutoTransform(); |
|
690 |
trans.addChild(flag); |
|
691 |
int scale = (int) ((20 / 4.5) * 1000); |
|
692 |
trans.setScale(new Vec3(scale, scale, scale)); |
|
693 |
trans.setPosition(posIni); |
|
694 |
trans |
|
695 |
.setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA); |
|
696 |
|
|
697 |
// CODIGO QUE PONE LA BANDERA EN UN PUNTO FIJO PERPENDICULAR A LA |
|
698 |
// SUPERFICIE |
|
699 |
// float cenLatRad = (float) (((90 - cenLat) * Math.PI) / 180.0f); |
|
700 |
// float cenLonRad = (float) ((cenLon * Math.PI) / 180.0f); |
|
701 |
|
|
702 |
// PositionAttitudeTransform trans = new |
|
703 |
// PositionAttitudeTransform(); |
|
704 |
// PositionAttitudeTransform rot1 = new PositionAttitudeTransform(); |
|
705 |
// PositionAttitudeTransform rot2 = new PositionAttitudeTransform(); |
|
706 |
// // cargando la bandera |
|
707 |
// trans.setPosition(posIni); |
|
708 |
// trans.setScale(new Vec3(600, 600, 600)); |
|
709 |
// |
|
710 |
// rot1.setAttitude(cenLonRad, new Vec3(0.0, 1.0, 0.0)); |
|
711 |
// |
|
712 |
// rot2.addChild(flag); |
|
713 |
// rot2.setAttitude(cenLatRad, new Vec3(0.0, 1.0, 0.0)); |
|
714 |
// |
|
715 |
// |
|
716 |
// rot1.addChild(rot2); |
|
717 |
// trans.addChild(rot1); |
|
718 |
// |
|
719 |
// // Sirver para optimizar la estructura del arbol |
|
720 |
// Optimizer opt = new Optimizer(); |
|
721 |
// opt.optimize(trans); |
|
722 |
|
|
723 |
/* *********************************************************** */ |
|
724 |
|
|
725 |
grupo.addChild(trans); |
|
726 |
} |
|
727 | 639 |
double elevation = 0; |
728 |
if (gazetteer) { |
|
729 |
elevation = 101000; |
|
730 |
} else { |
|
731 | 640 |
|
732 |
// calculate altitude
|
|
733 |
double avLat = 0;
|
|
734 |
if (minLat > 0.0 || maxLat < 0.0)
|
|
735 |
avLat = Math.min(Math.abs(minLat), Math.abs(maxLat));
|
|
736 |
double avLon = Math.min(180.0, geoExtent.getWidth());
|
|
641 |
// calculate altitude |
|
642 |
double avLat = 0; |
|
643 |
if (minLat > 0.0 || maxLat < 0.0) |
|
644 |
avLat = Math.min(Math.abs(minLat), Math.abs(maxLat)); |
|
645 |
double avLon = Math.min(180.0, geoExtent.getWidth()); |
|
737 | 646 |
|
738 |
double planetRadius = m_planet.getRadiusEquatorial();
|
|
739 |
double radiusLat = planetRadius * Math.cos(Math.toRadians(avLat));
|
|
740 |
double deltaLon = Math.sqrt(2 * radiusLat * radiusLat
|
|
741 |
* (1 - Math.cos(Math.toRadians(avLon))));
|
|
742 |
double deltaLat = Math.sqrt(2 * planetRadius * planetRadius
|
|
743 |
* (1 - Math.cos(Math.toRadians(geoExtent.getHeight()))));
|
|
647 |
double planetRadius = m_planet.getRadiusEquatorial(); |
|
648 |
double radiusLat = planetRadius * Math.cos(Math.toRadians(avLat)); |
|
649 |
double deltaLon = Math.sqrt(2 * radiusLat * radiusLat |
|
650 |
* (1 - Math.cos(Math.toRadians(avLon)))); |
|
651 |
double deltaLat = Math.sqrt(2 * planetRadius * planetRadius |
|
652 |
* (1 - Math.cos(Math.toRadians(geoExtent.getHeight())))); |
|
744 | 653 |
|
745 |
double zoomFactor = 1.0; |
|
746 |
elevation = (Math.max(deltaLon, deltaLat) * zoomFactor) + maxHeight; |
|
747 |
} |
|
654 |
double zoomFactor = 1.0; |
|
655 |
elevation = (Math.max(deltaLon, deltaLat) * zoomFactor) + maxHeight; |
|
748 | 656 |
|
749 | 657 |
// Calculate XYZ positions for camera. |
750 | 658 |
|
... | ... | |
758 | 666 |
|
759 | 667 |
double difx = (geoExtent.getMaxX() - geoExtent.getX()) / 1.2d; |
760 | 668 |
double dify = (geoExtent.getMaxY() - geoExtent.getY()) / 1.2d; |
761 |
double posx = geoExtent.getX() + difx; |
|
762 |
double posy = geoExtent.getY() + dify; |
|
763 |
|
|
764 |
double difMayor = difx; |
|
765 |
|
|
766 |
if (difx < dify) |
|
767 |
difMayor = dify; |
|
768 | 669 |
double height; |
769 | 670 |
|
770 |
if (gazetteer) |
|
771 |
height = elevation; |
|
772 |
else |
|
773 |
height = Math.sqrt(difx * difx + dify * dify); |
|
774 |
// height = Math.sqrt(difx * difx + dify * dify); |
|
671 |
height = Math.sqrt(difx * difx + dify * dify); |
|
775 | 672 |
|
776 |
// TESTING FOR PLANE MODE |
|
777 |
|
|
778 | 673 |
// EYE |
779 | 674 |
eye.setX(cenLon); |
780 | 675 |
eye.setY(cenLat); |
... | ... | |
792 | 687 |
// Calculate positions for SPHERICAL MODE. |
793 | 688 |
if (planetType == PlanetType.SPHERICAL_MODE) { |
794 | 689 |
// EYE |
795 |
// eye = UtilCoord.GeoToCarte((planetRadius + elevation), cenLon, |
|
796 |
// cenLat); |
|
797 | 690 |
Vec3 aux = new Vec3(cenLat, cenLon, elevation); |
798 | 691 |
eye = m_planet.convertLatLongHeightToXYZ(aux); |
799 |
// Vec3 aux1 = new Vec3((planetRadius + elevation), cenLon, cenLat); |
|
800 |
// eye = UtilCoord.GeoToCarte(aux1); |
|
801 | 692 |
// CENTER |
802 | 693 |
center.setX(0.0); |
803 | 694 |
center.setY(0.0); |
... | ... | |
816 | 707 |
// REPAINTING VIEWER |
817 | 708 |
if (m_canvas3d != null) |
818 | 709 |
m_canvas3d.repaint(); |
819 |
|
|
820 | 710 |
} |
821 | 711 |
|
822 | 712 |
public void tileCreated(TileEvent evt) { |
... | ... | |
857 | 747 |
if (dataType == Layer3DProps.layer3DImage) { |
858 | 748 |
// float opacity = 1.0f; |
859 | 749 |
String fileExtension = "png"; |
860 |
m_planet.setTexture(evt.getTilePagedLod(), tileFileName, textureStage); |
|
861 |
m_planet.setTextureOpacityLayer(textureStage, props3D.getOpacity()); |
|
750 |
m_planet.setTexture(evt.getTilePagedLod(), |
|
751 |
tileFileName, textureStage); |
|
752 |
m_planet.setTextureOpacityLayer(textureStage, props3D |
|
753 |
.getOpacity()); |
|
862 | 754 |
textureStage++; |
863 | 755 |
} else if (dataType == Layer3DProps.layer3DElevation) { |
864 | 756 |
String fileExtension = "tif"; |
865 |
m_planet.setHeightfield(evt.getTilePagedLod(), tileFileName, MDTStage); |
|
866 |
m_planet.setVerticalExaggerationLayer(MDTStage, props3D.getVerticalEx()); |
|
757 |
m_planet.setHeightfield(evt.getTilePagedLod(), |
|
758 |
tileFileName, MDTStage); |
|
759 |
m_planet.setVerticalExaggerationLayer(MDTStage, props3D |
|
760 |
.getVerticalEx()); |
|
867 | 761 |
MDTStage++; |
868 | 762 |
} |
869 | 763 |
} else { // no intersection |
870 | 764 |
if (dataType == Layer3DProps.layer3DImage) { |
871 |
m_planet.setTexture(evt.getTilePagedLod(), "", textureStage++); |
|
765 |
m_planet.setTexture(evt.getTilePagedLod(), "", |
|
766 |
textureStage++); |
|
872 | 767 |
} |
873 | 768 |
if (dataType == Layer3DProps.layer3DElevation) { |
874 |
m_planet.setHeightfield(evt.getTilePagedLod(), "", MDTStage); |
|
769 |
m_planet.setHeightfield(evt.getTilePagedLod(), "", |
|
770 |
MDTStage); |
|
875 | 771 |
} |
876 | 772 |
} |
877 | 773 |
} else { |
... | ... | |
1305 | 1201 |
} |
1306 | 1202 |
|
1307 | 1203 |
} |
1204 |
|
|
1205 |
public Node getSpecialNode() { |
|
1206 |
return this.m_canvas3d.getOSGViewer().getSpecialNode(0); |
|
1207 |
} |
|
1208 |
|
|
1209 |
public IViewerContainer getCanvas3d() { |
|
1210 |
return m_canvas3d; |
|
1211 |
} |
|
1212 |
|
|
1213 |
public void setCanvas3d(IViewerContainer m_canvas3d) { |
|
1214 |
this.m_canvas3d = m_canvas3d; |
|
1215 |
} |
|
1216 |
|
|
1308 | 1217 |
} |
import/ext3D/trunk/ext3D/src/com/iver/ai2/gvsig3d/map3d/GraphicLayer3D.java | ||
---|---|---|
1 |
package com.iver.ai2.gvsig3d.map3d; |
|
2 |
|
|
3 |
import java.awt.geom.Point2D; |
|
4 |
import java.util.ArrayList; |
|
5 |
|
|
6 |
import com.iver.ai2.gvsig3d.gui.VectorTest; |
|
7 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
|
8 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
|
9 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
|
10 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
|
11 |
import com.iver.cit.gvsig.fmap.rendering.FGraphicLabel; |
|
12 |
|
|
13 |
import es.upv.ai2.libjosg.AutoTransform; |
|
14 |
import es.upv.ai2.libjosg.Group; |
|
15 |
import es.upv.ai2.libjosg.Node; |
|
16 |
import es.upv.ai2.libjosg.Vec3; |
|
17 |
import es.upv.ai2.libjosg.Vec4; |
|
18 |
import es.upv.ai2.libjosg.features.Text; |
|
19 |
import es.upv.ai2.libjosg.planets.Planet; |
|
20 |
import es.upv.ai2.libjosg.viewer.IViewerContainer; |
|
21 |
|
|
22 |
public class GraphicLayer3D extends GraphicLayer { |
|
23 |
|
|
24 |
private Node especialNode; |
|
25 |
|
|
26 |
IViewerContainer canvas3d; |
|
27 |
|
|
28 |
private ArrayList graphics = new ArrayList(); |
|
29 |
|
|
30 |
private Planet planet; |
|
31 |
|
|
32 |
public GraphicLayer3D(IViewerContainer canvas3d, Planet planet) { |
|
33 |
super(); |
|
34 |
this.canvas3d = canvas3d; |
|
35 |
this.especialNode = canvas3d.getOSGViewer().getSpecialNode(0); |
|
36 |
this.planet = planet; |
|
37 |
} |
|
38 |
|
|
39 |
public void clearAllGraphics() { |
|
40 |
System.out.println("borrando busquedas"); |
|
41 |
// codigo de borrado de busquedas |
|
42 |
// especialNode.setEnabledNode(false); |
|
43 |
// especialNode.dispose(); |
|
44 |
// Group g = (Group)ESPECIALNODE; |
|
45 |
// G.GETCHILD(ARG0); |
|
46 |
} |
|
47 |
|
|
48 |
public void addGraphic(FGraphic g) { |
|
49 |
System.out.println("Borrando etiquetas"); |
|
50 |
// a?adir la etiqueta aki |
|
51 |
|
|
52 |
FGraphicLabel label = (FGraphicLabel) g; |
|
53 |
|
|
54 |
FLabel lab = label.getLabel(); |
|
55 |
Point2D p = lab.getOrig(); |
|
56 |
|
|
57 |
System.out.println("etiqueta ::: " + label.getLabel().getString()); |
|
58 |
|
|
59 |
// Variable declaration |
|
60 |
Vec3 posI = null, posE = null, posT = null; |
|
61 |
Vec3 posIni = null, posEnd = null, posText = null, pos1 = null, pos2 = null; |
|
62 |
|
|
63 |
// search for Gazetteer |
|
64 |
// There are two gazetteer modes SPHERICAL and PLANE mode |
|
65 |
if (planet.getType() == Planet.PlanetType.SPHERICAL_MODE) { |
|
66 |
// For spheriacl mode |
|
67 |
|
|
68 |
// Geodesical coordinates |
|
69 |
posI = new Vec3(p.getY(), p.getX(), 0); |
|
70 |
posE = new Vec3(p.getY(), p.getX(), 10000); |
|
71 |
posT = new Vec3(p.getY(), p.getX(), 50000); // Text position |
|
72 |
|
|
73 |
// To convert coordinate to cartesian |
|
74 |
posIni = planet.convertLatLongHeightToXYZ(posI); |
|
75 |
posEnd = planet.convertLatLongHeightToXYZ(posE); |
|
76 |
|
|
77 |
posText = planet.convertLatLongHeightToXYZ(posT); |
|
78 |
|
|
79 |
} else if (planet.getType() == Planet.PlanetType.PLANE_MODE) { |
|
80 |
|
|
81 |
// For plane mode |
|
82 |
posIni = new Vec3(p.getX(), p.getY(), 0); |
|
83 |
posText = new Vec3(p.getX(), p.getY(), 50000); // Text position |
|
84 |
} |
|
85 |
// To display text in gazetteer |
|
86 |
Text text = (Text) VectorTest.insertTextoS( |
|
87 |
label.getLabel().getString(), posText, new Vec4(1.0, 0.0, 0.0, |
|
88 |
1.0), 30, true); |
|
89 |
|
|
90 |
Group grupo = (Group) canvas3d.getOSGViewer().getSpecialNode(0); |
|
91 |
String name = ResourcesFactory.getResourcePath("flag.ive"); |
|
92 |
Node flag = canvas3d.getOSGViewer().readNodeFile(name); |
|
93 |
|
|
94 |
// Con autotransform |
|
95 |
AutoTransform trans = new AutoTransform(); |
|
96 |
trans.addChild(flag); |
|
97 |
int scale = (int) ((20 / 4.5) * 1000); |
|
98 |
trans.setScale(new Vec3(scale, scale, scale)); |
|
99 |
trans.setPosition(posIni); |
|
100 |
trans.setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA); |
|
101 |
|
|
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 |
} |
Also available in: Unified diff