|
|
|
@ -42,7 +42,6 @@ import java.io.IOException; |
|
|
|
|
* @version $Id: ColorRGBA.java,v 1.29 2007/09/09 18:25:14 irrisor Exp $ |
|
|
|
|
*/ |
|
|
|
|
public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable { |
|
|
|
|
|
|
|
|
|
static final float GAMMA = 2.2f; |
|
|
|
|
|
|
|
|
|
static final long serialVersionUID = 1; |
|
|
|
@ -137,6 +136,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* these values are assumed to be in linear space and stored as is. |
|
|
|
|
* If you want to assign sRGB values use |
|
|
|
|
* {@link ColorRGBA#setAsSrgb(float, float, float, float) } |
|
|
|
|
* |
|
|
|
|
* @param r The red component of this color. |
|
|
|
|
* @param g The green component of this <code>ColorRGBA</code>. |
|
|
|
|
* @param b The blue component of this <code>ColorRGBA</code>. |
|
|
|
@ -152,6 +152,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
/** |
|
|
|
|
* Copy constructor creates a new <code>ColorRGBA</code> object, based on |
|
|
|
|
* a provided color. |
|
|
|
|
* |
|
|
|
|
* @param rgba The <code>ColorRGBA</code> object to copy. |
|
|
|
|
*/ |
|
|
|
|
public ColorRGBA(ColorRGBA rgba) { |
|
|
|
@ -217,6 +218,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* <code>getColorArray</code> retrieves the color values of this |
|
|
|
|
* <code>ColorRGBA</code> as a four element <code>float</code> array in the |
|
|
|
|
* order: r,g,b,a. |
|
|
|
|
* |
|
|
|
|
* @return The <code>float</code> array that contains the color components. |
|
|
|
|
*/ |
|
|
|
|
public float[] getColorArray() { |
|
|
|
@ -226,6 +228,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
/** |
|
|
|
|
* Stores the current r,g,b,a values into the given array. The given array must have a |
|
|
|
|
* length of 4 or greater, or an array index out of bounds exception will be thrown. |
|
|
|
|
* |
|
|
|
|
* @param store The <code>float</code> array to store the values into. |
|
|
|
|
* @return The <code>float</code> array after storage. |
|
|
|
|
*/ |
|
|
|
@ -239,6 +242,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieves the alpha component value of this <code>ColorRGBA</code>. |
|
|
|
|
* |
|
|
|
|
* @return The alpha component value. |
|
|
|
|
*/ |
|
|
|
|
public float getAlpha() { |
|
|
|
@ -247,6 +251,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieves the red component value of this <code>ColorRGBA</code>. |
|
|
|
|
* |
|
|
|
|
* @return The red component value. |
|
|
|
|
*/ |
|
|
|
|
public float getRed() { |
|
|
|
@ -255,6 +260,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieves the blue component value of this <code>ColorRGBA</code>. |
|
|
|
|
* |
|
|
|
|
* @return The blue component value. |
|
|
|
|
*/ |
|
|
|
|
public float getBlue() { |
|
|
|
@ -263,6 +269,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieves the green component value of this <code>ColorRGBA</code>. |
|
|
|
|
* |
|
|
|
|
* @return The green component value. |
|
|
|
|
*/ |
|
|
|
|
public float getGreen() { |
|
|
|
@ -273,6 +280,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Sets this <code>ColorRGBA</code> to the interpolation by changeAmnt from |
|
|
|
|
* this to the finalColor: |
|
|
|
|
* this=(1-changeAmnt)*this + changeAmnt * finalColor |
|
|
|
|
* |
|
|
|
|
* @param finalColor The final color to interpolate towards. |
|
|
|
|
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage |
|
|
|
|
* change from this towards finalColor. |
|
|
|
@ -290,6 +298,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Sets this <code>ColorRGBA</code> to the interpolation by changeAmnt from |
|
|
|
|
* beginColor to finalColor: |
|
|
|
|
* this=(1-changeAmnt)*beginColor + changeAmnt * finalColor |
|
|
|
|
* |
|
|
|
|
* @param beginColor The beginning color (changeAmnt=0). |
|
|
|
|
* @param finalColor The final color to interpolate towards (changeAmnt=1). |
|
|
|
|
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage |
|
|
|
@ -307,6 +316,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
/** |
|
|
|
|
* <code>randomColor</code> is a utility method that generates a random |
|
|
|
|
* opaque color. |
|
|
|
|
* |
|
|
|
|
* @return a random <code>ColorRGBA</code> with an alpha set to 1. |
|
|
|
|
*/ |
|
|
|
|
public static ColorRGBA randomColor() { |
|
|
|
@ -321,6 +331,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Multiplies each r,g,b,a of this <code>ColorRGBA</code> by the corresponding |
|
|
|
|
* r,g,b,a of the given color and returns the result as a new <code>ColorRGBA</code>. |
|
|
|
|
* Used as a way of combining colors and lights. |
|
|
|
|
* |
|
|
|
|
* @param c The color to multiply by. |
|
|
|
|
* @return The new <code>ColorRGBA</code>. this*c |
|
|
|
|
*/ |
|
|
|
@ -332,6 +343,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Multiplies each r,g,b,a of this <code>ColorRGBA</code> by the given scalar and |
|
|
|
|
* returns the result as a new <code>ColorRGBA</code>. |
|
|
|
|
* Used as a way of making colors dimmer or brighter. |
|
|
|
|
* |
|
|
|
|
* @param scalar The scalar to multiply by. |
|
|
|
|
* @return The new <code>ColorRGBA</code>. this*scalar |
|
|
|
|
*/ |
|
|
|
@ -343,6 +355,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Multiplies each r,g,b,a of this <code>ColorRGBA</code> by the given scalar and |
|
|
|
|
* returns the result (this). |
|
|
|
|
* Used as a way of making colors dimmer or brighter. |
|
|
|
|
* |
|
|
|
|
* @param scalar The scalar to multiply by. |
|
|
|
|
* @return this*c |
|
|
|
|
*/ |
|
|
|
@ -358,6 +371,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Adds each r,g,b,a of this <code>ColorRGBA</code> by the corresponding |
|
|
|
|
* r,g,b,a of the given color and returns the result as a new <code>ColorRGBA</code>. |
|
|
|
|
* Used as a way of combining colors and lights. |
|
|
|
|
* |
|
|
|
|
* @param c The color to add. |
|
|
|
|
* @return The new <code>ColorRGBA</code>. this+c |
|
|
|
|
*/ |
|
|
|
@ -369,6 +383,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Adds each r,g,b,a of this <code>ColorRGBA</code> by the r,g,b,a the given |
|
|
|
|
* color and returns the result (this). |
|
|
|
|
* Used as a way of combining colors and lights. |
|
|
|
|
* |
|
|
|
|
* @param c The color to add. |
|
|
|
|
* @return this+c |
|
|
|
|
*/ |
|
|
|
@ -381,6 +396,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* <code>toString</code> returns the string representation of this <code>ColorRGBA</code>. |
|
|
|
|
* The format of the string is:<br> |
|
|
|
|
* Color[R.RRRR, G.GGGG, B.BBBB, A.AAAA] |
|
|
|
|
* |
|
|
|
|
* @return The string representation of this <code>ColorRGBA</code>. |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
@ -404,6 +420,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Saves this <code>ColorRGBA</code> into the given <code>float</code> array. |
|
|
|
|
* |
|
|
|
|
* @param floats The <code>float</code> array to take this <code>ColorRGBA</code>. |
|
|
|
|
* If null, a new <code>float[4]</code> is created. |
|
|
|
|
* @return The array, with r,g,b,a float values in that order. |
|
|
|
@ -423,6 +440,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* <code>equals</code> returns true if this <code>ColorRGBA</code> is logically equivalent |
|
|
|
|
* to a given color. That is, if all the components of the two colors are the same. |
|
|
|
|
* False is returned otherwise. |
|
|
|
|
* |
|
|
|
|
* @param o The object to compare against. |
|
|
|
|
* @return true if the colors are equal, false otherwise. |
|
|
|
|
*/ |
|
|
|
@ -456,6 +474,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* <code>hashCode</code> returns a unique code for this <code>ColorRGBA</code> based |
|
|
|
|
* on its values. If two colors are logically equivalent, they will return |
|
|
|
|
* the same hash code value. |
|
|
|
|
* |
|
|
|
|
* @return The hash code value of this <code>ColorRGBA</code>. |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
@ -499,9 +518,11 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
b = capsule.readFloat("b", 0); |
|
|
|
|
a = capsule.readFloat("a", 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieves the component values of this <code>ColorRGBA</code> as |
|
|
|
|
* a four element <code>byte</code> array in the order: r,g,b,a. |
|
|
|
|
* |
|
|
|
|
* @return the <code>byte</code> array that contains the color components. |
|
|
|
|
*/ |
|
|
|
|
public byte[] asBytesRGBA() { |
|
|
|
@ -517,6 +538,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Retrieves the component values of this <code>ColorRGBA</code> as an |
|
|
|
|
* <code>int</code> in a,r,g,b order. |
|
|
|
|
* Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue. |
|
|
|
|
* |
|
|
|
|
* @return The integer representation of this <code>ColorRGBA</code> in a,r,g,b order. |
|
|
|
|
*/ |
|
|
|
|
public int asIntARGB() { |
|
|
|
@ -531,6 +553,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Retrieves the component values of this <code>ColorRGBA</code> as an |
|
|
|
|
* <code>int</code> in r,g,b,a order. |
|
|
|
|
* Bits 24-31 are red, 16-23 are green, 8-15 are blue, 0-7 are alpha. |
|
|
|
|
* |
|
|
|
|
* @return The integer representation of this <code>ColorRGBA</code> in r,g,b,a order. |
|
|
|
|
*/ |
|
|
|
|
public int asIntRGBA() { |
|
|
|
@ -540,10 +563,12 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
| (((int) (a * 255) & 0xFF)); |
|
|
|
|
return rgba; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieves the component values of this <code>ColorRGBA</code> as an |
|
|
|
|
* <code>int</code> in a,b,g,r order. |
|
|
|
|
* Bits 24-31 are alpha, 16-23 are blue, 8-15 are green, 0-7 are red. |
|
|
|
|
* |
|
|
|
|
* @return The integer representation of this <code>ColorRGBA</code> in a,b,g,r order. |
|
|
|
|
*/ |
|
|
|
|
public int asIntABGR() { |
|
|
|
@ -553,10 +578,12 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
| (((int) (r * 255) & 0xFF)); |
|
|
|
|
return abgr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets the component values of this <code>ColorRGBA</code> with the given |
|
|
|
|
* combined ARGB <code>int</code>. |
|
|
|
|
* Bits 24-31 are alpha, bits 16-23 are red, bits 8-15 are green, bits 0-7 are blue. |
|
|
|
|
* |
|
|
|
|
* @param color The integer ARGB value used to set this <code>ColorRGBA</code>. |
|
|
|
|
* @return this |
|
|
|
|
*/ |
|
|
|
@ -567,9 +594,11 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
b = ((byte) (color) & 0xFF) / 255f; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets the RGBA values of this <code>ColorRGBA</code> with the given combined RGBA value |
|
|
|
|
* Bits 24-31 are red, bits 16-23 are green, bits 8-15 are blue, bits 0-7 are alpha. |
|
|
|
|
* |
|
|
|
|
* @param color The integer RGBA value used to set this object. |
|
|
|
|
* @return this |
|
|
|
|
*/ |
|
|
|
@ -580,9 +609,11 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
a = ((byte) (color) & 0xFF) / 255f; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets the RGBA values of this <code>ColorRGBA</code> with the given combined ABGR value |
|
|
|
|
* Bits 24-31 are alpha, bits 16-23 are blue, bits 8-15 are green, bits 0-7 are red. |
|
|
|
|
* |
|
|
|
|
* @param color The integer ABGR value used to set this object. |
|
|
|
|
* @return this |
|
|
|
|
*/ |
|
|
|
@ -598,6 +629,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Transform this <code>ColorRGBA</code> to a <code>Vector3f</code> using |
|
|
|
|
* x = r, y = g, z = b. The Alpha value is not used. |
|
|
|
|
* This method is useful for shader assignments. |
|
|
|
|
* |
|
|
|
|
* @return A <code>Vector3f</code> containing the RGB value of this <code>ColorRGBA</code>. |
|
|
|
|
*/ |
|
|
|
|
public Vector3f toVector3f() { |
|
|
|
@ -608,6 +640,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
* Transform this <code>ColorRGBA</code> to a <code>Vector4f</code> using |
|
|
|
|
* x = r, y = g, z = b, w = a. |
|
|
|
|
* This method is useful for shader assignments. |
|
|
|
|
* |
|
|
|
|
* @return A <code>Vector4f</code> containing the RGBA value of this <code>ColorRGBA</code>. |
|
|
|
|
*/ |
|
|
|
|
public Vector4f toVector4f() { |
|
|
|
@ -666,5 +699,4 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable |
|
|
|
|
srgb.a = a; |
|
|
|
|
return srgb; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|