Fixed ColorRGBA javadoc, made the clamp method use FastMath.clamp, integrated @kwando's pull request 131

experimental
Nehon 11 years ago
parent 95f215c180
commit c09a4b208d
  1. 2
      jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java
  2. 56
      jme3-core/src/main/java/com/jme3/math/ColorRGBA.java
  3. 2
      jme3-examples/src/main/java/jme3test/material/TestColoredTexture.java

@ -953,7 +953,7 @@ public class ParticleEmitter extends Geometry {
// affecting color, size and angle // affecting color, size and angle
float b = (p.startlife - p.life) / p.startlife; float b = (p.startlife - p.life) / p.startlife;
p.color.interpolate(startColor, endColor, b); p.color.interpolateLocal(startColor, endColor, b);
p.size = FastMath.interpolateLinear(b, startSize, endSize); p.size = FastMath.interpolateLinear(b, startSize, endSize);
p.angle += p.rotateSpeed * tpf; p.angle += p.rotateSpeed * tpf;

@ -35,14 +35,7 @@ import java.io.IOException;
/** /**
* <code>ColorRGBA</code> defines a color made from a collection of red, green * <code>ColorRGBA</code> defines a color made from a collection of red, green
* and blue values stored in Linear color space. An alpha value determines is * and blue values stored in Linear color space. An alpha value determines is
* transparency. All values must be between 0 and 1. If any value is set higher * transparency.
* or lower than these constraints they are clamped to the min or max. That is,
* if a value smaller than zero is set the value clamps to zero. If a value
* higher than 1 is passed, that value is clamped to 1. However, because the
* attributes r, g, b, a are public for efficiency reasons, they can be directly
* modified with invalid values. The client should take care when directly
* addressing the values. A call to clamp will assure that the values are within
* the constraints.
* *
* @author Mark Powell * @author Mark Powell
* @version $Id: ColorRGBA.java,v 1.29 2007/09/09 18:25:14 irrisor Exp $ * @version $Id: ColorRGBA.java,v 1.29 2007/09/09 18:25:14 irrisor Exp $
@ -139,8 +132,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/** /**
* Constructor instantiates a new <code>ColorRGBA</code> object. The * Constructor instantiates a new <code>ColorRGBA</code> object. The
* values are defined as passed parameters. These values are then clamped * values are defined as passed parameters.
* to insure that they are between 0 and 1.
* these values are assumed to be in linear space and stored as is. * these values are assumed to be in linear space and stored as is.
* If you want to assign sRGB values use * If you want to assign sRGB values use
* {@link ColorRGBA#setAsSrgb(float, float, float, float) } * {@link ColorRGBA#setAsSrgb(float, float, float, float) }
@ -169,8 +161,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
} }
/** /**
* <code>set</code> sets the RGBA values of this <code>ColorRGBA</code>. The * <code>set</code> sets the RGBA values of this <code>ColorRGBA</code>.
* values are then clamped to insure that they are between 0 and 1.
* these values are assumed to be in linear space and stored as is. * these values are assumed to be in linear space and stored as is.
* If you want to assign sRGB values use * If you want to assign sRGB values use
* {@link ColorRGBA#setAsSrgb(float, float, float, float) } * {@link ColorRGBA#setAsSrgb(float, float, float, float) }
@ -212,34 +203,13 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
} }
/** /**
* <code>clamp</code> insures that all values are between 0 and 1. If any * Saturate that color ensuring all channels have a value between 0 and 1
* are less than 0 they are set to zero. If any are more than 1 they are
* set to one.
*/ */
public void clamp() { public void clamp() {
if (r < 0) { FastMath.clamp(r, 0f, 1f);
r = 0; FastMath.clamp(g, 0f, 1f);
} else if (r > 1) { FastMath.clamp(b, 0f, 1f);
r = 1; FastMath.clamp(a, 0f, 1f);
}
if (g < 0) {
g = 0;
} else if (g > 1) {
g = 1;
}
if (b < 0) {
b = 0;
} else if (b > 1) {
b = 1;
}
if (a < 0) {
a = 0;
} else if (a > 1) {
a = 1;
}
} }
/** /**
@ -305,12 +275,14 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
* @param finalColor The final color to interpolate towards. * @param finalColor The final color to interpolate towards.
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage * @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from this towards finalColor. * change from this towards finalColor.
* @return this ColorRGBA
*/ */
public void interpolate(ColorRGBA finalColor, float changeAmnt) { public ColorRGBA interpolateLocal(ColorRGBA finalColor, float changeAmnt) {
this.r = (1 - changeAmnt) * this.r + changeAmnt * finalColor.r; this.r = (1 - changeAmnt) * this.r + changeAmnt * finalColor.r;
this.g = (1 - changeAmnt) * this.g + changeAmnt * finalColor.g; this.g = (1 - changeAmnt) * this.g + changeAmnt * finalColor.g;
this.b = (1 - changeAmnt) * this.b + changeAmnt * finalColor.b; this.b = (1 - changeAmnt) * this.b + changeAmnt * finalColor.b;
this.a = (1 - changeAmnt) * this.a + changeAmnt * finalColor.a; this.a = (1 - changeAmnt) * this.a + changeAmnt * finalColor.a;
return this;
} }
/** /**
@ -321,12 +293,14 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
* @param finalColor The final color to interpolate towards (changeAmnt=1). * @param finalColor The final color to interpolate towards (changeAmnt=1).
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage * @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from beginColor towards finalColor. * change from beginColor towards finalColor.
* @return this ColorRGBA
*/ */
public void interpolate(ColorRGBA beginColor, ColorRGBA finalColor, float changeAmnt) { public ColorRGBA interpolateLocal(ColorRGBA beginColor, ColorRGBA finalColor, float changeAmnt) {
this.r = (1 - changeAmnt) * beginColor.r + changeAmnt * finalColor.r; this.r = (1 - changeAmnt) * beginColor.r + changeAmnt * finalColor.r;
this.g = (1 - changeAmnt) * beginColor.g + changeAmnt * finalColor.g; this.g = (1 - changeAmnt) * beginColor.g + changeAmnt * finalColor.g;
this.b = (1 - changeAmnt) * beginColor.b + changeAmnt * finalColor.b; this.b = (1 - changeAmnt) * beginColor.b + changeAmnt * finalColor.b;
this.a = (1 - changeAmnt) * beginColor.a + changeAmnt * finalColor.a; this.a = (1 - changeAmnt) * beginColor.a + changeAmnt * finalColor.a;
return this;
} }
/** /**
@ -487,7 +461,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
hash += 37 * hash + Float.floatToIntBits(a); hash += 37 * hash + Float.floatToIntBits(a);
return hash; return hash;
} }
public void write(JmeExporter e) throws IOException { public void write(JmeExporter e) throws IOException {
OutputCapsule capsule = e.getCapsule(this); OutputCapsule capsule = e.getCapsule(this);
capsule.write(r, "r", 0); capsule.write(r, "r", 0);

@ -75,7 +75,7 @@ public class TestColoredTexture extends SimpleApplication {
nextColor = ColorRGBA.randomColor(); nextColor = ColorRGBA.randomColor();
} }
ColorRGBA currentColor = new ColorRGBA(); ColorRGBA currentColor = new ColorRGBA();
currentColor.interpolate(prevColor, nextColor, time); currentColor.interpolateLocal(prevColor, nextColor, time);
mat.setColor("Color", currentColor); mat.setColor("Color", currentColor);
} }

Loading…
Cancel
Save