c# ISceneNode Inherintance (like 03.CustomSceneNode in c++)

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
lvanderree

c# ISceneNode Inherintance (like 03.CustomSceneNode in c++)

Post by lvanderree »

Hello all, I'm playing around wiht Irrlicht in c#.Net and exploring the possibilities of this extremely fast engine.

At the moment I'm trying to create a new class which inherits it's members from ISceneNode, but I haven't found a way to do this. (just like the example 03. CustomSceneNode in c++)

So my question is: am I doing something wrong, or is this not possible (yet) and should I change the c++ source code for it? I can change the c++ source, but prefer to make my inheritence in c#.

So basicly what I'm trying to do is:

Code: Select all

	public class ExtendedSceneNode : ISceneNode {
		ExtendedSceneNode() : base( ???* realSceneNode??? ) {
		}
	}
but as you can see above, I don't know what the give to the base constuctor... I can change this in c++, but haven't got enough experience in c# to know if there is a solution for this in c# as well.

It seems to me that there now also isn't a way to create a new ISceneNode. Of course you can create several with the SceneManager, but not your own.

Any help would be appreciated
lvanderree

a "solution"

Post by lvanderree »

I did some puzzeling myself and have succeeded in inheriting the ISceneNode, but I'm far from happy with the way I have to do this...

In my main application I created the following code

Code: Select all

   ISceneNode emptyNode = device.SceneManager.AddEmptySceneNode(null,-1);
   ExtendedSceneNode extNode = new ExtendedSceneNode(device.SceneManager, emptyNode.NativeSceneNode);
The code for the ExtendedSceneNode looks like this:

Code: Select all

 public class ExtendedSceneNode: ISceneNode
 {
  //Constuctor
  unsafe
  public ExtendedSceneNode(ISceneManager smgr, irr.scene.ISceneNode* realSceneNode) : base(realSceneNode)
  { 
    ....
  }
This code does his job and I can see my newly created ExtendedSceneNode, but irr.scene.ISceneNode* realSceneNode really annoys me. Is there another cleaner way to extend the ISceneNode in c# or is this not possible in the c# api?
Galaxy613
Posts: 20
Joined: Wed Jun 01, 2005 12:46 am
Location: USA, VA
Contact:

Post by Galaxy613 »

Hmmm, this IS a tough one. :? Keep at it and some time you'll get it. :D Heres what I got, but now it says "No Overload method for 'ISceneNode' takes 0 arguments." :roll:

Code: Select all

class ExtendedSceneNode : ISceneNode
{
	#region Varaibles
	ISceneNode node;
	ISceneManager localsmgr;
	#endregion
	
	public ExtendedSceneNode(ISceneManager smgr,ISceneNode parent,int id)
	{
		node = smgr.AddEmptySceneNode(parent,id);
		localsmgr = smgr;
	}
}

Code: Select all

  			ExtendedSceneNode extNode = new ExtendedSceneNode(device.SceneManager, null, -1);
  			if(extNode == null)
  				MessageBox.Show("Something has gone wrong!!!");
  			else
  				MessageBox.Show("Something went right!!!");
Doing this may not be possible, but keep trying until your sure theres not way to do it. Good luck! :)
Image
lvanderree
Posts: 2
Joined: Fri Jun 03, 2005 5:15 pm
Location: Netherlands

Post by lvanderree »

The error message "No Overload method for 'ISceneNode' takes 0 arguments." is because Irrlicht.Net hasn't got a constuctor for ISceneNode which takes zero arguments. So with Irrlicht.Net you can't say:

Code: Select all

ISceneNode node = new ISceneNode();
And because you implicitely say

Code: Select all

 public ExtendedSceneNode(ISceneManager smgr,ISceneNode parent,int id) : base()
you get this error.

The only constructor available for a ISceneNode in Irrlicht.Net is the one I already use (with the realSceneNode), like in this:

Code: Select all

ISceneNode alreadyInstancedNode = device.SceneManager.AddEmptySceneNode(null,-1);
irr.scene.ISceneNode* realSceneNode = alreadyInstancedNode.NativeSceneNode;
ISceneNode node = new ISceneNode(realSceneNode);
I don't know if this is the only way to get a pointer to the realSceneNode, because this isn't a very nice way to get one. But also a pointer to the Irrlicht C++ version of a ISceneNode isn't the nicest way to create a new Irrlicht.Net ISceneNode I think.

I wonder why it's done this way, and why not the constructors from the C++ Irrlicht version of ISceneNode are ported?!
Now you have to give it a unsafe irr.scene.ISceneNode* C++ argument, which I think is pretty bizar.

But at the moment I haven't looked well enough at the problems which can (and probably will) arise when changing the constructors of the ISceneNode in Irrlicht.Net to the ones used at the standard Irrlicht version, but I think this is a lot nicer.
Post Reply