/** * Converts a screen point to the geographic coordinates on the globe. * * @param screenX X coordinate * @param screenY Y coordinate * @param result Pre-allocated Position receives the geographic coordinates * * @return true if the screen point could be converted; false if the screen point is not on the globe */ public boolean screenPointToGroundPosition(float screenX, float screenY, Position result) { if (this.wwd.rayThroughScreenPoint(screenX, screenY, ray)) { Globe globe = wwd.getGlobe(); if (globe.intersect(ray, this.pickPoint)) { globe.cartesianToGeographic(pickPoint.x, this.pickPoint.y, this.pickPoint.z, result); return true; } } return false; }
/** * Converts a screen point to the geographic coordinates on the globe. * * @param screenX X coordinate * @param screenY Y coordinate * @param result Pre-allocated Position receives the geographic coordinates * * @return true if the screen point could be converted; false if the screen point is not on the globe */ public boolean screenPointToGroundPosition(float screenX, float screenY, Position result) { if (this.wwd.rayThroughScreenPoint(screenX, screenY, ray)) { Globe globe = wwd.getGlobe(); if (globe.intersect(ray, this.pickPoint)) { globe.cartesianToGeographic(pickPoint.x, this.pickPoint.y, this.pickPoint.z, result); return true; } } return false; } }
protected Camera lookAtToCamera(Globe globe, LookAt lookAt, Camera result) { this.lookAtToViewingTransform(globe, lookAt, this.modelview); this.modelview.extractEyePoint(this.originPoint); globe.cartesianToGeographic(this.originPoint.x, this.originPoint.y, this.originPoint.z, this.originPos); globe.cartesianToLocalTransform(this.originPoint.x, this.originPoint.y, this.originPoint.z, this.origin); this.modelview.multiplyByMatrix(this.origin); result.latitude = this.originPos.latitude; result.longitude = this.originPos.longitude; result.altitude = this.originPos.altitude; result.heading = this.modelview.extractHeading(lookAt.roll); // disambiguate heading and roll result.tilt = this.modelview.extractTilt(); result.roll = lookAt.roll; // roll passes straight through return result; }
protected LookAt cameraToLookAt(Globe globe, Camera camera, LookAt result) { this.cameraToViewingMatrix(globe, camera, this.modelview); this.modelview.extractEyePoint(this.forwardRay.origin); this.modelview.extractForwardVector(this.forwardRay.direction); if (!globe.intersect(this.forwardRay, this.originPoint)) { double horizon = globe.horizonDistance(camera.altitude); this.forwardRay.pointAt(horizon, this.originPoint); } globe.cartesianToGeographic(this.originPoint.x, this.originPoint.y, this.originPoint.z, this.originPos); globe.cartesianToLocalTransform(this.originPoint.x, this.originPoint.y, this.originPoint.z, this.origin); this.modelview.multiplyByMatrix(this.origin); result.latitude = this.originPos.latitude; result.longitude = this.originPos.longitude; result.altitude = this.originPos.altitude; result.range = -this.modelview.m[11]; result.heading = this.modelview.extractHeading(camera.roll); // disambiguate heading and roll result.tilt = this.modelview.extractTilt(); result.roll = camera.roll; // roll passes straight through return result; }
protected void renderTerrainPickedObject(RenderContext rc) { if (rc.terrain.getSector().isEmpty()) { return; // no terrain to pick } // Acquire a unique picked object ID for terrain. int pickedObjectId = rc.nextPickedObjectId(); // Enqueue a drawable for processing on the OpenGL thread that displays terrain in the unique pick color. Pool<DrawableSurfaceColor> pool = rc.getDrawablePool(DrawableSurfaceColor.class); DrawableSurfaceColor drawable = DrawableSurfaceColor.obtain(pool); drawable.color = PickedObject.identifierToUniqueColor(pickedObjectId, drawable.color); drawable.program = (BasicShaderProgram) rc.getShaderProgram(BasicShaderProgram.KEY); if (drawable.program == null) { drawable.program = (BasicShaderProgram) rc.putShaderProgram(BasicShaderProgram.KEY, new BasicShaderProgram(rc.resources)); } rc.offerSurfaceDrawable(drawable, Double.NEGATIVE_INFINITY /*z-order before all other surface drawables*/); // If the pick ray intersects the terrain, enqueue a picked object that associates the terrain drawable with its // picked object ID and the intersection position. if (rc.pickRay != null && rc.terrain.intersect(rc.pickRay, this.pickPoint)) { rc.globe.cartesianToGeographic(this.pickPoint.x, this.pickPoint.y, this.pickPoint.z, this.pickPos); this.pickPos.altitude = 0; // report the actual altitude, which may not lie on the terrain's surface rc.offerPickedObject(PickedObject.fromTerrain(pickedObjectId, this.pickPos)); } }