Connect node with custom class? (ISceneNode User data)
You could do the following:
in your collsion code:
EDIT: sry only read the first page obviously u already found a good way
Code: Select all
class CSceneCollector : public irr::scene::ISceneNodeAnimator
{
public:
CSceneCollector(void) : UserData(NULL){}
~CSceneCollector(void){if (UserData)UserData->drop();
void animateNode (ISceneNode *node, u32 timeMs){}
ISceneNodeAnimator * createClone (ISceneNode *node, ISceneManager *newManager=0)
{
CSceneCollector* anim = new CSceneCollector;
anim->setUserData(UserData);
node->addAnimator(anim);
anim->drop();
}
ESCENE_NODE_ANIMATOR_TYPE getType () const
{
return NODE_USER_DATA_ANIMATOR; //some unused anim number
}
Unit* getUserData(void){return UserData;}
void setUserData(Unit* data)
{
if (data == UserData)
return;
if (UserData)
UserData->drop();
UserData = data;
if (UserData)
UserData->grab();
}
protected:
Unit* UserData;
};
Code: Select all
//when creating Your Node
CSceneCollector* anim = new CSceneCollector;
anim->setUserData(YOUR_UNIT);
Node->addAnimator(anim);
anim->drop();
...
//later in your collision code
.....
//found sceneNode Node
irr::core::list<ISceneNodeAnimator*> animators = Node->getAnimators();
//check if node has userdata
Unit* UserData = NULL;
irr::core::list<ISceneNodeAnimator*>::ConstIterator it = animators.begin();
while (it != animators.end())
{
if ((*it)->getType() == NODE_USER_DATA_ANIMATOR)
{
UserData = ((CSceneCollector*)(*it))->getUserData();
break;
}
it++;
}
if (UserData != NULL)
{
//do ur magic
}
....
EDIT: sry only read the first page obviously u already found a good way
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
well u could always set ur userdata animator first. then u can cancel the search after the first animator. which is retrived by begin()
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
but searching 10 animators is less work than 500 scenenodes
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Idon't think that it is a good idea to a void* UserData pointer into a ISceneNode. Isn't there this new CollisionCallbackClass? Maybe that can be used to retrive Your userdata.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Isn't picking done by the CollisionManager???well so a good time for the CollisionCallback::rayHit....well and what is there besides that?
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
a void* in an animator doesn't make sense at all...and in a scenenode hmm.
Its a graphics engine not a game engine. You should keep all game related stuff out of irrlicht itself.
Its a graphics engine not a game engine. You should keep all game related stuff out of irrlicht itself.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
oh ffs
Just use a std::map, one side the pointer to your node as the key and the pointer to your data as, well, your data. Simple, small and fast. End of story.
-EDIT-
P.S.: Dan911: The fact Irrlicht is taking so much time on secondary stuff like collision which it doesn't do well enough because it isn't a proper physic engine nor contain one is a problem in itself. It takes time away from the prior focus of Irrlicht, aka, to be a powerful and simple graphic engine on a wide range of system. A good number of people (I'd wager the majority) replace/use on top a custom library/their own system as soon as they start a serious project. There might be some exception, but I'd wager it's still not the norm. So please, while I won't actively march against those features in Irrlicht, can they stop being brought in debates as arguments to bring even more? Unless the definition of goals of Irr is changed, this is not it.
Just use a std::map, one side the pointer to your node as the key and the pointer to your data as, well, your data. Simple, small and fast. End of story.
-EDIT-
P.S.: Dan911: The fact Irrlicht is taking so much time on secondary stuff like collision which it doesn't do well enough because it isn't a proper physic engine nor contain one is a problem in itself. It takes time away from the prior focus of Irrlicht, aka, to be a powerful and simple graphic engine on a wide range of system. A good number of people (I'd wager the majority) replace/use on top a custom library/their own system as soon as they start a serious project. There might be some exception, but I'd wager it's still not the norm. So please, while I won't actively march against those features in Irrlicht, can they stop being brought in debates as arguments to bring even more? Unless the definition of goals of Irr is changed, this is not it.
Last edited by Dorth on Sun Feb 08, 2009 10:15 pm, edited 1 time in total.