Question about sceneNodes

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
post_ex0dus
Posts: 3
Joined: Mon Oct 10, 2011 6:16 pm

Question about sceneNodes

Post by post_ex0dus »

Hey everyone, i'm doing my best to program my first RTS-Game with the Irrlicht engine.
Here is my problem:
I got a class "Vehicle" and every Vehicle gets a pointer on a scene node, which is e.g. a Tank or a Rover...
now i want to select one Node with my cursor ( by using a ray and the getSceneNodeAndCollisionPointFromRay-method). that works fine! but i now i want to get the Object of type "Vehicle", which belongs to the selected scene-node.
example:
I got a Vehicle "Super-Tank" and it has a pointer on a sceneNode called "tankNode". now i select the tanknode with my mouse cursor, and i want the program to give me the belonging Object, the "Super-Tank".
any Ideas how i could do that?

thank you so much and forgive my bad english :)
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Question about sceneNodes

Post by serengeor »

There would be quite a few ways to do this.
1)Iterate over all objects and compare nodes.
2)modify irrlicht's scene node's source to accept your object's pointer to be stored.
3)use external collision library to get your collisions, usually those libraries let you in some way store your objects with collision objects.
4)???
Working on game: Marrbles (Currently stopped).
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: Question about sceneNodes

Post by Virror »

I did number 2, it was just a few lines of code to add a user pointer in to the scene node class. Now when i select a node, i can access that node properties, like hp or whatever.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Question about sceneNodes

Post by randomMesh »

You don't need to hack the engine, you could use a map (irr::core::map or std::map) with the node as the key.
"Whoops..."
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: Question about sceneNodes

Post by Virror »

True, but always good to learn how to get, hack and compile the source if you are serious on using irrlicht for some time ; )
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Question about sceneNodes

Post by CuteAlien »

Virror wrote:True, but always good to learn how to get, hack and compile the source if you are serious on using irrlicht for some time ; )
I'm always glad when people can hack the engine, but still be careful and avoid it unless you have to. I started out that way - hacking everything that I felt was missing directly into the engine - and later learned how much harder it makes updating your engine to a new version. I still hack from time to time in my engine versions, but learned to do at least one thing - create a patch-file for every single change I make.
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
Virror
Posts: 191
Joined: Mon May 02, 2011 3:15 pm

Re: Question about sceneNodes

Post by Virror »

True, patch file is the best option ofcourse, but i count that as a hack as well because its still a "change" to the engine : )
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Question about sceneNodes

Post by CuteAlien »

The patch is for you own documentation. Just so when you start changing the engine you will still know afterward which changes belong together. I didn't do that the first time I modified a local engine and then spend over a week just figuring out my own changes once I updated to a newer Irrlicht. The easiest way to do that is if you put your local Irrlicht into a version control program like mercurial and just check-in after each change. Then you can do diffs between those versions.

Well... doesn't matter for a single change - but if you start having more than that it pretty soon starts saving a lot of time.
But the best way is trying to avoid engine changes, so as long as you can do the same in your application in some way (for example using a map in this case) it's always the better solution.
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
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: Question about sceneNodes

Post by Brainsaw »

I prefer to not change the engine, but create plugins for it. Works great e.g. in my ODE integration (aka "IrrODE"), but I have also written a whole bunch of plugins for IrrEdit so that I don't have to hard code a lot of things (e.g. the checkpoints in the "Stunt Marble Racers" game). I guess for user data I would also write a scenenode that doesn't render anything but holds the information needed and make it a child of the node it belongs to. OK, the IrrOde wrapper does include a user data pointer I have used in the IrrOdeCar demo just to count hits when an airplane shoots at another one ;)
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Post Reply