protected void moveControlPoint(GfrMrkMoveHoriz controlPoint, Point lastMousePoint, Point moveToPoint)
{
View view = super._wwd.getView();
Globe globe = super._wwd.getModel().getGlobe();
Position refPos = controlPoint.getPosition();
if (refPos == null)
return;
Line ray = view.computeRayFromScreenPoint(moveToPoint.getX(), moveToPoint.getY());
Line previousRay = view.computeRayFromScreenPoint(lastMousePoint.getX(), lastMousePoint.getY());
Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(super._wwd, refPos.getElevation(), ray);
Vec4 previousVec = AirspaceEditorUtil.intersectGlobeAt(super._wwd, refPos.getElevation(), previousRay);
if (vec == null || previousVec == null)
{
return;
}
Position pos = globe.computePositionFromPoint(vec);
Position previousPos = globe.computePositionFromPoint(previousVec);
LatLon change = pos.subtract(previousPos);
java.util.List<LatLon> boundary = new ArrayList<LatLon>();
for (LatLon ll : ((Path) this._pol_).getPositions())
{
boundary.add(ll);
}
int intIndexControlPoint = controlPoint.getIndex();
/*
* There is a bug here :
* refPos.getAltitude() gives the altitude of the control node :
* e.g.
* 3250m in a mountain,
* -4232m in the ocean.
* But the posNew, while rendering is threated the elevation of the
* control node ABOVE the elevation of the ground level.
*
* Nice example of this bug between France and Italy with a Path
* from the Alps to Ligurian Sea.
* The control node in the mountain increases its altitude everytime it is moved,
* while the control node in the sea decreases its altitude.
*
* => possible fix : hard code a fix value instead of refPos.getAltitude()
* use the value of refPos.getAltitude() as a fix altitude, and not the
* height above ground level.
*/
Position posNew = new Position(pos.add(change), refPos.getAltitude());
boundary.set(intIndexControlPoint, posNew);
// Path ensures that the last boundary position is the same as the first. Remove the last point
// before setting the boundary.
java.util.List<Position> boundary2 = new ArrayList<Position>();
for (LatLon ll : boundary)
{
boundary2.add(new Position(ll, ((Position) ll).getElevation()));
}
((Path) this._pol_).setPositions(boundary2);
}