Working with materials, basic programming question.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Working with materials, basic programming question.

Post 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.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You take the address of the reference to get a pointer...

Code: Select all

pointerMaterial = &nodeMaterial;
cederron
Posts: 53
Joined: Thu Jul 13, 2006 11:35 pm

Post 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?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
Post Reply