Associate object with node

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
dutt
Posts: 8
Joined: Tue Sep 21, 2010 10:10 am

Associate object with node

Post by dutt »

What's the standard/accepted way of associating an object(say a ship) with a scene node? My node selection by mouse is working now, but I'm not sure how to go from node to object.

Do I create a ShipSceneNode with doesn't change SceneNode, just connect it with my ship-object?
barakatx2
Posts: 14
Joined: Tue Aug 24, 2010 7:00 am

Post by barakatx2 »

One way you could do it is by creating an std::map<ISceneNode*,ShipObject*>. If you haven't used a map before, here is what they are: http://www.cplusplus.com/reference/stl/map/ If you need an example I would be happy to write one.

Also, Irrlicht has it's own implementation of the map collection (I don't know how it is different from std::map or which is better) which is documented here: http://irrlicht.sourceforge.net/docu/cl ... _1map.html

I think they both work the same way from the front end. You could also do what you said and make a custom scene node that has a pointer to the ship object, which would be faster if your game is going to be CPU intensive.
dutt
Posts: 8
Joined: Tue Sep 21, 2010 10:10 am

Post by dutt »

Then a ShipSceneNode it is, thanks for the help :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Using a custom scene node is fundamentally wrong in this situation. Either use the mapping as suggested before, or just use names of the scene nodes to identify the things. Or IDs, which can also hint the content
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

we use a base class 'CObject' which houses a scenenode. we then set the ID of the scenenode, the ID of the object and the ID of the physicsobject to the same value. When 'picking' an object, we can use either the normal smgr selection style (which returns us a scenenode) or we can use the physics engine picking method (which returns us a physicsobject). either way, since they all have the same ID, we can easily search the master list of objects to find the right one. In the editor, we allow the user to toggle between 'scenenode' and 'physicsobject' selection.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

the object class should have more info than just the scenenode. Using a custom scenenode might work, but you still need to attach the AI, physics, etc... it is easier to create a custom object class that houses all of this and then use the ID's to keep them in sync. It also makes it easier to maintain seperate lists for object updating, dead objects etc...
Post Reply