001/* 002 * JColor3f -- Represents a Java3D JColor3f tuple that can accept an AWT Color object. 003 * 004 * Copyright (C) 2023, by Joseph A. Huwaldt. 005 * All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public License 018 * along with this program; if not, write to the Free Software 019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 020 * Or visit: http://www.gnu.org/licenses/lgpl.html 021 */ 022package jahuwaldt.j3d; 023 024import java.awt.Color; 025import org.jogamp.vecmath.Tuple3d; 026import org.jogamp.vecmath.Tuple3f; 027 028 029/** 030 * A three-element color value represented by single precision floating 031 * point x,y,z values. The x,y,z values represent the red, green, and 032 * blue color values, respectively. Color components should be in the 033 * range of [0.0, 1.0]. 034 * <p> 035 * Java 3D assumes that a linear (gamma-corrected) visual is used for 036 * all colors. 037 * 038 */ 039public class JColor3f extends org.jogamp.vecmath.Color3f implements java.io.Serializable { 040 041 // Compatible with 1.1 042 static final long serialVersionUID = 1L; 043 044 /** 045 * Constructs and initializes a JColor3f from the three xyz values. 046 * @param x the red color value 047 * @param y the green color value 048 * @param z the blue color value 049 */ 050 public JColor3f(float x, float y, float z) { 051 super(x,y,z); 052 } 053 054 055 /** 056 * Constructs and initializes a JColor3f from the array of length 3. 057 * @param v the array of length 3 containing xyz in order 058 */ 059 public JColor3f(float[] v) { 060 super(v); 061 } 062 063 064 /** 065 * Constructs and initializes a JColor3f from the specified JColor3f. 066 * @param v1 the JColor3f containing the initialization x y z data 067 */ 068 public JColor3f(JColor3f v1) { 069 super(v1); 070 } 071 072 073 /** 074 * Constructs and initializes a JColor3f from the specified Tuple3f. 075 * @param t1 the Tuple3f containing the initialization x y z data 076 */ 077 public JColor3f(Tuple3f t1) { 078 super(t1); 079 } 080 081 082 /** 083 * Constructs and initializes a JColor3f from the specified Tuple3d. 084 * @param t1 the Tuple3d containing the initialization x y z data 085 */ 086 public JColor3f(Tuple3d t1) { 087 super(t1); 088 } 089 090 091 /** 092 * Constructs and initializes a JColor3f from the specified AWT 093 * Color object. The alpha value of the AWT color is ignored. 094 * No conversion is done on the color to compensate for 095 * gamma correction. 096 * 097 * @param color the AWT color with which to initialize this 098 * JColor3f object 099 * 100 * @since vecmath 1.2 101 */ 102 public JColor3f(Color color) { 103 super((float)color.getRed() / 255.0f, 104 (float)color.getGreen() / 255.0f, 105 (float)color.getBlue() / 255.0f); 106 } 107 108 109 /** 110 * Constructs and initializes a JColor3f to (0.0, 0.0, 0.0). 111 */ 112 public JColor3f() { 113 super(); 114 } 115 116 117 /** 118 * Sets the r,g,b values of this JColor3f object to those of the 119 * specified AWT Color object. 120 * No conversion is done on the color to compensate for 121 * gamma correction. 122 * 123 * @param color the AWT color to copy into this JColor3f object 124 * 125 * @since vecmath 1.2 126 */ 127 public final void set(Color color) { 128 x = (float)color.getRed() / 255.0f; 129 y = (float)color.getGreen() / 255.0f; 130 z = (float)color.getBlue() / 255.0f; 131 } 132 133 134 /** 135 * Returns a new AWT color object initialized with the r,g,b 136 * values of this JColor3f object. 137 * 138 * @return a new AWT Color object 139 * 140 * @since vecmath 1.2 141 */ 142 public final Color get() { 143 int r = Math.round(x * 255.0f); 144 int g = Math.round(y * 255.0f); 145 int b = Math.round(z * 255.0f); 146 147 return new Color(r, g, b); 148 } 149 150}