Page 1 of 1

Colour-Vector in C++

Posted: Mon Feb 27, 2012 9:19 am
by tsn
Could someone please give me an example how to build a colour vector in C++? I always get type cast errors.
Thanks a lot in advance!

Re: Colour-Vector in C++

Posted: Mon Feb 27, 2012 9:57 am
by Alex
Hi Thomas,

by a colour vector do you mean a colour with four components or a vector of several color objects?

I tested the following code under the run() function of the Cmd_msg_n_times example:

Code: Select all

#include <rf_sdk/sdk/color.h>

...

virtual void run ( Cmd* rfEvntCmd )
{
  Scene& scene =  AppManager::instance()->getCurrentScene();
      
  PB_Emitter emitter = scene.get_PB_Emitter( "Circle01" );
  Color col( 255, 0, 0 );
  emitter.setParameter( "Color", col );
}
Let us know some more about your case: Objects you want to use to initialize your colours, and so.

Re: Colour-Vector in C++

Posted: Mon Feb 27, 2012 10:25 am
by tsn
Thank you very much, Alex.

It is indeed about assigning a color to freshly created object. We're trying to dye objects randomly based on the selection of a GUI. There, the user can choose whether he wants to use random or uniform colors. The approach so far was:

Code: Select all

		if (scene.getGlobalVariableValue<bool>("gv_rndColour") == true)
		{
			int colR = static_cast<int>(randValue(0.0f,255.0f));
			int colG = static_cast<int>(randValue(0.0f,255.0f));
			int colB = static_cast<int>(randValue(0.0f,255.0f));
			newColVec.setX(colR);
			newColVec.setY(colG);
			newColVec.setZ(colB);
		}

		// Use single colour from GUI, if rndColor = False
		else
		{
			Vector curColVec = scene.getGlobalVariableValue<Vector>("gv_colVec");
			newColVec.setX(curColVec.getX());
			newColVec.setY(curColVec.getY());
			newColVec.setZ(curColVec.getZ());
		}

		// Set new parameters
		curObj.setParameter("Color", newColVec);
I have to say that I'm not the programmer in this case. It's one of my-developers who is familiar with C++, but from what I've seen in you code segment I think he didn't use the color.h file. He also tried it with floats and four components, but I guess the entire approach isn't correct.

Re: Colour-Vector in C++

Posted: Mon Feb 27, 2012 10:40 am
by Alex
Hi again,

yes, it seems the problem is calling setParameter with a Vector instead of a Color object.
The Color constructor based on a Vector seems to work, so the fix is straight forward.

One more thing that might suppose an issue for you is that the Color constructor based on a Vector expects a Vector of floats in range 0.0f..1.0f instead of 0..255.

Re: Colour-Vector in C++

Posted: Mon Feb 27, 2012 10:48 am
by tsn
Again, thanks a lot for your help and the float-int tip. I'm sure that your code will do the trick.