[JME 2.X] new method for ColorRGBA class

Hi,

is it possible to add a new method to the ColorRGBA class? if yes how?



this would be:

   /**
    * Change this color by increasing or decreasing it by a factor of an other color:
    * this = this + multiplier * stepColor
    *
    * This can be helpful to implement efficiently color transitions.
    *
    * @param stepColor The step color to add
    * @param multiplier A multiplier to apply on the step color
    */
   public void transition( final ColorRGBA stepColor, final float multiplier ) {
      this.r = this.r + multiplier * stepColor.r;
      this.g = this.g + multiplier * stepColor.g;
      this.b = this.b + multiplier * stepColor.b;
      this.a = this.a + multiplier * stepColor.a;
   }



Note that the name is free. :)

N.

Basically an interpolate method?

Yes one more but I found interpolate not appropriate since it relates to something but here we don't give this something/target to the method, just one step (multiplied by a variable amount).

The other reason is that its signature clashes with this one:


public void interpolate(ColorRGBA beginColor,ColorRGBA finalColor,float changeAmnt)

  :(

Well, I'm currently working on a MaterialTransitionController and the way I designed it need this method. Now, I'll give it a try to use this already existing method and decide afterwards :wink:

Okay, I can see two cons:

  • firstly, when using original interpolate method, I need to keep the final material immutable during all the time of the transition => I can't use it as a mutable Material (can live with that though)
  • secondly, there is less computation (but it should be ok): the (1-changeAmnt)*this thing is not useful for me.



    one pro:
  • less variables to handle internally by the controller



    I'll check the time needed but I may not need this new method…