Exemplo n.º 1
0
		public void Start(IntPtr windowHandle)
		{
			if (irrThread != null)
				throw new InvalidOperationException("Previous viewport needs to be stopped!");

			commandQueue = new Queue<Command>();

			irrThread = new Thread(new ParameterizedThreadStart(irrThreadMain));
			irrThread.Name = "Irrlicht rendering";

			IrrlichtCreationParameters p = new IrrlichtCreationParameters();
			//p.AntiAliasing = 4;
			p.DriverType = DriverType.Direct3D8;
			p.WindowID = windowHandle;

			irrThread.Start(p);
		}
Exemplo n.º 2
0
        public FNGame()
        {
            var param = new IrrlichtCreationParameters()
            {
                AntiAliasing = 8,
                DeviceType   = DeviceType.Best,
                DriverType   = DriverType.OpenGL,
                VSync        = true,
                WindowSize   = new Dimension2Di(1200, 700)
            };

            device = IrrlichtDevice.CreateDevice(param);

            device.OnEvent += device_OnEvent;

            Driver = device.VideoDriver;
            Scene  = device.SceneManager;
            Gui    = device.GUIEnvironment;
        }
Exemplo n.º 3
0
        public void Start(IntPtr windowHandle)
        {
            if (irrThread != null)
            {
                throw new InvalidOperationException("Previous viewport needs to be stopped!");
            }

            commandQueue = new Queue <Command>();

            irrThread      = new Thread(new ParameterizedThreadStart(irrThreadMain));
            irrThread.Name = "Irrlicht rendering";

            IrrlichtCreationParameters p = new IrrlichtCreationParameters();

            //p.AntiAliasing = 4;
            p.DriverType = DriverType.Direct3D8;
            p.WindowID   = windowHandle;

            irrThread.Start(p);
        }
        /// <summary>
        /// Initiates Irrlicht and prepares the scene for rendering
        /// </summary>
        /// <param name="renderTo">Control will display the model</param>
        public MD2Viewer(Control renderTo)
        {
            renderingTo = renderTo;

            Dimension2Di displayDimensions = new Dimension2Di(renderTo.ClientSize.Width,
                renderTo.ClientSize.Height);

            IrrlichtCreationParameters creationParams = new IrrlichtCreationParameters();
            creationParams.BitsPerPixel = 16;
            creationParams.DoubleBuffer = false;
            creationParams.DriverType = DriverType.Software;
            creationParams.WindowSize = new Dimension2Di(renderingTo.Width, renderingTo.Height);
            creationParams.WindowID = renderingTo.Handle;
            creationParams.Fullscreen = false;

            irrlichtDevice = IrrlichtDevice.CreateDevice(creationParams);

            ClearScene();

            backgroundColour = new Color(150, 150, 150, 0);
        }
