Scene Node pointers...
Scene Node pointers...
Is there a quick or simple way for validating whether or not a created scene node pointer i still in the scene manager list or draw? As in to pass a pointer to a function etc?
Thanks
Thanks
That's a bit of a weird question.
All you should need to do is check to see that the parent node is in the scene graph. Repeat that until you get to the scene managers root node or a NULL node. If you hit a NULL node, then your node is not in the graph, or it is a child of a node that is not in the graph.
Travis
All you should need to do is check to see that the parent node is in the scene graph. Repeat that until you get to the scene managers root node or a NULL node. If you hit a NULL node, then your node is not in the graph, or it is a child of a node that is not in the graph.
Travis
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Hey goaty, it will definitely help more if you get at least a little more involved with the internal structures of Irrlicht. Otherwise you will have to make your whole app by asking each time again. So give it a try. In case you still fail you just come back and show what you've got and we will be happily helping you out.
-
- Posts: 49
- Joined: Sun Dec 10, 2006 6:23 pm
this may work
This may work for what you are trying to do! Be nicer to each other BTW, we only have eachother. So maby dont be so rude to people who try to help goaty.
EDIT * THIS CODE DOES NOT WORK (Endless loop)*
EDIT * THIS CODE DOES NOT WORK (Endless loop)*
EDIT * THIS CODE DOES NOT WORK (Endless loop)*
Code: Select all
scene::ISceneNode * NodeReader = smgr->addEmptySceneNode(0,-1);
bool IsInGraph = false;
NodeReader = NodeToRead->getParent ();
//look through for a specific node
while (NodeReader != NULL){
if (NodeReader = NodeToFind)
{
bool IsInGraph = true;
}
NodeReader = NodeReader->getParent();
}
Last edited by harukiblue on Fri Jan 12, 2007 7:28 pm, edited 1 time in total.
Maybe I'm the only one, but I think it is rude to expect others to write your code for you.So maby dont be so rude to people who try to help goaty
This is a simple exercise that he should be able to figure out given the description I provided in my previous posts. The goal is to help goaty to be self-sufficient. If he can't write a simple function to walk the parent tree, then he will have a lot of trouble when it comes to more complicated things in a rendering engine. He is not going to learn anything if we just give him the answer [and it appears that someone else already has].
Also, the code you provided will not work. IsInGraph would always be false, you always set IsInGraph to true, you create a scene node that you never use, and you continue to walk up the graph even though you are really done searching.
Travis
-
- Posts: 49
- Joined: Sun Dec 10, 2006 6:23 pm
cont...
I agree with you compleetly, that is why I posted that he should be more to polite to people who give him helpfull hints. BUT enough of that right, let me see if I can get this code right!Maybe I'm the only one, but I think it is rude to expect others to write your code for you.
Code: Select all
int FindNode ( ISceneManager * smgr,
ISceneNode * NodeToRead,
ISceneNode * NodeToFind)
{
//create a pointer to a ISceneNode to temporarily hold the current
//node being read.
scene::ISceneNode * NodeReader = smgr->addEmptySceneNode(0,-1);
//integer to store the generation
int Generation=0;
//Default is false, set to true if we find the node we are looking for.
bool IsInGraph = false;
//store the starting pointer into the Reader
NodeReader = NodeToRead->getParent ();
//look through the tree for a specific node
while (NodeReader != NULL){
//Check to see if the curent Node in the tree is the one we are looking for.
if (NodeReader == NodeToFind)
{
//the node is in the graph.
bool IsInGraph = true;
//exit the conditional loop
NodeReader = NULL;
}
NodeReader = NodeReader->getParent();
Generation++;
}
return Generation;
}
Well your code would return the right result in most cases, but it is still not right. It would return 0 if the node you were searching for was the same as the node you started the search from. Also...
To see if a node is in the scene graph, you would write
Of course you could generalize that to allow you to see if a given node is an ancestor to another node...
Travis
- Find is probably not a good function name, especially since this function only searches up the scene graph.
- You create NodeReader, but you don't need to create a node. You already have a pointer to the node to find and the node to start from. Just remove the creation of the empty scene node entirely.
- You create a new IsInGraph variable inside the if in your while loop. This prevents you from setting the IsInGraph variable outside the while loop to true. Actually, you don't use IsInGraph at all, so why bother?
Code: Select all
bool ISceneNode_isInSceneGraph(ISceneNode* self, ISceneManager* smgr)
{
ISceneNode* root = smgr->getRootSceneNode();
while (self && (self != root))
self = self->getParent();
return self != 0;
}
Code: Select all
bool isInSceneGraph = ISceneNode_isInSceneGraph(node, smgr);
Code: Select all
bool ISceneNode_isAncestor(ISceneNode* self, ISceneNode* ancestor)
{
while (self && (self != ancestor))
self = self->getParent();
return self != 0;
}
bool ISceneNode_isInSceneGraph(ISceneNode* self, ISceneManager* smgr)
{
return ISceneNode_isAncestor(self, smgr->getRootSceneNode());
}
-
- Posts: 49
- Joined: Sun Dec 10, 2006 6:23 pm
I dont get it =(
I dont understand what this means
BUT I'll take a guess . . .
if self != 0 return true else return false?
Sorry I guess I should brush up on some more C++
also I think I miss understood what the purpose was because your first function does not check to see if it is inside the graph as far as I can tell (above the Node generation). I am probrally just an idiot! So I am sorry about that
Code: Select all
return self != 0;
if self != 0 return true else return false?
Sorry I guess I should brush up on some more C++
also I think I miss understood what the purpose was because your first function does not check to see if it is inside the graph as far as I can tell (above the Node generation). I am probrally just an idiot! So I am sorry about that
-
- Posts: 49
- Joined: Sun Dec 10, 2006 6:23 pm
woops
I think that I mis read the while loop, I can see now that you do indeed cycle through the nodes, but inbetween each cycle you dont do anything? I thought that we were supposed to check to see if the current parrent of that cycle matched a specific node. Am I wrong?
A node is in the scene graph if its parent is in the scene graph or it is the root scene node. The first part of that is a recursive definition, but it is simple. Basically that says a node is in the scene graph if it has the root scene node as an ancestor.
The code loops looking for a NULL pointer or the root scene node. Every time through the loop, we look at the parent of the node that we last examined [an ancestor of the original node]. If we hit the root scene node, then the node is in the graph. If it ends with a NULL pointer, then the node is not in the graph.
The code loops looking for a NULL pointer or the root scene node. Every time through the loop, we look at the parent of the node that we last examined [an ancestor of the original node]. If we hit the root scene node, then the node is in the graph. If it ends with a NULL pointer, then the node is not in the graph.