Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / render / Material.java
blobefae5377dcaec7520d4a6e8f4931fad0bbf95379
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 2471 2007-07-31 21:50:57Z 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), 20f);
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 Color getSpecular()
72 return this.specular;
75 public Color getDiffuse()
77 return this.diffuse;
80 public Color getAmbient()
82 return this.ambient;
85 public Color getEmission()
87 return this.emission;
90 public float getShininess()
92 return this.shininess;
95 public void apply(javax.media.opengl.GL gl, int face)
97 float[] rgba = new float[4];
99 gl.glMaterialfv(face, javax.media.opengl.GL.GL_SPECULAR, this.specular.getRGBComponents(rgba), 0);
100 gl.glMaterialfv(face, javax.media.opengl.GL.GL_DIFFUSE, this.diffuse.getRGBComponents(rgba), 0);
101 gl.glMaterialfv(face, javax.media.opengl.GL.GL_AMBIENT, this.ambient.getRGBComponents(rgba), 0);
102 gl.glMaterialf(face, javax.media.opengl.GL.GL_SHININESS, this.shininess);
103 gl.glMaterialfv(face, javax.media.opengl.GL.GL_EMISSION, this.emission.getRGBComponents(rgba), 0);