2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
;
13 * @version $Id: Material.java 1175 2007-03-07 21:16:55Z tgaskins $
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
;
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()
73 public Color
getDiffuse()
78 public Color
getAmbient()
83 public Color
getEmission()
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);