📄 colorrgba.java
字号:
* Stores the current r/g/b/a values into the tempf array. The tempf array must have a
* length of 4 or greater, or an array index out of bounds exception will be thrown.
* @param store The array of floats to store the values into.
* @return The float[] after storage.
*/
public float[] getColorArray(float[] store) {
store[0]=r;
store[1]=g;
store[2]=b;
store[3]=a;
return store;
}
/**
* Sets this color 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 precentage
* change from this towards finalColor
*/
public void interpolate(ColorRGBA finalColor,float changeAmnt){
this.r=(1-changeAmnt)*this.r + changeAmnt*finalColor.r;
this.g=(1-changeAmnt)*this.g + changeAmnt*finalColor.g;
this.b=(1-changeAmnt)*this.b + changeAmnt*finalColor.b;
this.a=(1-changeAmnt)*this.a + changeAmnt*finalColor.a;
}
/**
* Sets this color to the interpolation by changeAmnt from beginColor to finalColor
* this=(1-changeAmnt)*beginColor + changeAmnt * finalColor
* @param beginColor The begining color (changeAmnt=0)
* @param finalColor The final color to interpolate towards (changeAmnt=1)
* @param changeAmnt An amount between 0.0 - 1.0 representing a precentage
* change from beginColor towards finalColor
*/
public void interpolate(ColorRGBA beginColor,ColorRGBA finalColor,float changeAmnt){
this.r=(1-changeAmnt)*beginColor.r + changeAmnt*finalColor.r;
this.g=(1-changeAmnt)*beginColor.g + changeAmnt*finalColor.g;
this.b=(1-changeAmnt)*beginColor.b + changeAmnt*finalColor.b;
this.a=(1-changeAmnt)*beginColor.a + changeAmnt*finalColor.a;
}
/**
*
* <code>randomColor</code> is a utility method that generates a random
* color.
*
* @return a random color.
*/
public static ColorRGBA randomColor() {
ColorRGBA rVal = new ColorRGBA(0, 0, 0, 1);
rVal.r = FastMath.nextRandomFloat();
rVal.g = FastMath.nextRandomFloat();
rVal.b = FastMath.nextRandomFloat();
rVal.clamp();
return rVal;
}
/**
* Multiplies each r/g/b/a of this color by the r/g/b/a of the given color and
* returns the result as a new ColorRGBA. Used as a way of combining colors and lights.
* @param c The color to multiply.
* @return The new ColorRGBA. this*c
*/
public ColorRGBA mult(ColorRGBA c) {
return new ColorRGBA(c.r * r, c.g * g, c.b * b, c.a * a);
}
/**
* Multiplies each r/g/b/a of this color by the r/g/b/a of the given color and
* returns the result as a new ColorRGBA. Used as a way of combining colors and lights.
* @param scalar scalar to multiply with
* @return The new ColorRGBA. this*c
*/
public ColorRGBA multLocal(float scalar) {
this.r *= scalar;
this.g *= scalar;
this.b *= scalar;
this.a *= scalar;
return this;
}
/**
* Adds each r/g/b/a of this color by the r/g/b/a of the given color and
* returns the result as a new ColorRGBA.
* @param c The color to add.
* @return The new ColorRGBA. this+c
*/
public ColorRGBA add(ColorRGBA c) {
return new ColorRGBA(c.r + r, c.g + g, c.b + b, c.a + a);
}
/**
* Multiplies each r/g/b/a of this color by the r/g/b/a of the given color and
* returns the result as a new ColorRGBA. Used as a way of combining colors and lights.
* @param c The color to multiply.
* @return The new ColorRGBA. this*c
*/
public ColorRGBA addLocal(ColorRGBA c) {
set(c.r + r, c.g + g, c.b + b, c.a + a);
return this;
}
/**
* <code>toString</code> returns the string representation of this color.
* The format of the string is:<br>
* com.jme.ColorRGBA: [R=RR.RRRR, G=GG.GGGG, B=BB.BBBB, A=AA.AAAA]
* @return the string representation of this color.
*/
public String toString() {
return "com.jme.renderer.ColorRGBA: [R="+r+", G="+g+", B="+b+", A="+a+"]";
}
@Override
public ColorRGBA clone() {
try {
return (ColorRGBA) super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError(); // can not happen
}
}
/**
* Saves this ColorRGBA into the given float[] object.
*
* @param floats
* The float[] to take this ColorRGBA. If null, a new float[4] is
* created.
* @return The array, with R, G, B, A float values in that order
*/
public float[] toArray(float[] floats) {
if (floats == null) {
floats = new float[4];
}
floats[0] = r;
floats[1] = g;
floats[2] = b;
floats[3] = a;
return floats;
}
/**
* <code>equals</code> returns true if this color is logically equivalent
* to a given color. That is, if the values of the two colors are the same.
* False is returned otherwise.
* @param o the object to compare againts.
* @return true if the colors are equal, false otherwise.
*/
public boolean equals(Object o) {
if( !(o instanceof ColorRGBA) ) {
return false;
}
if(this == o) {
return true;
}
ColorRGBA comp = (ColorRGBA)o;
if (Float.compare(r, comp.r) != 0) return false;
if (Float.compare(g, comp.g) != 0) return false;
if (Float.compare(b, comp.b) != 0) return false;
if (Float.compare(a, comp.a) != 0) return false;
return true;
}
/**
* <code>hashCode</code> returns a unique code for this color object based
* on it's values. If two colors are logically equivalent, they will return
* the same hash code value.
* @return the hash code value of this color.
*/
public int hashCode() {
int hash = 37;
hash += 37 * hash + Float.floatToIntBits(r);
hash += 37 * hash + Float.floatToIntBits(g);
hash += 37 * hash + Float.floatToIntBits(b);
hash += 37 * hash + Float.floatToIntBits(a);
return hash;
}
/**
* Used with serialization. Not to be called manually.
* @param in where to read from
* @throws IOException
* @throws ClassNotFoundException
* @see java.io.Externalizable
*/
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
r=in.readFloat();
g=in.readFloat();
b=in.readFloat();
a=in.readFloat();
}
/**
* Used with serialization. Not to be called manually. *
* @param out where to write to
* @throws IOException
* @see java.io.Externalizable
*/
public void writeExternal(ObjectOutput out) throws IOException {
out.writeFloat(r);
out.writeFloat(g);
out.writeFloat(b);
out.writeFloat(a);
}
public void write(JMEExporter e) throws IOException {
OutputCapsule capsule = e.getCapsule(this);
capsule.write(r, "r", 0);
capsule.write(g, "g", 0);
capsule.write(b, "b", 0);
capsule.write(a, "a", 0);
}
public void read(JMEImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this);
r = capsule.readFloat("r", 0);
g = capsule.readFloat("g", 0);
b = capsule.readFloat("b", 0);
a = capsule.readFloat("a", 0);
}
public Class<? extends ColorRGBA> getClassTag() {
return this.getClass();
}
public int asIntARGB() {
int argb = (((int) (a * 255) & 0xFF) << 24)
| (((int) (r * 255) & 0xFF) << 16)
| (((int) (g * 255) & 0xFF) << 8)
| (((int) (b * 255) & 0xFF));
return argb;
}
public int asIntRGBA() {
int rgba = (((int) (r * 255) & 0xFF) << 24)
| (((int) (g * 255) & 0xFF) << 16)
| (((int) (b * 255) & 0xFF) << 8)
| (((int) (a * 255) & 0xFF));
return rgba;
}
public void fromIntARGB(int color) {
a = ((byte) (color >> 24) & 0xFF) / 255f;
r = ((byte) (color >> 16) & 0xFF) / 255f;
g = ((byte) (color >> 8) & 0xFF) / 255f;
b = ((byte) (color) & 0xFF) / 255f;
}
public void fromIntRGBA(int color) {
r = ((byte) (color >> 24) & 0xFF) / 255f;
g = ((byte) (color >> 16) & 0xFF) / 255f;
b = ((byte) (color >> 8) & 0xFF) / 255f;
a = ((byte) (color) & 0xFF) / 255f;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -