Identifying scene nodes from getSceneNodeFromCameraBB(cam)

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
ben
Posts: 18
Joined: Fri May 22, 2009 4:43 pm

Identifying scene nodes from getSceneNodeFromCameraBB(cam)

Post by ben »

Hi,

This is seemingly simple but just wont work for me!
I'm using:

selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);

to find which node is selected. Once I have this node, I can apply properties to it, but how can I retrieve existing properties?

Say I have two teams, Team 1 and Team 2 and I need to find out which team the node belongs to. Obviously I could make lists and iterate through them, but this seems inefficient.
I have tried assigning names to the scenenodes, and then using:

selectedSceneNode->getName() == NAME

but this always returns false.
I have tried creating a parent node for each team and then creating all units for each team as children, and then using getParent(), but again, no luck.

Anyone got any ideas?, because I'm pretty stumped at the moment.

Thanks
Ben
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

use the ID.
ISceneNode->getID, setID
Image
Image
ben
Posts: 18
Joined: Fri May 22, 2009 4:43 pm

Post by ben »

Unfortunately I'm using the ID already for a different purpose.

I just tried iterating through a list, and its not as bad as I expected... especially after including as many conditions as possible to make it do as little work as possible.
However this issue is one that I'm definitely going to encounter again in writing this game, so any improved solution is more than welcome.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

ok, then lets find whats the problem with the getName

as i tried, it returned the value what i expected. i think you have problem with the statement.

Code: Select all

if (selectedSceneNode->getName() == NAME)
{
printf("shouldnt find anything\n");
}
// it just compare the pointers of the chars (since its c8*), not the characters in the string
// so you have to use the strcmp function
if (!strcmp(selectedSceneNode->getName() == NAME)
{
printf("found my node! yey! \n");
}
this one works for me with the collision example
Image
Image
ben
Posts: 18
Joined: Fri May 22, 2009 4:43 pm

Post by ben »

Ahhhh many thanks!

I knew it would be something simple! I'm fairly new to programming.

I used the same concept but implemented it slightly differently;

Code: Select all

    stringc P1 = "PLAYERONE";
    stringc P2 = "PLAYERTWO";
    stringc NAME = selectedSceneNode->getName();

    if (NAME == P1)
    { 
//...etc
because this way I could (if I need to) store more information in the name, by using the substring function to only look at the appropriate part of it! (ie the first nine characters in this case.)

This solves all my problems in this respect!
Thanks!
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

okay ^^
you could use strncmp, what compares the first n letters, but that isnt work for the others.
so i think your solution is ok ;)
Image
Image
Post Reply