Worldwind public release 0.2
[worldwind-tracker.git] / gov / nasa / worldwind / Material.java
blob4c22855f9daf99bb80835cab622bb46c78a87a30
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;
9 import java.awt.Color;
11 /**
12 * @author tag
13 * @version $Id: Material.java 1175 2007-03-07 21:16:55Z tgaskins $
15 public class Material
17 public static final int SPECULAR = 0;
18 public static final int DIFFUSE = 1;
19 public static final int AMBIENT = 2;
20 public static final int EMISSION = 3;
22 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,
23 0.0f), new Color(0.2f, 0.2f, 0.2f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 20f);
25 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,
26 0.0f), new Color(0.2f, 0.0f, 0.0f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 20f);
28 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,
29 0.0f), new Color(0.0f, 0.2f, 0.0f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 20f);
31 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,
32 0.0f), new Color(0.0f, 0.0f, 0.2f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 20f);
34 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,
35 0.0f), new Color(0.2f, 0.2f, 0.01f, 0.0f), new Color(0.0f, 0.0f, 0.0f, 0.0f), 20f);
37 private final Color specular;
38 private final Color diffuse;
39 private final Color ambient;
40 private final Color emission;
41 private final float shininess;
43 /**
44 * @param specular
45 * @param diffuse
46 * @param ambient
47 * @param emission
48 * @param shininess
49 * @throws IllegalArgumentException if <code>specular</code>, <code>diffuse</code>, <code>ambient</code> or
50 * <code>emission</code> is null
52 public Material(Color specular, Color diffuse, Color ambient, Color emission, float shininess)
54 if (specular == null || diffuse == null || ambient == null || emission == null)
56 String msg = WorldWind.retrieveErrMsg("nullValue.ColorIsNull");
57 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
58 throw new IllegalArgumentException(msg);
61 this.specular = specular;
62 this.diffuse = diffuse;
63 this.ambient = ambient;
64 this.emission = emission;
65 this.shininess = shininess;
68 public Color getSpecular()
70 return this.specular;
73 public Color getDiffuse()
75 return this.diffuse;
78 public Color getAmbient()
80 return this.ambient;
83 public Color getEmission()
85 return this.emission;
88 public float getShininess()
90 return this.shininess;
93 public void apply(javax.media.opengl.GL gl, int face)
95 float[] rgba = new float[4];
97 gl.glMaterialfv(face, javax.media.opengl.GL.GL_SPECULAR, this.specular.getRGBComponents(rgba), 0);
98 gl.glMaterialfv(face, javax.media.opengl.GL.GL_DIFFUSE, this.diffuse.getRGBComponents(rgba), 0);
99 gl.glMaterialfv(face, javax.media.opengl.GL.GL_AMBIENT, this.ambient.getRGBComponents(rgba), 0);
100 gl.glMaterialf(face, javax.media.opengl.GL.GL_SHININESS, this.shininess);
101 gl.glMaterialfv(face, javax.media.opengl.GL.GL_EMISSION, this.emission.getRGBComponents(rgba), 0);