Update to Worldwind release 0.4.1
[worldwind-tracker.git] / gov / nasa / worldwind / render / Material.java
blob80e9d9e01d8143a709b0ff00f1598901e61f6b63
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind.render;
9 import gov.nasa.worldwind.util.Logging;
11 import java.awt.*;
13 /**
14 * @author tag
15 * @version $Id: Material.java 2677 2007-08-25 06:41:38Z tgaskins $
17 public class Material
19 public static final int SPECULAR = 0;
20 public static final int DIFFUSE = 1;
21 public static final int AMBIENT = 2;
22 public static final int EMISSION = 3;
24 public static final Material WHITE = new Material(new Color(0.9f, 0.9f, 0.9f, 0.0f), new Color(0.8f, 0.8f, 0.8f,
25 0.0f), new Color(0.2f, 0.2f, 0.2f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 20f);
27 public static final Material RED = new Material(new Color(0.75f, 0.0f, 0.0f, 0.0f), new Color(0.8f, 0.0f, 0.0f,
28 0.0f), new Color(0.2f, 0.0f, 0.0f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 80f);
30 public static final Material GREEN = new Material(new Color(0.0f, 0.75f, 0.0f, 0.0f), new Color(0.0f, 0.8f, 0.0f,
31 0.0f), new Color(0.0f, 0.2f, 0.0f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 20f);
33 public static final Material BLUE = new Material(new Color(0.0f, 0.0f, 0.75f, 0.0f), new Color(0.0f, 0.0f, 0.8f,
34 0.0f), new Color(0.0f, 0.0f, 0.2f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 20f);
36 public static final Material YELLOW = new Material(new Color(0.75f, 0.75f, 0.55f, 0.0f), new Color(0.8f, 0.8f, 0.0f,
37 0.0f), new Color(0.2f, 0.2f, 0.01f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 20f);
39 private final Color specular;
40 private final Color diffuse;
41 private final Color ambient;
42 private final Color emission;
43 private final float shininess;
45 /**
46 * @param specular
47 * @param diffuse
48 * @param ambient
49 * @param emission
50 * @param shininess
51 * @throws IllegalArgumentException if <code>specular</code>, <code>diffuse</code>, <code>ambient</code> or
52 * <code>emission</code> is null
54 public Material(Color specular, Color diffuse, Color ambient, Color emission, float shininess)
56 if (specular == null || diffuse == null || ambient == null || emission == null)
58 String msg = Logging.getMessage("nullValue.ColorIsNull");
59 Logging.logger().severe(msg);
60 throw new IllegalArgumentException(msg);
63 this.specular = specular;
64 this.diffuse = diffuse;
65 this.ambient = ambient;
66 this.emission = emission;
67 this.shininess = shininess;
70 public Material(Color color)
72 if (color == null)
74 String msg = Logging.getMessage("nullValue.ColorIsNull");
75 Logging.logger().severe(msg);
76 throw new IllegalArgumentException(msg);
79 this.specular = new Color(0.75f, 0.75f, 0.55f, 0.0f);
80 this.diffuse = color;
81 this.ambient = new Color(0.2f, 0.2f, 0.01f, 0.0f);
82 this.emission = new Color(0.0f, 0.0f, 0.0f, 0.0f);
83 this.shininess = 20f;
86 public Color getSpecular()
88 return this.specular;
91 public Color getDiffuse()
93 return this.diffuse;
96 public Color getAmbient()
98 return this.ambient;
101 public Color getEmission()
103 return this.emission;
106 public float getShininess()
108 return this.shininess;
111 public void apply(javax.media.opengl.GL gl, int face)
113 float[] rgba = new float[4];
115 gl.glMaterialfv(face, javax.media.opengl.GL.GL_SPECULAR, this.specular.getRGBComponents(rgba), 0);
116 gl.glMaterialfv(face, javax.media.opengl.GL.GL_DIFFUSE, this.diffuse.getRGBComponents(rgba), 0);
117 gl.glMaterialfv(face, javax.media.opengl.GL.GL_AMBIENT, this.ambient.getRGBComponents(rgba), 0);
118 gl.glMaterialf(face, javax.media.opengl.GL.GL_SHININESS, this.shininess);
119 gl.glMaterialfv(face, javax.media.opengl.GL.GL_EMISSION, this.emission.getRGBComponents(rgba), 0);