{
Terrain terrain = dc.getTerrain();
ExtrudedPolygon pol = (ExtrudedPolygon) super._pol_;
Position refPos = pol.getReferencePosition();
Vec4 refPoint = terrain.getSurfacePoint(refPos.getLatitude(), refPos.getLongitude(), 0);
int altitudeMode = pol.getAltitudeMode();
double height = pol.getHeight();
Vec4 vaa = null;
double vaaLength = 0; // used to compute independent length of each cap vertex
double vaLength = 0;
int i = 0;
for (LatLon location : pol.getOuterBoundary())
{
Vec4 vert;
// Compute the top/cap point.
if (altitudeMode == WorldWind.CONSTANT || !(location instanceof Position))
{
if (vaa == null)
{
// Compute the vector lengths of the top and bottom points at the reference position.
vaa = refPoint.multiply3(height / refPoint.getLength3());
vaaLength = vaa.getLength3();
vaLength = refPoint.getLength3();
}
// Compute the bottom point, which is on the terrain.
vert = terrain.getSurfacePoint(location.getLatitude(), location.getLongitude(), 0);
double delta = vaLength - vert.dot3(refPoint) / vaLength;
vert = vert.add3(vaa.multiply3(1d + delta / vaaLength));
}
else if (altitudeMode == WorldWind.RELATIVE_TO_GROUND)
{
vert = terrain.getSurfacePoint(location.getLatitude(), location.getLongitude(),
((Position) location).getAltitude());