protected void buildSlopeMap(){
  if (dataBuffer == null)   return;
  int resIdx=minuteSpacing / 5;
  if (resIdx < 0)   resIdx=0;
 else   if (resIdx > 3)   resIdx=3;
  double deltaX=etopoSpacings[resIdx];
  slopeMap=new byte[bufferWidth * bufferHeight];
  for (int y=0; y < bufferHeight; y++) {
    double lat=90. - 180. * (double)y / (double)bufferHeight;
    double coslat=Math.cos(Math.toRadians(lat));
    double slopeScaler=(double)slopeAdjust * coslat / deltaX;
    int idx0=y * bufferWidth;
    for (int x=0; x < bufferWidth; x++) {
      int idx1=idx0 + x;
      int idx2=idx1 + bufferWidth;
      if (y == bufferHeight - 1)       idx2=idx1;
      double d1=(double)dataBuffer[idx1];
      double d2=(double)dataBuffer[idx2];
      double slope=slopeScaler * (d2 - d1);
      if (slope > 0.99)       slope=0.99;
 else       if (slope < -0.99)       slope=-0.99;
      int islope=(int)(slope * 127.);
      slopeMap[idx1]=(byte)islope;
    }
  }
}

protected void buildSlopeMap ( ) { if ( dataBuffer == null ) return ; int resIdx = minuteSpacing / 5 ; if ( resIdx < 0 ) resIdx = 0 ; else if ( resIdx > 3 ) resIdx = 3 ; double deltaX = etopoSpacings [ resIdx ] ; slopeMap = new byte [ bufferWidth * bufferHeight ] ; for ( int y = 0 ; y < bufferHeight ; y ++ ) { double lat = 90. - 180. * ( double ) y / ( double ) bufferHeight ; double coslat = Math . cos ( Math . toRadians ( lat ) ) ; double slopeScaler = ( double ) slopeAdjust * coslat / deltaX ; int idx0 = y * bufferWidth ; for ( int x = 0 ; x < bufferWidth ; x ++ ) { int idx1 = idx0 + x ; int idx2 = idx1 + bufferWidth ; if ( y == bufferHeight - 1 ) idx2 = idx1 ; double d1 = ( double ) dataBuffer [ idx1 ] ; double d2 = ( double ) dataBuffer [ idx2 ] ; double slope = slopeScaler * ( d2 - d1 ) ; if ( slope > 0.99 ) slope = 0.99 ; else if ( slope < - 0.99 ) slope = - 0.99 ; int islope = ( int ) ( slope * 127. ) ; slopeMap [ idx1 ] = ( byte ) islope ; } } }
builds the slope index map . this method is called when the etopo resolution changes and when the slope contrast changes . the slope of the terrain is clipped ; slopes are between the range of + / - 45 deg . the calculated slope value is then linearly scaled to the range + / - 127 .
