gvsig-3d / 2.1 / branches / org.gvsig.view3d_vector_and_extrusion_2.3 / org.gvsig.view3d / org.gvsig.view3d / org.gvsig.view3d.lib / org.gvsig.view3d.lib.impl / src / main / java / org / gvsig / view3d / lib / impl / layers / vector / alternativepoints / BasicExtrudableMarker.java @ 734
History | View | Annotate | Download (6.63 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright © 2007-2016 gvSIG Association
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.view3d.lib.impl.layers.vector.alternativepoints; |
25 |
|
26 |
import java.awt.Color; |
27 |
|
28 |
import javax.media.opengl.GL; |
29 |
import javax.media.opengl.GL2; |
30 |
|
31 |
import gov.nasa.worldwind.WorldWind; |
32 |
import gov.nasa.worldwind.geom.Angle; |
33 |
import gov.nasa.worldwind.geom.Position; |
34 |
import gov.nasa.worldwind.geom.Vec4; |
35 |
import gov.nasa.worldwind.render.DrawContext; |
36 |
import gov.nasa.worldwind.render.markers.BasicMarker; |
37 |
import gov.nasa.worldwind.render.markers.Marker; |
38 |
import gov.nasa.worldwind.render.markers.MarkerAttributes; |
39 |
import gov.nasa.worldwind.render.markers.MarkerShape; |
40 |
import gov.nasa.worldwind.util.Logging; |
41 |
|
42 |
/**
|
43 |
* Marker that can be extruded. Adapted from {@link BasicMarker}.
|
44 |
*
|
45 |
* @author Andrea Antonello andrea.antonello@gmail.com
|
46 |
*/
|
47 |
public class BasicExtrudableMarker implements Marker { |
48 |
|
49 |
protected Position position; // may be null |
50 |
protected Angle heading; // may be null |
51 |
protected Angle pitch; // may be null |
52 |
protected Angle roll; // may be null |
53 |
|
54 |
// To avoid the memory overhead of creating an attributes object for every new marker, attributes are
|
55 |
// required to be specified at construction.
|
56 |
protected BasicExtrudableMarkerAttributes attributes;
|
57 |
|
58 |
private int altitudeMode = WorldWind.ABSOLUTE; |
59 |
|
60 |
public BasicExtrudableMarker(Position position, BasicExtrudableMarkerAttributes attrs) { |
61 |
if (attrs == null) { |
62 |
String message = Logging.getMessage("nullValue.AttributesIsNull"); |
63 |
Logging.logger().severe(message); |
64 |
throw new IllegalArgumentException(message); |
65 |
} |
66 |
|
67 |
this.position = position;
|
68 |
this.attributes = attrs;
|
69 |
} |
70 |
|
71 |
public BasicExtrudableMarker(Position position, BasicExtrudableMarkerAttributes attrs, Angle heading) { |
72 |
if (attrs == null) { |
73 |
String message = Logging.getMessage("nullValue.AttributesIsNull"); |
74 |
Logging.logger().severe(message); |
75 |
throw new IllegalArgumentException(message); |
76 |
} |
77 |
|
78 |
this.position = position;
|
79 |
this.heading = heading;
|
80 |
this.attributes = attrs;
|
81 |
} |
82 |
|
83 |
public Position getPosition() { |
84 |
return position;
|
85 |
} |
86 |
|
87 |
public void setPosition(Position position) { |
88 |
this.position = position;
|
89 |
} |
90 |
|
91 |
/** {@inheritDoc} */
|
92 |
public Angle getHeading() {
|
93 |
return this.heading; |
94 |
} |
95 |
|
96 |
/** {@inheritDoc} */
|
97 |
public void setHeading(Angle heading) { |
98 |
this.heading = heading;
|
99 |
} |
100 |
|
101 |
/** {@inheritDoc} */
|
102 |
public Angle getRoll() {
|
103 |
return this.roll; |
104 |
} |
105 |
|
106 |
/** {@inheritDoc} */
|
107 |
public void setRoll(Angle roll) { |
108 |
this.roll = roll;
|
109 |
} |
110 |
|
111 |
/** {@inheritDoc} */
|
112 |
public Angle getPitch() {
|
113 |
return this.pitch; |
114 |
} |
115 |
|
116 |
/** {@inheritDoc} */
|
117 |
public void setPitch(Angle pitch) { |
118 |
this.pitch = pitch;
|
119 |
} |
120 |
|
121 |
public MarkerAttributes getAttributes() {
|
122 |
return attributes;
|
123 |
} |
124 |
|
125 |
public void setAttributes(MarkerAttributes attributes) { |
126 |
if (attributes instanceof BasicExtrudableMarkerAttributes) { |
127 |
BasicExtrudableMarkerAttributes attr = (BasicExtrudableMarkerAttributes) attributes; |
128 |
this.attributes = attr;
|
129 |
} |
130 |
} |
131 |
|
132 |
public void render(DrawContext dc, Vec4 point, double radius, boolean isRelative) { |
133 |
MarkerShape shape = this.attributes.getShape(dc);
|
134 |
shape.render(dc, this, point, radius, isRelative);
|
135 |
renderExtrude(dc, point); |
136 |
} |
137 |
|
138 |
public void render(DrawContext dc, Vec4 point, double radius) { |
139 |
this.attributes.getShape(dc).render(dc, this, point, radius, false); |
140 |
|
141 |
renderExtrude(dc, point); |
142 |
} |
143 |
|
144 |
private void renderExtrude(DrawContext dc, Vec4 point) { |
145 |
if (attributes.isDoExtrude()) {
|
146 |
|
147 |
Vec4 placePoint; |
148 |
if (this.altitudeMode == WorldWind.CLAMP_TO_GROUND) { |
149 |
placePoint = dc.computeTerrainPoint(position.getLatitude(), position.getLongitude(), 0);
|
150 |
} else if (this.altitudeMode == WorldWind.RELATIVE_TO_GROUND) { |
151 |
placePoint = |
152 |
dc.computeTerrainPoint(position.getLatitude(), position.getLongitude(), position.getAltitude()); |
153 |
} else {
|
154 |
// ABSOLUTE
|
155 |
double height = position.getElevation();
|
156 |
placePoint = |
157 |
dc.getGlobe().computePointFromPosition(position.getLatitude(), position.getLongitude(), height); |
158 |
} |
159 |
|
160 |
Vec4 terrainPoint = dc.computeTerrainPoint(position.getLatitude(), position.getLongitude(), 0);
|
161 |
|
162 |
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
|
163 |
|
164 |
if ((!dc.isDeepPickingEnabled()))
|
165 |
gl.glEnable(GL.GL_DEPTH_TEST); |
166 |
gl.glDepthFunc(GL.GL_LEQUAL); |
167 |
gl.glDepthMask(true);
|
168 |
|
169 |
try {
|
170 |
dc.getView().pushReferenceCenter(dc, point); // draw relative to the place point
|
171 |
|
172 |
// set width
|
173 |
gl.glLineWidth(2f);
|
174 |
gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_FASTEST); |
175 |
gl.glEnable(GL.GL_LINE_SMOOTH); |
176 |
|
177 |
// set color
|
178 |
Color color = attributes.getMaterial().getDiffuse();
|
179 |
gl.glColor4ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue(), |
180 |
(byte) color.getAlpha());
|
181 |
|
182 |
// draw line
|
183 |
gl.glBegin(GL2.GL_LINE_STRIP); |
184 |
gl.glVertex3d(Vec4.ZERO.x, Vec4.ZERO.y, Vec4.ZERO.z); |
185 |
gl.glVertex3d(terrainPoint.x - placePoint.x, terrainPoint.y - placePoint.y, |
186 |
terrainPoint.z - placePoint.z); |
187 |
gl.glEnd(); |
188 |
} finally {
|
189 |
dc.getView().popReferenceCenter(dc); |
190 |
} |
191 |
} |
192 |
} |
193 |
|
194 |
public void setAltitudeMode(int altitudeMode) { |
195 |
this.altitudeMode = altitudeMode;
|
196 |
} |
197 |
|
198 |
} |