# ColorRGBA - what is mult and add?

Hi, very new here. Just want to say awesome work to everyone. I hope I can create some more tutorials as it is really lacking though.

I’m looking at ColorRGBA to figure out how it works.

1. What does mult do? I’ve read the description, but I don’t see it doing anything. I’ve changed Hello SimpleApplication to:

[java] flyCam.setMoveSpeed(10f);

ColorRGBA blue = ColorRGBA.Blue;

Box b = new Box(Vector3f.ZERO, 1, 1, 1);

Geometry geom = new Geometry(“Box”, b);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat.setColor(“m_Color”, blue);

geom.setMaterial(mat);

rootNode.attachChild(geom);

ColorRGBA random = ColorRGBA.randomColor();

ColorRGBA red = ColorRGBA.Red;

//blue.clone().interpolate(red, 0.5f);

blue.mult(red);

mat.setColor(“m_Color”, blue);[/java]

2. The description for multLocal and addLocal are the same? I don’t get it. One adds and the other multiplies. This is very confusing for me, especially since trying to find it out for myself doesn’t work like above 1). Can someone please explain?

[java] /**
• 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;

}

/**
• 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

*/

set(c.r + r, c.g + g, c.b + b, c.a + a);

return this;

}[/java]

Thanks! Sorry for asking stupid questions

Oh, addLocal() should of course read “Adds each r/g/b/a…” and it also doesnt return a new Color but the same. In your code you just use add() and not addLocal() and so the returned color would be the new color, not “blue”…

So you could do either

[java]ColorRGBA myNewColor = blue.mult(red);

mat.setColor(“m_Color”, myNewColor);

[/java]

or

[java]blue.multLocal(red);

mat.setColor(“m_Color”, blue);[/java]

1. the mult function return a new instance of ColorRGBA with the result of the multiplication while multLocal multiply directly the current instance of the object.

so this code

``` blue.mult(red); ```

does absolutely nothing. Use multLocal to have the result stored in the blue variable, or create another color variable like that :

``` ColorRGBA resultColor=blue.mult(red); ```

Be aware that multiplying blue by red will give you black (0.0,0.0,0.0,1.0).

2. this is a typo or a bad copy/paste, thank you to point that out, we’ll fix it.

As you can see in the source of the addLocal method adds the red, green, blue and alpha channels of the param color to the current instance of color.

Adding blue and red will give you purple (1.0,0.0,1.0,1.0)

hope that helps

EDIT : @Normen, did i told you, you are fast?

Thanks! That helps a lot. I didn’t understand the ‘Local’ variants, but now I get it.

One more question:

Hello Collision has this line for the directional light:

[java]dl.setColor(ColorRGBA.White.clone().multLocal(2));[/java]

It’s the same as [java]ColorRGBA.White.mult(2f)[/java]

Is there a reason it is done with clone and local? Or is it just habit? The local now makes sense and probably doesn’t make a difference, but why the clone?

EDIT:

Also, how does transparency work on a light’s color? I see it has no effect.

No, I dont think theres a certain reasoning for that. It should be the same.

I want more

1. Also, how does transparency work on a light’s color? I see it has no effect.

Secondly, but somewhat off-topic, should the following in the Vector3f.java not be different?

[java] /**
• Constructor instantiates a new <>Vector3f</> with default
• values of (0,0,0).

*

*/

public Vector3f() {

x = y = z = 0;

}

[/java]

to

[java] /**
• Constructor instantiates a new <>Vector3f</> with default
• values of (0,0,0).

*

*/

public Vector3f() {

this.x = this.y = this.z = 0;

}[/java]
1. What exactly do you imagine “transparency” to be for light?
2. No, its fine

Transparency does nothing for lights. The material’s transparency is determined by the alpha value of the material’s diffuse color.