Page 1 of 1

Working with materials, basic programming question.

Posted: Thu Apr 26, 2007 11:55 pm
by cederron
Hello.
I Want to get the material of a node and manipulate it, but not with the reference returned with getMaterial, I think you will understand better with some sample code:

Code: Select all

SMaterial *pointerMaterial;
SMaterial &nodeMaterial = node->getMaterial(0);
pointerMaterial = nodeMaterial;


//Now I want to modify the material but using pointerMaterial
pointerMaterial->Texture1 = ...
I thought that modifying pointerMaterial I could modify the node material also but it's not working. I know it is something with pointers and indirections but It's my weak point, so any help is apreciated, thank you.

Posted: Fri Apr 27, 2007 5:30 am
by vitek
You take the address of the reference to get a pointer...

Code: Select all

pointerMaterial = &nodeMaterial;

Posted: Fri Apr 27, 2007 4:00 pm
by cederron
Man! That was not what I wanted to do, I'm sorry.
What I want to do is:

Code: Select all

SMaterial *myMaterial = new SMaterial();
myMaterial->Texture1 = myTexture;
SMaterial &nodeMaterial = node->getMaterial(0);

//now I want to replace nodeMaterial with myMaterial,
//this works in my code and node shows the new material
nodeMaterial = *myMaterial;

//But if I modify myMaterial, changes are not reflected in the 
//node
myMaterial->Texture1 = anotherTexture;

//I want anotherTexture to be shown in the node but it's 
//not working.



How can I do this?

Posted: Fri Apr 27, 2007 4:13 pm
by hybrid
The first assignment copies all values from myMaterial to nodeMaterial. Thus, any changes to myMaterial will still be local to myMaterial. You have to change nodeMaterial all the time.