Exemplo n.º 5
0
		void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
		{
			BackgroundWorker worker = sender as BackgroundWorker;
			IrrlichtCreationParameters p = new IrrlichtCreationParameters();
			p.DriverType = DriverType.Direct3D9;
			p.WindowID = (IntPtr)e.Argument;

			IrrlichtDevice device = IrrlichtDevice.CreateDevice(p);
			if (device == null)
				// if device cannot be created by any reason - we just leave this thread,
				// after all IsRedering will report false, so it is all OK.
				return;

			VideoDriver driver = device.VideoDriver;
			SceneManager smgr = device.SceneManager;
			GUIEnvironment gui = device.GUIEnvironment;

			// setup a simple 3d scene

			CameraSceneNode cam = smgr.AddCameraSceneNode();
			cam.Target = new Vector3Df(0);

			SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 15, 0), 30.0f);
			cam.AddAnimator(anim);
			anim.Drop();

			SceneNode cube = smgr.AddCubeSceneNode(20);
			cube.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp"));
			cube.SetMaterialTexture(1, driver.GetTexture("../../media/water.jpg"));
			cube.SetMaterialFlag(MaterialFlag.Lighting, false);
			cube.SetMaterialType(MaterialType.Reflection2Layer);

			smgr.AddSkyBoxSceneNode(
				"../../media/irrlicht2_up.jpg",
				"../../media/irrlicht2_dn.jpg",
				"../../media/irrlicht2_lf.jpg",
				"../../media/irrlicht2_rt.jpg",
				"../../media/irrlicht2_ft.jpg",
				"../../media/irrlicht2_bk.jpg");

			gui.AddImage(
				driver.GetTexture("../../media/lime_logo_alpha.png"),
				new Vector2Di(30, 0));

			// draw all

			while (device.Run())
			{
				driver.BeginScene(false);
				
				smgr.DrawAll();
				gui.DrawAll();

				// draw stats

				int x = 20;
				int y = driver.ScreenSize.Height - 50;

				driver.Draw2DRectangle(
					new Recti(x, y, x + driver.ScreenSize.Width - 2 * x, y + 30),
					new IrrlichtLime.Video.Color(0, 0, 0, 128));

				device.GUIEnvironment.BuiltInFont.Draw(
					"Driver: " + driver.Name,
					new Vector2Di(x + 5, y + 5),
					new IrrlichtLime.Video.Color(255, 255, 255));

				device.GUIEnvironment.BuiltInFont.Draw(
					"FPS: " + driver.FPS.ToString(),
					new Vector2Di(x + 5, y + 15),
					new IrrlichtLime.Video.Color(255, 255, 255));

				driver.EndScene();

				// check for cancellation

				if (worker.CancellationPending)
					device.Close();

				// check for new command

				lock (backgroundCommand)
				{
					switch (backgroundCommand.Type)
					{
						case Command.Kind.Resized:
							driver.ResizeNotify(backgroundCommand.Value as Dimension2Di);
							backgroundCommand.Clear();
							break;
					}
				}
			}

			// drop the device

			device.Drop();
		}
Exemplo n.º 6
0
        void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker           worker = sender as BackgroundWorker;
            IrrlichtCreationParameters p      = new IrrlichtCreationParameters();

            p.DriverType = DriverType.Direct3D9;
            p.WindowID   = (IntPtr)e.Argument;

            IrrlichtDevice device = IrrlichtDevice.CreateDevice(p);

            if (device == null)
            {
                // if device cannot be created by any reason - we just leave this thread,
                // after all IsRedering will report false, so it is all OK.
                return;
            }

            VideoDriver    driver = device.VideoDriver;
            SceneManager   smgr   = device.SceneManager;
            GUIEnvironment gui    = device.GUIEnvironment;

            // setup a simple 3d scene

            CameraSceneNode cam = smgr.AddCameraSceneNode();

            cam.Target = new Vector3Df(0);

            SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 15, 0), 30.0f);

            cam.AddAnimator(anim);
            anim.Drop();

            SceneNode cube = smgr.AddCubeSceneNode(20);

            cube.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp"));
            cube.SetMaterialTexture(1, driver.GetTexture("../../media/water.jpg"));
            cube.SetMaterialFlag(MaterialFlag.Lighting, false);
            cube.SetMaterialType(MaterialType.Reflection2Layer);

            smgr.AddSkyBoxSceneNode(
                "../../media/irrlicht2_up.jpg",
                "../../media/irrlicht2_dn.jpg",
                "../../media/irrlicht2_lf.jpg",
                "../../media/irrlicht2_rt.jpg",
                "../../media/irrlicht2_ft.jpg",
                "../../media/irrlicht2_bk.jpg");

            gui.AddImage(
                driver.GetTexture("../../media/lime_logo_alpha.png"),
                new Vector2Di(30, 0));

            // draw all

            while (device.Run())
            {
                driver.BeginScene(false);

                smgr.DrawAll();
                gui.DrawAll();

                // draw stats

                int x = 20;
                int y = driver.ScreenSize.Height - 50;

                driver.Draw2DRectangle(
                    new Recti(x, y, x + driver.ScreenSize.Width - 2 * x, y + 30),
                    new IrrlichtLime.Video.Color(0, 0, 0, 128));

                device.GUIEnvironment.BuiltInFont.Draw(
                    "Driver: " + driver.Name,
                    new Vector2Di(x + 5, y + 5),
                    new IrrlichtLime.Video.Color(255, 255, 255));

                device.GUIEnvironment.BuiltInFont.Draw(
                    "FPS: " + driver.FPS.ToString(),
                    new Vector2Di(x + 5, y + 15),
                    new IrrlichtLime.Video.Color(255, 255, 255));

                driver.EndScene();

                // check for cancellation

                if (worker.CancellationPending)
                {
                    device.Close();
                }

                // check for new command

                lock (backgroundCommand)
                {
                    switch (backgroundCommand.Type)
                    {
                    case Command.Kind.Resized:
                        driver.ResizeNotify(backgroundCommand.Value as Dimension2Di);
                        backgroundCommand.Clear();
                        break;
                    }
                }
            }

            // drop the device

            device.Drop();
        }
