Help using ISceneNode.AddChild() in .NET hosted in WinForm

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
nicthu
Posts: 4
Joined: Sat Nov 19, 2005 6:48 am

Help using ISceneNode.AddChild() in .NET hosted in WinForm

Post by nicthu »

Hello,
I have been experimenting with the .NET version for a few weeks in my off time. I have version 0.12.0.

I basically want to draw 3 sides of an open box, then rotate that structure in front of a camera using my own buttons (not FPS). I don't know anything about meshes etc., so I am using flat TestSceneNodes scaled to the sizes I need. I can draw 2 sides of the box, but as soon as I parent one to the other, the child one disappears.

Any ideas what I am doing wrong?

Here is some sample code, just create a new .NET Windows Form and throw this after (outside) the Main() method:

Code: Select all

        IrrlichtDevice device = null;
        ICameraSceneNode camera = null;
        ISceneNode container = null;

        bool OKtoDraw = false;

        private void Form1_Load(object sender, System.EventArgs e)
        {
            // start up the engine

            this.device = new IrrlichtDevice(DriverType.OPENGL,
              new Dimension2D(640, 480),
              8,
              false,
              false,
              false,
              false,
              this.Handle
              );

            this.device.ResizeAble = true;

            // load some textures 

            ITexture texWall = this.device.VideoDriver.GetTexture(@"C:\irrlicht-0.12.0\media\wall.bmp");
            ITexture texStones = this.device.VideoDriver.GetTexture(@"C:\irrlicht-0.12.0\media\stones.jpg");

            this.camera = this.device.SceneManager.AddCameraSceneNode(
              null, new Vector3D(30, 5, 5), new Vector3D(0, 0, 0), -1);

            // Floor of the container:
            ISceneNode containerFloor = this.device.SceneManager.AddTestSceneNode(1,
              null, 1,
              new Vector3D(10, 0, 4),
              new Vector3D(0, 0, 0),
              // Length, Height, Width
              new Vector3D(20, 0, 8)
              );
            containerFloor.SetMaterialTexture(0, texWall);

            // Closed end of the container:
            ISceneNode containerClosedEnd = this.device.SceneManager.AddTestSceneNode(1,
              null, 2,
              new Vector3D(0, 5, 4),
              new Vector3D(0, 0, 0),
              new Vector3D(0, 10, 8)
              );
            containerClosedEnd.SetMaterialTexture(0, texStones);

            // Attach the Closed End to the Floor:
            // As soon as I do this, the containerClosedEnd disappears!
            containerFloor.AddChild(containerClosedEnd);

            this.container = containerFloor;

            // Fire up the engine
            this.device.Run();

            // View Form
            this.Show();
            this.OKtoDraw = true;
        }

        void RefreshWindow()
        {
            if (this.OKtoDraw)
            {
                this.device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(0, 100, 100, 100));

                this.device.SceneManager.DrawAll();

                this.device.VideoDriver.EndScene();
            }
        }

        private void Form1_Resize(object sender, System.EventArgs e)
        {
            RefreshWindow();
        }

        private void Form1_Closed(object sender, System.EventArgs e)
        {
            Application.Exit();
        }

        private void Form1_Activated(object sender, System.EventArgs e)
        {
            RefreshWindow();
        }

        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            RefreshWindow();
        }
Foole
Posts: 87
Joined: Mon Aug 29, 2005 10:08 am

Post by Foole »

Is it possible that you aren't taking into consideration the fact that a child node's co-ordinates are relative to the parent?

Unless the parent is at 0,0,0 attaching a node will make it appear somewhere else.
nicthu
Posts: 4
Joined: Sat Nov 19, 2005 6:48 am

Post by nicthu »

No, it is not possible. :o

I can see the parent, and the child is not that far from the parent, and my camera is some distance away.
Besides, even if I specify (0,0,0) for the child (in case AddTestSceneNode uses relative positioning), the child still disappears.

Can't anyone try my code and confirm this behavior?
I need to know if I am doing something wrong or if it is a bug to report.

Thanks
Locked