Esempio n. 1
0
 public RGB getAmbientColor(float ambience, Vector3D hitPoint) {
   RGB original = getColor();
   double reflectance = getReflectance();
   if (texture != null) {
     if (texture instanceof ImageTexture) {
       float theta = (float) Math.acos((hitPoint.getZ() - this.origin.getZ()) / this.radius);
       float phi =
           (float)
               Math.atan2(
                   hitPoint.getY() - this.origin.getY(), hitPoint.getX() - this.origin.getX());
       if (phi < 0) {
         phi += 2 * Math.PI;
       }
       float u = (float) (phi / (2 * Math.PI));
       float v = (float) ((Math.PI - theta) / Math.PI);
       original = texture.getValue(new Vector2D(u, v), hitPoint);
     } else {
       original = texture.getValue(null, hitPoint);
     }
   }
   if (reflectance == 0) {
     return original;
   } else {
     return new RGB(
         (int) (original.getRed() * reflectance),
         (int) (original.getGreen() * reflectance),
         (int) (original.getBlue() * reflectance));
   }
 }
Esempio n. 2
0
 public RGB getLitColor(Light light, Vector3D point, float ambience) {
   float nDotL = getNDotL(point, light.getLightVector());
   if (ambience == 0) {
     RGB multipliedLight = light.getColor().multiply(getAmbientColor(ambience, point));
     return multipliedLight.multiplyByScalar(nDotL);
   } else {
     int color = (int) ((ambience + (getReflectance() * nDotL)) * 255);
     return new RGB(color, color, color);
   }
 }