Exemplo n.º 7
0
        /// <summary>
        /// The irrlicht thread for rendering.
        /// </summary>
        private void StartIrr()
        {
            try
            {
                IrrlichtCreationParameters irrparam = new IrrlichtCreationParameters();
                if (irrlichtPanel.IsDisposed)
                {
                    throw new Exception("Form closed!");
                }
                if (irrlichtPanel.InvokeRequired)
                {
                    irrlichtPanel.Invoke(new MethodInvoker(delegate { irrparam.WindowID = irrlichtPanel.Handle; }));
                }
                irrparam.DriverType   = DriverType.Direct3D9;
                irrparam.BitsPerPixel = 16;

                device = IrrlichtDevice.CreateDevice(irrparam);

                if (device == null)
                {
                    throw new NullReferenceException("Could not create device for engine!");
                }

                driver = device.VideoDriver;
                smgr   = device.SceneManager;
                gui    = device.GUIEnvironment;

                var animText = "";
                if (Animations.AnimationNames.Count > 0)
                {
                    animText = "Animation: " + Animations.AnimationNames[selectedAnimIdx].Key;
                }
                var mAnimText     = gui.AddStaticText(animText, new Recti(0, this.ClientSize.Height - 80, 100, this.ClientSize.Height - 70));
                var mPositionText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 70, 100, this.ClientSize.Height - 60));
                var mRotationText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 60, 100, this.ClientSize.Height - 50));
                var fpsText       = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 50, 100, this.ClientSize.Height - 40));
                var infoText      = gui.AddStaticText("[Space] - Reset\n[LMouse] - Rotate\n[MMouse] - Move\n[Wheel] - Zoom", new Recti(0, this.ClientSize.Height - 40, 100, this.ClientSize.Height));
                mAnimText.OverrideColor   = mPositionText.OverrideColor = mRotationText.OverrideColor = fpsText.OverrideColor = infoText.OverrideColor = new Color(255, 255, 255);
                mAnimText.BackgroundColor = mPositionText.BackgroundColor = mRotationText.BackgroundColor = fpsText.BackgroundColor = infoText.BackgroundColor = new Color(0, 0, 0);

                SkinnedMesh skinnedMesh = smgr.CreateSkinnedMesh();
                foreach (var meshBuffer in cdata.staticMesh.MeshBuffers)
                {
                    skinnedMesh.AddMeshBuffer(meshBuffer);
                }
                smgr.MeshManipulator.RecalculateNormals(skinnedMesh);
                if (RigFile != null)
                {
                    rig.Apply(skinnedMesh);
                    if (AnimFile != null)
                    {
                        anims.Apply(skinnedMesh);
                    }
                }
                skinnedMesh.SetDirty(HardwareBufferType.VertexAndIndex);
                skinnedMesh.FinalizeMeshPopulation();
                AnimatedMeshSceneNode node = smgr.AddAnimatedMeshSceneNode(skinnedMesh);

                if (node == null)
                {
                    throw new Exception("Could not load file!");
                }

                node.Scale = new Vector3Df(3.0f);
                node.SetMaterialFlag(MaterialFlag.Lighting, false);
                SetMaterials(driver, node);

                CameraSceneNode camera = smgr.AddCameraSceneNode(null, new Vector3Df(node.BoundingBox.Radius * 8, node.BoundingBox.Radius, 0), new Vector3Df(0, node.BoundingBox.Radius, 0));
                camera.NearValue = 0.001f;
                camera.FOV       = 45 * CommonData.PI_OVER_180;
                scaleMul         = node.BoundingBox.Radius / 4;

                var viewPort = driver.ViewPort;
                var lineMat  = new Material();
                lineMat.Lighting = false;

                while (device.Run())
                {
                    driver.ViewPort = viewPort;
                    driver.BeginScene(ClearBufferFlag.All, new Color(100, 101, 140));

                    node.Position         = modelPosition;
                    node.Rotation         = modelAngle;
                    node.DebugDataVisible = DebugSceneType.Skeleton | DebugSceneType.BBox;
                    mPositionText.Text    = $"X: {modelPosition.X.ToString("F2")} Y: {modelPosition.Y.ToString("F2")} Z: {modelPosition.Z.ToString("F2")}";
                    mRotationText.Text    = $"Yaw: {modelAngle.Y.ToString("F2")} Roll: {modelAngle.Z.ToString("F2")}";
                    fpsText.Text          = $"FPS: {driver.FPS}";

                    smgr.DrawAll();
                    gui.DrawAll();

                    driver.ViewPort = new Recti(this.ClientSize.Width - 100, this.ClientSize.Height - 80, this.ClientSize.Width, this.ClientSize.Height);
                    //driver.ClearBuffers(ClearBufferFlag.None);

                    driver.SetMaterial(lineMat);
                    var matrix = new Matrix(new Vector3Df(0, 0, 0), modelAngle);
                    driver.SetTransform(TransformationState.World, matrix);
                    matrix = matrix.BuildProjectionMatrixOrthoLH(100, 80, camera.NearValue, camera.FarValue);
                    driver.SetTransform(TransformationState.Projection, matrix);
                    matrix = matrix.BuildCameraLookAtMatrixLH(new Vector3Df(50, 0, 0), new Vector3Df(0, 0, 0), new Vector3Df(0, 1f, 0));
                    driver.SetTransform(TransformationState.View, matrix);
                    driver.Draw3DLine(0, 0, 0, 30f, 0, 0, Color.OpaqueGreen);
                    driver.Draw3DLine(0, 0, 0, 0, 30f, 0, Color.OpaqueBlue);
                    driver.Draw3DLine(0, 0, 0, 0, 0, 30f, Color.OpaqueRed);

                    driver.EndScene();
                }

                device.Drop();
            }
            catch (ThreadAbortException) { }
            catch (NullReferenceException) { }
            catch (Exception ex)
            {
                if (!this.IsDisposed)
                {
                    MessageBox.Show(ex.Message);
                    //this.Invoke(new MethodInvoker(delegate { this.Close(); }));
                }
            }
        }
        /// <summary>
        /// The irrlicht thread for rendering.
        /// </summary>
        private void StartIrr()
        {
#if DEBUG
            try
#endif
            {
                float DEGREES_TO_RADIANS = (float)(Math.PI / 180.0);

                //Setup
                IrrlichtCreationParameters irrparam = new IrrlichtCreationParameters();
                if (irrlichtPanel.IsDisposed)
                {
                    throw new Exception("Form closed!");
                }
                if (irrlichtPanel.InvokeRequired)
                {
                    irrlichtPanel.Invoke(new MethodInvoker(delegate { irrparam.WindowID = irrlichtPanel.Handle; }));
                }
                irrparam.DriverType   = DriverType.Direct3D9;
                irrparam.BitsPerPixel = 32;
                irrparam.AntiAliasing = 1;

                device = IrrlichtDevice.CreateDevice(irrparam);

                if (device == null)
                {
                    throw new NullReferenceException("Could not create device for engine!");
                }

                driver = device.VideoDriver;
                smgr   = SceneManagerWolvenKit.Create(device);
                gui    = device.GUIEnvironment;

                smgr.Attributes.SetValue("TW_TW3_TEX_PATH", depot);
                driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true);

                lightNode         = smgr.AddLightSceneNode(null, new Vector3Df(0, 0, 0), new Colorf(1.0f, 1.0f, 1.0f), 200000.0f);
                smgr.AmbientLight = new Colorf(1.0f, 1.0f, 1.0f);
                worldNode         = smgr.AddEmptySceneNode();
                //NOTE: Witcher assets use Z up but Irrlicht uses Y up so rotate the model
                worldNode.Rotation = new Vector3Df(-90, 0, 0);
                //NOTE: We also need to flip the x-coordinate with this rotation
                worldNode.Scale   = new Vector3Df(-1.0f, 1.0f, 1.0f);
                worldNode.Visible = true;

                var dome = smgr.AddSkyDomeSceneNode(driver.GetTexture("Terrain\\skydome.jpg"), 16, 8, 0.95f, 2.0f);
                dome.Visible = true;

                fpsText = gui.AddStaticText("FPS: 0",
                                            new Recti(2, 10, 200, 30), false, false, null, 1, false);
                fpsText.OverrideColor = IrrlichtLime.Video.Color.SolidRed;
                fpsText.OverrideFont  = gui.GetFont("#DefaultWKFont");

                vertexCountText = gui.AddStaticText("Vertices: " + totalVertexCount.ToString(),
                                                    new Recti(2, 32, 300, 52), false, false, null, 1, false);
                vertexCountText.OverrideColor = IrrlichtLime.Video.Color.SolidRed;
                vertexCountText.OverrideFont  = gui.GetFont("#DefaultWKFont");

                meshCountText = gui.AddStaticText("Meshes: " + totalMeshCount.ToString(),
                                                  new Recti(2, 54, 300, 74), false, false, null, 1, false);
                meshCountText.OverrideColor = IrrlichtLime.Video.Color.SolidRed;
                meshCountText.OverrideFont  = gui.GetFont("#DefaultWKFont");

                var camera = smgr.AddCameraSceneNodeWolvenKit();
                camera.FarValue = 10000.0f;

                //distanceBar.Invoke((MethodInvoker)delegate
                //{
                //    camera.FarValue = (float)Math.Pow(10.0, (double)distanceBar.Value);
                //});

                viewPort = driver.ViewPort;
                var lineMat = new IrrlichtLime.Video.Material
                {
                    Lighting = false
                };

                var WMatrix = new Matrix(new Vector3Df(0, 0, 0), smgr.ActiveCamera.ModelRotation);

                var PMatrix = new Matrix();
                PMatrix = PMatrix.BuildProjectionMatrixOrthoLH(100, 80, 0.001f, 10000.0f);

                var VMatrix = new Matrix();
                VMatrix = VMatrix.BuildCameraLookAtMatrixLH(new Vector3Df(50, 0, 0), new Vector3Df(0, 0, 0), new Vector3Df(0, 1f, 0));

                int gizmoX        = (int)(irrlichtPanel.Width * 0.92f);
                int gizmoY        = (int)(irrlichtPanel.Height * 0.92f);
                var gizmoViewPort = new Recti(gizmoX, gizmoY, irrlichtPanel.Width, irrlichtPanel.Height);

                while (device.Run())
                {
                    if (this.Visible)
                    {
                        ProcessCommand();

                        driver.BeginScene(ClearBufferFlag.All);
                        int val = driver.FPS;
                        fpsText.Text = "FPS: " + val.ToString();

                        smgr.DrawAll();
                        gui.DrawAll();

                        // draw xyz axis right bottom
                        driver.ViewPort = gizmoViewPort;

                        driver.SetMaterial(lineMat);

                        WMatrix.SetRotationRadians(smgr.ActiveCamera.ModelRotation * DEGREES_TO_RADIANS);
                        driver.SetTransform(TransformationState.World, WMatrix);
                        driver.SetTransform(TransformationState.Projection, PMatrix);
                        driver.SetTransform(TransformationState.View, VMatrix);

                        driver.Draw3DLine(0, 0, 0, 30f, 0, 0, IrrlichtLime.Video.Color.SolidGreen);
                        driver.Draw3DLine(0, 0, 0, 0, 30f, 0, IrrlichtLime.Video.Color.SolidBlue);
                        driver.Draw3DLine(0, 0, 0, 0, 0, 30f, IrrlichtLime.Video.Color.SolidRed);

                        driver.ViewPort = viewPort;

                        driver.EndScene();
                    }
                    else
                    {
                        device.Yield();
                    }
                }
            }
