Ejemplo n.º 1
0
 /**
  * Prepare the light for rendering.
  *
  * @param width the output image width
  * @param height the output image height
  */
 public void prepare(int width, int height) {
   float lx = (float) (Math.cos(azimuth) * Math.cos(elevation));
   float ly = (float) (Math.sin(azimuth) * Math.cos(elevation));
   float lz = (float) Math.sin(elevation);
   direction = new Vector3f(lx, ly, lz);
   direction.normalize();
   if (type != DISTANT) {
     lx *= distance;
     ly *= distance;
     lz *= distance;
     lx += width * centreX;
     ly += height * centreY;
   }
   position = new Vector3f(lx, ly, lz);
   realColor.set(new Color(color));
   realColor.scale(intensity);
   cosConeAngle = (float) Math.cos(coneAngle);
 }
Ejemplo n.º 2
0
 /**
  * Specifies the angle of the effect.
  *
  * @param angle the angle of the effect.
  * @angle
  * @see #getAngle
  */
 public void setAngle(float angle) {
   this.angle = angle;
   float cos = (float) Math.cos(angle);
   float sin = (float) Math.sin(angle);
   m00 = cos;
   m01 = sin;
   m10 = -sin;
   m11 = cos;
 }
Ejemplo n.º 3
0
  private int getEnvironmentMap(Vector3f normal, int[] inPixels, int width, int height) {
    if (environmentMap != null) {
      float angle = (float) Math.acos(-normal.y);

      float x, y;
      y = angle / ImageMath.PI;

      if (y == 0.0f || y == 1.0f) x = 0.0f;
      else {
        float f = normal.x / (float) Math.sin(angle);

        if (f > 1.0f) f = 1.0f;
        else if (f < -1.0f) f = -1.0f;

        x = (float) Math.acos(f) / ImageMath.PI;
      }
      // A bit of empirical scaling....
      x = ImageMath.clamp(x * envWidth, 0, envWidth - 1);
      y = ImageMath.clamp(y * envHeight, 0, envHeight - 1);
      int ix = (int) x;
      int iy = (int) y;

      float xWeight = x - ix;
      float yWeight = y - iy;
      int i = envWidth * iy + ix;
      int dx = ix == envWidth - 1 ? 0 : 1;
      int dy = iy == envHeight - 1 ? 0 : envWidth;
      return ImageMath.bilinearInterpolate(
          xWeight,
          yWeight,
          envPixels[i],
          envPixels[i + dx],
          envPixels[i + dy],
          envPixels[i + dx + dy]);
    }
    return 0;
  }