Skip to content

Fix PointPlacemark pitch issue #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 34 additions & 35 deletions src/gov/nasa/worldwind/render/PointPlacemark.java
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,26 @@ protected void doDrawOrderedRenderable(DrawContext dc, PickSupport pickCandidate
(byte) color.getAlpha());
}

// Compute the scale
double xscale;
Double scale = this.getActiveAttributes().getScale();
if (scale != null)
xscale = scale * this.activeTexture.getWidth(dc);
else
xscale = this.activeTexture.getWidth(dc);

double yscale;
if (scale != null)
yscale = scale * this.activeTexture.getHeight(dc);
else
yscale = this.activeTexture.getHeight(dc);

// Calculate maximum possible depth value in case of rectangle is tilted on 90 degree and rotated on 45
double maxDepth = Math.max(xscale, yscale) * 1.42;

// The image is drawn using a parallel projection.
osh.pushProjectionIdentity(gl);
gl.glOrtho(0d, dc.getView().getViewport().width, 0d, dc.getView().getViewport().height, -1d, 1d);
gl.glOrtho(0d, dc.getView().getViewport().width, 0d, dc.getView().getViewport().height, -maxDepth, maxDepth);

// Apply the depth buffer but don't change it (for screen-space shapes).
if ((!dc.isDeepPickingEnabled()))
Expand All @@ -1014,52 +1031,34 @@ protected void doDrawOrderedRenderable(DrawContext dc, PickSupport pickCandidate

// Adjust depth of image to bring it slightly forward
double depth = opm.screenPoint.z - (8d * 0.00048875809d);
depth = depth < 0d ? 0d : (depth > 1d ? 1d : depth);
depth = depth < 0d ? 0d : Math.min(depth, 1d);
gl.glDepthFunc(GL.GL_LESS);
gl.glDepthRange(depth, depth);

// The image is drawn using a translated and scaled unit quad.
// Translate to screen point and adjust to align hot spot.
osh.pushModelviewIdentity(gl);
gl.glTranslated(opm.screenPoint.x + this.dx, opm.screenPoint.y + this.dy, 0);

// Compute the scale
double xscale;
Double scale = this.getActiveAttributes().getScale();
if (scale != null)
xscale = scale * this.activeTexture.getWidth(dc);
else
xscale = this.activeTexture.getWidth(dc);

double yscale;
if (scale != null)
yscale = scale * this.activeTexture.getHeight(dc);
else
yscale = this.activeTexture.getHeight(dc);
// Translate to screen point.
gl.glTranslated(opm.screenPoint.x, opm.screenPoint.y, 0);

Double heading = getActiveAttributes().getHeading();
// Apply the pitch if specified.
Double pitch = getActiveAttributes().getPitch();

// Adjust heading to be relative to globe or screen
if (heading != null)
{
if (AVKey.RELATIVE_TO_GLOBE.equals(this.getActiveAttributes().getHeadingReference()))
heading = dc.getView().getHeading().degrees - heading;
else
heading = -heading;
if (pitch != null) {
gl.glRotated(pitch, 1, 0, 0);
}

// Apply the heading and pitch if specified.
if (heading != null || pitch != null)
{
gl.glTranslated(xscale / 2, yscale / 2, 0);
if (pitch != null)
gl.glRotated(pitch, 1, 0, 0);
if (heading != null)
gl.glRotated(heading, 0, 0, 1);
gl.glTranslated(-xscale / 2, -yscale / 2, 0);
// Apply the heading if specified.
Double heading = getActiveAttributes().getHeading();
if (heading != null) {
// Adjust heading to be relative to globe or screen
heading = AVKey.RELATIVE_TO_GLOBE.equals(this.getActiveAttributes().getHeadingReference())
? dc.getView().getHeading().degrees - heading : -heading;
gl.glRotated(heading, 0, 0, 1);
}

// Adjust to align hot spot.
gl.glTranslated(this.dx, this.dy, 0);

// Scale the unit quad
gl.glScaled(xscale, yscale, 1);

Expand Down
1 change: 1 addition & 0 deletions src/gov/nasa/worldwindx/examples/Placemarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public void run()
// Create and assign the placemark attributes.
PointPlacemarkAttributes attrs = new PointPlacemarkAttributes();
attrs.setImage(symbolImage);
attrs.setImageOffset(new Offset(0.5, 0.5, AVKey.FRACTION, AVKey.FRACTION));
attrs.setImageColor(new Color(1f, 1f, 1f, 1f));
attrs.setLabelOffset(new Offset(0.9d, 0.6d, AVKey.FRACTION, AVKey.FRACTION));
attrs.setScale(0.5);
Expand Down