[Solved] Problem with nodes and SceneNodes

Rom

26-01-2006 11:48:29

Hi everybody,

I'm trying to iterate over all the node and the entities of my scene.
I've written a recursive method :
void printNodeContent(SceneNode s) {
Console.WriteLine("Node n.0 : " + s.GetName());
if (s.NumChildren() == 0)
{
for (ushort i = 0; i < s.NumAttachedObjects(); i++)
{
Console.WriteLine(" Attached Object n." + i + " : " + s.GetAttachedObject(i).GetName());
}
}
else {
for (ushort i = 0; i < s.NumChildren(); i++)
{
printNodeContent((SceneNode)(s.GetChild(i)));
}
}

}


But it crashes when I do the cast from Node to SceneNode.
Can someone tell me how to solve that ?

Thanks ;)

rastaman

26-01-2006 15:19:01

This is an inherent problem with swig proxy classes, they don’t cast up (all the time).
The C# object ( from “s.GetChild(i)” ) was created as a Node and just holds a IntPtr to the c++ object witch was created as a SceneNode, swig has no way of knowing this.

In your for loop you could do this.

SceneNode sn = new SceneNode( Node.getCPtr(s.GetChild(i)).Handle , false )
printNodeContent( sn );

Rom

26-01-2006 22:07:42

Great, thanks rastaman ;)
That's the kind of answer I like :)