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 -> ???
getMaterial(i).setTexture
Re: getMaterial(i).setTexture
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?
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
Re: getMaterial(i).setTexture
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.
Re: getMaterial(i).setTexture
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 learnkevinsbro 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.
Working on game: Marrbles (Currently stopped).
Re: getMaterial(i).setTexture
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: getMaterial(i).setTexture
Ooh yeah! Now we all should drop the classes and rewrite Irrlicht in plain C code! As plain as Sheep-Cutie's glades!CuteAlien wrote:Every good programmer I've ever met has learned things while coding. Classes are just there to fill the gaps
RIGHT, Sheep-Cutie ?
Re: getMaterial(i).setTexture
Hehe, I thought we were talking about classes for learning, like school classes - not classes like structs :-)booe wrote:Ooh yeah! Now we all should drop the classes and rewrite Irrlicht in plain C code! As plain as Sheep-Cutie's glades!CuteAlien wrote: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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: getMaterial(i).setTexture
So.... so they are actually teaching C++ in school? I tought that only Sheep-Cutie's shepherd used to teach her AWESOME Pascal! WOOOHOO!CuteAlien wrote:Hehe, I thought we were talking about classes for learning, like school classes - not classes like structsbooe wrote:Ooh yeah! Now we all should drop the classes and rewrite Irrlicht in plain C code! As plain as Sheep-Cutie's glades!CuteAlien wrote:Every good programmer I've ever met has learned things while coding. Classes are just there to fill the gaps
Re: getMaterial(i).setTexture
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?
Re: getMaterial(i).setTexture
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++!
You need to learn a good deal of C++!
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt