]> gerrit.simantics Code Review - simantics/3d.git/blob - javax.vecmath/src/javax/vecmath/Color3f.java
Included old javax.vecmath 1.5.2 to org.simantics.g3d.feature
[simantics/3d.git] / javax.vecmath / src / javax / vecmath / Color3f.java
1 /*
2  * $RCSfile: Color3f.java,v $
3  *
4  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
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.
12  *
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).
18  *
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.
22  *
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
25  * have any questions.
26  *
27  * $Revision: 1.6 $
28  * $Date: 2008/02/28 20:18:50 $
29  * $State: Exp $
30  */
31
32 package javax.vecmath;
33
34 import java.awt.Color;
35
36
37 /**
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].
42  * <p>
43  * Java 3D assumes that a linear (gamma-corrected) visual is used for
44  * all colors.
45  *
46  */
47 public class Color3f extends Tuple3f implements java.io.Serializable {
48
49     // Compatible with 1.1
50     static final long serialVersionUID = -1861792981817493659L;
51
52     /**
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
57      */
58     public Color3f(float x, float y, float z) {
59         super(x,y,z);
60     }
61
62
63     /**
64      * Constructs and initializes a Color3f from the array of length 3.
65      * @param v the array of length 3 containing xyz in order
66      */
67     public Color3f(float[] v) {
68         super(v);
69     }
70
71
72     /**
73      * Constructs and initializes a Color3f from the specified Color3f.
74      * @param v1 the Color3f containing the initialization x y z data
75      */
76     public Color3f(Color3f v1) {
77         super(v1);
78     }
79
80
81     /**
82      * Constructs and initializes a Color3f from the specified Tuple3f.
83      * @param t1 the Tuple3f containing the initialization x y z data
84      */
85     public Color3f(Tuple3f t1) {
86         super(t1);
87     }
88
89
90     /**
91      * Constructs and initializes a Color3f from the specified Tuple3d.
92      * @param t1 the Tuple3d containing the initialization x y z data
93      */
94     public Color3f(Tuple3d t1) {
95         super(t1);
96     }
97
98
99     /**
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
103      * gamma correction.
104      *
105      * @param color the AWT color with which to initialize this
106      * Color3f object
107      *
108      * @since vecmath 1.2
109      */
110     public Color3f(Color color) {
111         super((float)color.getRed() / 255.0f,
112               (float)color.getGreen() / 255.0f,
113               (float)color.getBlue() / 255.0f);
114     }
115
116
117     /**
118      * Constructs and initializes a Color3f to (0.0, 0.0, 0.0).
119      */
120     public Color3f() {
121         super();
122     }
123
124
125     /**
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
129      * gamma correction.
130      *
131      * @param color the AWT color to copy into this Color3f object
132      *
133      * @since vecmath 1.2
134      */
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;
139     }
140
141
142     /**
143      * Returns a new AWT color object initialized with the r,g,b
144      * values of this Color3f object.
145      *
146      * @return a new AWT Color object
147      *
148      * @since vecmath 1.2
149      */
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);
154
155         return new Color(r, g, b);
156     }
157
158 }