2 * $RCSfile: Color3f.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 three-element color value represented by single precision floating
39 * point x,y,z values. The x,y,z values represent the red, green, and
40 * blue color values, respectively. Color components should be in the
41 * range of [0.0, 1.0].
43 * Java 3D assumes that a linear (gamma-corrected) visual is used for
47 public class Color3f extends Tuple3f implements java.io.Serializable {
49 // Compatible with 1.1
50 static final long serialVersionUID = -1861792981817493659L;
53 * Constructs and initializes a Color3f from the three xyz values.
54 * @param x the red color value
55 * @param y the green color value
56 * @param z the blue color value
58 public Color3f(float x, float y, float z) {
64 * Constructs and initializes a Color3f from the array of length 3.
65 * @param v the array of length 3 containing xyz in order
67 public Color3f(float[] v) {
73 * Constructs and initializes a Color3f from the specified Color3f.
74 * @param v1 the Color3f containing the initialization x y z data
76 public Color3f(Color3f v1) {
82 * Constructs and initializes a Color3f from the specified Tuple3f.
83 * @param t1 the Tuple3f containing the initialization x y z data
85 public Color3f(Tuple3f t1) {
91 * Constructs and initializes a Color3f from the specified Tuple3d.
92 * @param t1 the Tuple3d containing the initialization x y z data
94 public Color3f(Tuple3d t1) {
100 * Constructs and initializes a Color3f from the specified AWT
101 * Color object. The alpha value of the AWT color is ignored.
102 * No conversion is done on the color to compensate for
105 * @param color the AWT color with which to initialize this
110 public Color3f(Color color) {
111 super((float)color.getRed() / 255.0f,
112 (float)color.getGreen() / 255.0f,
113 (float)color.getBlue() / 255.0f);
118 * Constructs and initializes a Color3f to (0.0, 0.0, 0.0).
126 * Sets the r,g,b values of this Color3f object to those of the
127 * specified AWT Color object.
128 * No conversion is done on the color to compensate for
131 * @param color the AWT color to copy into this Color3f object
135 public final void set(Color color) {
136 x = (float)color.getRed() / 255.0f;
137 y = (float)color.getGreen() / 255.0f;
138 z = (float)color.getBlue() / 255.0f;
143 * Returns a new AWT color object initialized with the r,g,b
144 * values of this Color3f object.
146 * @return a new AWT Color object
150 public final Color get() {
151 int r = Math.round(x * 255.0f);
152 int g = Math.round(y * 255.0f);
153 int b = Math.round(z * 255.0f);
155 return new Color(r, g, b);