Hi, I want to have an object that is an IMeshSceneNode but that contains other informations (for example a status), something like:
MyNode :: IMeshSceneNode
(
MyNode( ... );
int status;
int getStatus();
setStatus(int);
)
what is the best way to do this?
Noob question about subclassing a IMeshSceneNode
Create you own struct/class (whichever keyword you like more) which has all you want in it.
I like struct
I hope I did not make any mistake, did not test it
I like struct
Code: Select all
struct myMeshSceneNode{
private:
IMeshSceneNode* node;
int status;
public:
int getStatus() const
{
return status;
}
void setStatus(int newStatus)
{
status= newStatus;
return;
}
void setNode(IMeshSceneNode* newNode)
{
node= newNode;
return;
}
IMeshSceneNode* getNode() const
{
return node;
}
};
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Height2Normal v. 2.1 - convert height maps to normal maps
Step back! I have a void pointer, and I'm not afraid to use it!
Hi,
another possibility is to inherit from IMeshSceneNode like:
Special to this is that you do not need setnode() or getnode(), because myNode has the same functions and vars as IMeshSceneNode.
enity wrote: "myMeshSceneNode is a class and has following properties..."
>> he create a complete new class
I wrote: "myNode is a variation of IMeshSceneNode and has following changes"
>> I change an existing class
Both codes are correct just decide on your own.
MfG
Scarabol
another possibility is to inherit from IMeshSceneNode like:
Special to this is that you do not need setnode() or getnode(), because myNode has the same functions and vars as IMeshSceneNode.
enity wrote: "myMeshSceneNode is a class and has following properties..."
>> he create a complete new class
I wrote: "myNode is a variation of IMeshSceneNode and has following changes"
>> I change an existing class
Both codes are correct just decide on your own.
Code: Select all
class myNode : public IMeshSceneNode
{
public:
myNode();
~myNode();
int getstatus(void);
private:
int _status;
}
Scarabol
Thanks to all, I need something like the second solution, because in this way I can attach the node to the scenegraph and an animator to the node. The animator then reads the status of the node (using a cast in the animateNode function).
The problem is that I get those errors related to abstract funcion (I guess):
Here is my class:
In main.cpp I simply call CPin testsc();
Can you help me?
Thanks
The problem is that I get those errors related to abstract funcion (I guess):
Code: Select all
main.cpp: In function `int createScene(irr::scene::ISceneManager*, irr::gui::IGUIEnvironment*)':
main.cpp:312: error: invalid return type for function `CPin testsc()'
main.cpp:312: error: because the following virtual functions are abstract:
include/ISceneNode.h:138: error: virtual void irr::scene::ISceneNode::render()
include/ISceneNode.h:173: error: virtual const irr::core::aabbox3d<irr::f32>& irr::scene::ISceneNode::getBoundingBox() const
include/IMeshSceneNode.h:34: error: virtual void irr::scene::IMeshSceneNode::setMesh(irr::scene::IMesh*)
include/IMeshSceneNode.h:38: error: virtual irr::scene::IMesh* irr::scene::IMeshSceneNode::getMesh()
include/IMeshSceneNode.h:44: error: virtual void irr::scene::IMeshSceneNode::setReadOnlyMaterials(bool)
include/IMeshSceneNode.h:49: error: virtual bool irr::scene::IMeshSceneNode::isReadOnlyMaterials() const
Code: Select all
#include <irrlicht.h>
using namespace irr;
class CPin : public irr::scene::IMeshSceneNode
{
public:
CPin();
~CPin();
int getstatus(void);
private:
int _status;
};
Can you help me?
Thanks
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
Yes, you need to override these since they are pure virtual.Tranen wrote:The problem is that I get those errors related to abstract funcion (I guess)
If you don't know how inhertitance works, i suggest you go with composition rather than inheritance.
Composition would be more suitable in this case anyway, there is no point in having another type of IMeshSceneNode, just to have a status variable.
"Whoops..."
>there is no point in having another type of IMeshSceneNode, just to have a status variable
I need to subclass the meshscenenode class for this reason:
I need to create an animator that will do different animation (it changes position and or cololr) based on the status of this object, so I need to know the status of the object in the animateNode of the animator. The same animator instance is shared between more nodes I can get position/color from the node but nothing else.
This is also the reason why I cannot use composition.
Thanks
I need to subclass the meshscenenode class for this reason:
I need to create an animator that will do different animation (it changes position and or cololr) based on the status of this object, so I need to know the status of the object in the animateNode of the animator. The same animator instance is shared between more nodes I can get position/color from the node but nothing else.
This is also the reason why I cannot use composition.
Thanks
That sounds like feature request, but would be cool to have very small addition to ISceneNode and IGUIElement interfaces:
that is it.
Engine will not touch/check/use this value (no allocation and no destroy). UserData is user's ability to pin own data to certain node. User may define own datastructure and save pointer to it into UserData.
P.S.: this is kind of technique uses WinForms (.NET): each Control has Tag which has Object type (sort of void* in C++). A very useful thing.
Code: Select all
public: void* UserData = 0;
Engine will not touch/check/use this value (no allocation and no destroy). UserData is user's ability to pin own data to certain node. User may define own datastructure and save pointer to it into UserData.
P.S.: this is kind of technique uses WinForms (.NET): each Control has Tag which has Object type (sort of void* in C++). A very useful thing.