#if DEBUG
            catch (ThreadAbortException) { }
            catch (NullReferenceException) { }
            catch (Exception ex)
            {
                if (!this.IsDisposed)
                {
                    MessageBox.Show(ex.Message);
                    //this.Invoke(new MethodInvoker(delegate { this.Close(); }));
                }
            }
#endif
        }
Exemplo n.º 9
0
        /// <summary>
        /// The irrlicht thread for rendering.
        /// </summary>
        private void StartIrr()
        {
            try
            {
                //Setup
                IrrlichtCreationParameters irrparam = new IrrlichtCreationParameters();
                if (irrlichtPanel.IsDisposed)
                {
                    throw new Exception("Form closed!");
                }
                if (irrlichtPanel.InvokeRequired)
                {
                    irrlichtPanel.Invoke(new MethodInvoker(delegate { irrparam.WindowID = irrlichtPanel.Handle; }));
                }
                irrparam.DriverType   = DriverType.Direct3D9;
                irrparam.DriverType   = DriverType.OpenGL;
                irrparam.BitsPerPixel = 16;

                device = IrrlichtDevice.CreateDevice(irrparam);

                if (device == null)
                {
                    throw new NullReferenceException("Could not create device for engine!");
                }

                driver = device.VideoDriver;
                smgr   = device.SceneManager;
                gui    = device.GUIEnvironment;

                var cam = smgr.AddCameraSceneNode(null);
                cam.TargetAndRotationBinding = true;
                cam.Position = new Vector3Df(-100.0f, 500.0f, 100.0f);
                cam.Target   = new Vector3Df(0.0f);
                cam.FarValue = 42000.0f;

                device.CursorControl.Visible = false;

                //Terrain
                heightmap = driver.CreateImage("Terrain\\basemap.bmp");

                terrain = smgr.AddTerrainSceneNode(
                    "Terrain\\basemap.bmp",
                    null,
                    -1,
                    new Vector3Df(0.0f)
                    );
                terrain.Scale = new Vector3Df(32, 5, 32);
                terrain.SetMaterialFlag(MaterialFlag.Lighting, false);

                terrain.SetMaterialTexture(0, driver.GetTexture("Terrain\\rockwall.jpg"));
                selector = smgr.CreateTerrainTriangleSelector(terrain, 0);

                var arrow = smgr.AddAnimatedMeshSceneNode(smgr.AddArrowMesh("arrow", new IrrlichtLime.Video.Color(255, 255, 0, 0), new IrrlichtLime.Video.Color(255, 0, 255, 0)), null);
                arrow.SetMaterialFlag(MaterialFlag.Lighting, false);
                arrow.Scale    = new Vector3Df(100.0f);
                arrow.Rotation = new Vector3Df(0.0f, 0.0f, 180.0f);

                //Skybox and skydome
                driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, false);

                /*var box = smgr.AddSkyBoxSceneNode(
                 *  ("Terrain\\irrlicht2_up.jpg"),
                 *  ("Terrain\\irrlicht2_dn.jpg"),
                 *  ("Terrain\\irrlicht2_lf.jpg"),
                 *  ("Terrain\\irrlicht2_rt.jpg"),
                 *  ("Terrain\\irrlicht2_ft.jpg"),
                 *  ("Terrain\\irrlicht2_bk.jpg"));
                 * box.Visible = true;*/

                var dome = smgr.AddSkyDomeSceneNode(driver.GetTexture("Terrain\\skydome.jpg"), 16, 8, 0.95f, 2.0f);
                dome.Visible = true;
                driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, true);

                var helpq = gui.AddStaticText("Press Q to disable focus!",
                                              new Recti(0, this.ClientSize.Height - 40, 100, this.ClientSize.Height), true, true, null, 1, true);
                var helpesc = gui.AddStaticText("Press ESC to quit",
                                                new Recti(0, this.ClientSize.Height - 20, 100, this.ClientSize.Height), true, true, null, 1, true);
                middletext = gui.AddStaticText("Click to enable mouselook and move with WASD",
                                               new Recti(ClientSize.Width / 2 - 100, this.ClientSize.Height / 2, ClientSize.Width / 2 + 100, this.ClientSize.Height / 2 + 30), true, true, null, 1, true);
                middletext.OverrideColor   = IrrlichtLime.Video.Color.SolidWhite;
                middletext.BackgroundColor = IrrlichtLime.Video.Color.SolidBlack;
                var irrTimer = device.Timer;
                var then     = 0;
                var then30   = 0;

                device.CursorControl.Visible = false;

                Vector2Df lastcurr = new Vector2Df(0f);
                uint      dt       = 0;
                while (device.Run())
                {
                    driver.BeginScene(ClearBufferFlag.All);

                    if (catchmouse)
                    {
                        // move the arrow to the nearest vertex ...
                        IrrlichtLime.Core.Vector2Di center = new IrrlichtLime.Core.Vector2Di(irrlichtPanel.Width / 2, irrlichtPanel.Height / 2);
                        Line3Df     ray = smgr.SceneCollisionManager.GetRayFromScreenCoordinates(center, cam);
                        Vector3Df   pos;
                        Triangle3Df Tri;
                        var         curr = device.CursorControl.RelativePosition;

                        // Threshold and periodical check so we don't spin around due to float conversions
                        if (device.Timer.Time > dt && curr.GetDistanceFrom(lastcurr) > 0.01f)
                        {
                            Line3Df cursor_ray = smgr.SceneCollisionManager
                                                 .GetRayFromScreenCoordinates(new Vector2Di((int)(curr.X * irrlichtPanel.Width), (int)(curr.Y * irrlichtPanel.Height)), cam);

                            smgr.ActiveCamera.Target = cursor_ray.Middle;
                            dt       = device.Timer.Time + 30;
                            lastcurr = curr;
                            device.CursorControl.Position = center;
                        }

                        if (smgr.SceneCollisionManager.GetCollisionPoint(ray, selector, out pos, out Tri, out outnode))
                        {
                            var scale = 32;  // terrain is scaled 32X
                            var size  = 512; // heightmap is 512x512 pixels
                            var x     = (pos.X / scale);
                            var z     = (pos.Z / scale);
                            var index = x * size + z;

                            x *= scale;
                            z *= scale;

                            arrow.Position = new Vector3Df(x, terrain.GetHeight(x, z) + 100, z);
                        }
                    }

                    smgr.DrawAll();
                    gui.DrawAll();

                    driver.EndScene();

                    //device.CursorControl.Position = new Vector2Di(irrlichtPanel.
                }

                device.Drop();
            }
            catch (ThreadAbortException) { }
            catch (NullReferenceException) { }
            catch (Exception ex)
            {
                if (!this.IsDisposed)
                {
                    MessageBox.Show(ex.Message);
                    //this.Invoke(new MethodInvoker(delegate { this.Close(); }));
                }
            }
        }