2 * $RCSfile: Color4f.java,v $
4 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 * This code is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 only, as
9 * published by the Free Software Foundation. Sun designates this
10 * particular file as subject to the "Classpath" exception as provided
11 * by Sun in the LICENSE file that accompanied this code.
13 * This code is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * version 2 for more details (a copy is included in the LICENSE file that
17 * accompanied this code).
19 * You should have received a copy of the GNU General Public License version
20 * 2 along with this work; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 * CA 95054 USA or visit www.sun.com if you need additional information or
28 * $Date: 2008/02/28 20:18:50 $
32 package javax.vecmath;
34 import java.awt.Color;
38 * A four-element color represented by single precision floating point
39 * x, y, z, and w values. The x, y, z, and w values represent the red,
40 * blue, green, and alpha color values, respectively. Color and alpha
41 * components should be in the range [0.0, 1.0].
43 * Java 3D assumes that a linear (gamma-corrected) visual is used for
47 public class Color4f extends Tuple4f implements java.io.Serializable {
49 // Compatible with 1.1
50 static final long serialVersionUID = 8577680141580006740L;
53 * Constructs and initializes a Color4f from the specified xyzw
55 * @param x the red color value
56 * @param y the green color value
57 * @param z the blue color value
58 * @param w the alpha value
60 public Color4f(float x, float y, float z, float w) {
66 * Constructs and initializes a Color4f from the array of length 4.
67 * @param c the array of length 4 containing r,g,b,a in order
69 public Color4f(float[] c) {
75 * Constructs and initializes a Color4f from the specified Color4f.
76 * @param c1 the Color4f containing the initialization r,g,b,a data
78 public Color4f(Color4f c1) {
84 * Constructs and initializes a Color4f from the specified Tuple4f.
85 * @param t1 the Tuple4f containing the initialization r,g,b,a data
87 public Color4f(Tuple4f t1) {
93 * Constructs and initializes a Color4f from the specified Tuple4d.
94 * @param t1 the Tuple4d containing the initialization r,g,b,a data
96 public Color4f(Tuple4d t1) {
102 * Constructs and initializes a Color4f from the specified AWT
104 * No conversion is done on the color to compensate for
107 * @param color the AWT color with which to initialize this
112 public Color4f(Color color) {
113 super((float)color.getRed() / 255.0f,
114 (float)color.getGreen() / 255.0f,
115 (float)color.getBlue() / 255.0f,
116 (float)color.getAlpha() / 255.0f);
121 * Constructs and initializes a Color4f to (0.0, 0.0, 0.0, 0.0).
129 * Sets the r,g,b,a values of this Color4f object to those of the
130 * specified AWT Color object.
131 * No conversion is done on the color to compensate for
134 * @param color the AWT color to copy into this Color4f object
138 public final void set(Color color) {
139 x = (float)color.getRed() / 255.0f;
140 y = (float)color.getGreen() / 255.0f;
141 z = (float)color.getBlue() / 255.0f;
142 w = (float)color.getAlpha() / 255.0f;
147 * Returns a new AWT color object initialized with the r,g,b,a
148 * values of this Color4f object.
150 * @return a new AWT Color object
154 public final Color get() {
155 int r = Math.round(x * 255.0f);
156 int g = Math.round(y * 255.0f);
157 int b = Math.round(z * 255.0f);
158 int a = Math.round(w * 255.0f);
160 return new Color(r, g, b, a);