getMaterial(i).setTexture

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
kevinsbro
Posts: 51
Joined: Fri Nov 05, 2010 8:18 pm

getMaterial(i).setTexture

Post by kevinsbro »

I'm sorry for this dumb question but I don't quite understand why

node->setMaterialTexture(0, texture);
and
node->getMaterial(0).setTexture(0, texture);

give the same results.

the returned material isn't a pointer, so how come when I change the texture, it changes the texture in the material for the actual node??

Or is it a pointer??? but why . then and not -> ???
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: getMaterial(i).setTexture

Post by Mel »

node->getMaterial() returns a reference to the material. A reference is somehow like a pointer, though, you can't do pointer arithmetics with them.

When you return something in a function, normally you return a copy of the result, so, the returned value only exists in the destination space. but in some cases, due to memory restrictions, or because the returned object is too big, or something else, it is best to return a reference, which is an adress to the original space. As it isn't exactly pointer, you can't use it like so, but you can use as the original object, and you can copy it using the = operator, something that you can't do with pointers. Or you have to use the . operator to access the members, instead of the ->

You may declare a "reference" using '&' before a variable name, and they are common in the parameters of the functions. read more there:

http://www.eetimes.com/discussion/progr ... s-Pointers

On to other matter, those methods aren't exactly equivalent.

node->setMaterialTexture(0, texture); -> sets the given texture to all the materials of the scene node (which can be many)
node->getMaterial(0).setTexture(0, texture); -> sets the given texture only to the specified material.

Got it clear?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
kevinsbro
Posts: 51
Joined: Fri Nov 05, 2010 8:18 pm

Re: getMaterial(i).setTexture

Post by kevinsbro »

Thank you so much. I understood the functions weren't 100% the same, I just meant that they gave the same result in my case. And I honestly had never heard of using references like that. It bugs me sometimes how I want to learn and improve my programming skills faster than my classes will teach me formally. I feel like all I know, I've learned on my own and my classes teach me too late.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: getMaterial(i).setTexture

Post by serengeor »

kevinsbro wrote:It bugs me sometimes how I want to learn and improve my programming skills faster than my classes will teach me formally. I feel like all I know, I've learned on my own and my classes teach me too late.
Than grab a good c++ book and study it. It might be a bit hard on your own sometimes, but It'll be a lot faster if you're willing to learn :)
Working on game: Marrbles (Currently stopped).
CuteAlien
Admin
Posts: 9718
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: getMaterial(i).setTexture

Post by CuteAlien »

Every good programmer I've ever met has learned things while coding. Classes are just there to fill the gaps :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
booe
Posts: 76
Joined: Thu Jul 29, 2010 2:12 pm

Re: getMaterial(i).setTexture

Post by booe »

CuteAlien wrote:Every good programmer I've ever met has learned things while coding. Classes are just there to fill the gaps :-)
Ooh yeah! Now we all should drop the classes and rewrite Irrlicht in plain C code! As plain as Sheep-Cutie's glades!


RIGHT, Sheep-Cutie ?
CuteAlien
Admin
Posts: 9718
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: getMaterial(i).setTexture

Post by CuteAlien »

booe wrote:
CuteAlien wrote:Every good programmer I've ever met has learned things while coding. Classes are just there to fill the gaps :-)
Ooh yeah! Now we all should drop the classes and rewrite Irrlicht in plain C code! As plain as Sheep-Cutie's glades!
Hehe, I thought we were talking about classes for learning, like school classes - not classes like structs :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
booe
Posts: 76
Joined: Thu Jul 29, 2010 2:12 pm

Re: getMaterial(i).setTexture

Post by booe »

CuteAlien wrote:
booe wrote:
CuteAlien wrote:Every good programmer I've ever met has learned things while coding. Classes are just there to fill the gaps :-)
Ooh yeah! Now we all should drop the classes and rewrite Irrlicht in plain C code! As plain as Sheep-Cutie's glades!
Hehe, I thought we were talking about classes for learning, like school classes - not classes like structs :-)
So.... so they are actually teaching C++ in school? I tought that only Sheep-Cutie's shepherd used to teach her AWESOME Pascal! WOOOHOO!
kevinsbro
Posts: 51
Joined: Fri Nov 05, 2010 8:18 pm

Re: getMaterial(i).setTexture

Post by kevinsbro »

Another thing. How does the "setMaterialType" "setMaterialTexture" "setMaterialFlag" work in the SceneNode class? How is it able to actually do as it says in the MeshSceneNode class when they're not virtual and don't know about the MeshSceneNodes material variables?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: getMaterial(i).setTexture

Post by Mel »

ISceneNode is an abstract class, and provides those methods as pure virtual, so you can't instance a ISceneNode as it is. But you don't use "ISceneNodes" exactly. Instead, you use derivate classes which implement those methods, those classes then can be casted to ISceneNodes for general handling, and so, you can manage many types of ISceneNodes with the same code. The good point is that the inheritance rules and the polimorphism are the responsibles that when you call any of the pure virtual methods, the correct method is called each time. IMeshSceneNode can have its own implementation of those methods, IAnimatedMeshSceneNode has its own and so on. And when they are cast to ISceneNodes, and those methods are called, in fact, the methods that are being called are those of the IMeshSceneNode or the IAnimatedMeshSceneNode.

You need to learn a good deal of C++! :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply