Пример #1
0
    public void execute(GL10 gl) {
      float[] paleYellow = {1.0f, 1.0f, 0.3f, 1.0f};
      float[] white = {1.0f, 1.0f, 1.0f, 1.0f};
      float[] black = {0.0f, 0.0f, 0.0f, 0.0f};
      float[] sunPos = {0.0f, 0.0f, 0.0f, 1.0f};
      float sunWidth = 0.0f;
      float sunScreenLoc[] = new float[4]; // xyz and radius
      float earthScreenLoc[] = new float[4]; // xyz and radius

      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glShadeModel(GL10.GL_SMOOTH);

      gl.glEnable(GL10.GL_LIGHTING);
      gl.glEnable(GL10.GL_BLEND);
      gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

      gl.glPushMatrix();

      gl.glTranslatef(
          -m_Eyeposition[X_VALUE], -m_Eyeposition[Y_VALUE], -m_Eyeposition[Z_VALUE]); // 1

      gl.glLightfv(SS_SUNLIGHT, GL10.GL_POSITION, makeFloatBuffer(sunPos));
      gl.glEnable(SS_SUNLIGHT);

      gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_EMISSION, makeFloatBuffer(paleYellow));

      gl.glDisable(GL10.GL_DEPTH_TEST);
      executePlanet(m_Sun, gl, false, sunScreenLoc);
      gl.glEnable(GL10.GL_DEPTH_TEST);

      gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_EMISSION, makeFloatBuffer(black));

      gl.glPopMatrix();

      if ((m_LensFlare != null) && (sunScreenLoc[Z_INDEX] > 0.0f)) {
        CGPoint centerRelative = new CGPoint();
        CGSize windowSize = new CGSize();
        float sunsBodyWidth =
            44.0f; // about the width of the sun's bady within the glare in the bitmap, in pixels.
        float cx, cy;
        float aspectRatio;
        float scale = 0f;

        DisplayMetrics display = myAppcontext.getResources().getDisplayMetrics();
        windowSize.width = display.widthPixels;
        windowSize.height = display.heightPixels;

        cx = windowSize.width / 2.0f;
        cy = windowSize.height / 2.0f;

        aspectRatio = cx / cy;

        centerRelative.x = sunScreenLoc[X_INDEX] - cx;
        centerRelative.y = (cy - sunScreenLoc[Y_INDEX]) / aspectRatio;

        scale =
            CT.renderTextureAt(
                gl,
                centerRelative.x,
                centerRelative.y,
                0f,
                windowSize,
                m_FlareSource,
                sunScreenLoc[RADIUS_INDEX],
                1.0f,
                1.0f,
                1.0f,
                1.0f);

        sunWidth = scale * windowSize.width * sunsBodyWidth / 256.0f;
      }

      gl.glEnable(SS_FILLLIGHT2);

      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glPushMatrix();

      gl.glTranslatef(-m_Eyeposition[X_VALUE], -m_Eyeposition[Y_VALUE], -m_Eyeposition[Z_VALUE]);

      gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, makeFloatBuffer(white));
      gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, makeFloatBuffer(white));

      executePlanet(m_Earth, gl, true, earthScreenLoc);

      gl.glPopMatrix();

      if ((m_LensFlare != null) && (sunScreenLoc[Z_INDEX] > 0)) {
        float scale = 1.0f;
        float delX = origwidth / 2.0f - sunScreenLoc[X_INDEX];
        float delY = origheight / 2.0f - sunScreenLoc[Y_INDEX];
        float grazeDist = earthScreenLoc[RADIUS_INDEX] + sunWidth;
        float percentVisible = 1.0f;
        float vanishDist = earthScreenLoc[RADIUS_INDEX] - sunWidth;

        float distanceBetweenBodies = (float) sqrt(delX * delX + delY * delY);

        if ((distanceBetweenBodies > vanishDist) && (distanceBetweenBodies < grazeDist)) {
          percentVisible = (float) ((distanceBetweenBodies - vanishDist) / sunWidth);

          if (percentVisible > 1.0) percentVisible = 1.0f;
          else if (percentVisible < 0.3) percentVisible = .5f;
        } else if (distanceBetweenBodies > grazeDist) {
          percentVisible = 1.0f;
        } else {
          percentVisible = 0.0f;
        }

        scale = STANDARD_FOV / m_FieldOfView;

        CGPoint source = new CGPoint();
        source.x = sunScreenLoc[X_INDEX];
        source.y = sunScreenLoc[Y_INDEX];
        CGSize winsize = new CGSize();
        winsize.width = origwidth;
        winsize.height = origheight;

        if (percentVisible > 0.0) {
          m_LensFlare.execute(gl, winsize, source, scale, percentVisible);
        }
      }
    }