Beispiel #1
0
    public void update(ref Bitmap bitmap, DateTime time)
    {
      ImageHandler blend = new ImageHandler(bitmap);
      // Lock bitmaps
      day.lockBitmap();
      night.lockBitmap();
      blend.lockBitmap();

      // Calculate the Greenwich Sidereal Time
      double GST = getGreenwichSiderealTime(time);

      // Calculate the solar right ascension and declination

      double alpha = getSolarRightAscension(time);
      double delta = getSolarDeclination(time);

      // Loop over the y-pixels of the night/day images
      int i_x;
      int i_y;

      for (i_x = 0; i_x < this.n_x; i_x++)
      {
        // Calculate the longitude
        double longitude = 180 - (i_x + 0.5) / this.n_x * 360;

        // Calculate the solar hour angle
        double HA = GST * 360 / 24 - longitude - alpha;

        for (i_y = 0; i_y < this.n_y; i_y++)
        {
          // Calculate the latitude
          double latitude = 90 - (i_y + 0.5) / this.n_y * 180;

          // Calculate the altitude of the sun
          double alt = getAltitude(HA, delta, latitude, longitude);

          // Work out the interpolation factor for drawing the pixel
          double intFactor;

          if (alt > dayAltMin)
          {
            intFactor = 1;
          }
          else if (alt < nightAltMax)
          {
            intFactor = 0;
          }
          else
          {
            intFactor = (alt - nightAltMax) / (dayAltMin - nightAltMax);
          }

          // Get the RGB pixels of the day and night images
          int dayRGB = (int)this.day.getPixel(i_x, i_y);
          int nightRGB = (int)this.night.getPixel(i_x, i_y);

          int dayR = dayRGB >> 16 & 0xFF;
          int dayG = dayRGB >> 8 & 0xFF;
          int dayB = dayRGB & 0xFF;

          int nightR = nightRGB >> 16 & 0xFF;
          int nightG = nightRGB >> 8 & 0xFF;
          int nightB = nightRGB & 0xFF;

          // Calculate the interpolated value of the blended pixel
          int blendedRGB = (int)(dayR * intFactor + nightR * (1 - intFactor)) << 16 |
                           (int)(dayG * intFactor + nightG * (1 - intFactor)) << 8 |
                           (int)(dayB * intFactor + nightB * (1 - intFactor));

          blend.setPixel(i_x, i_y, blendedRGB);
        }
      }
      // Lock bitmaps
      day.unlockBitmap();
      night.unlockBitmap();
      blend.unlockBitmap();
    }