Beispiel #1
0
        public void Run()
        {
            while (device.Run())
            {
                if (OnUpdate != null)
                {
                    OnUpdate();
                }

                sphere.Rotation += new Vector3Df(0, 1, 0);

                device.SetWindowCaption(Driver.FPS.ToString());

                //collision

                selectionCube.Position = _cam.Intersection;


                Driver.BeginScene(true, true, new Color(110, 60, 50));

                Scene.DrawAll();
                Gui.DrawAll();

                Driver.EndScene();

                device.Yield();
            }
        }
Beispiel #2
0
        static void Main()
        {
            device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(800, 600));
            device.SetWindowCaption("Sphere Camera - Irrlicht Engine");
            driver = device.VideoDriver;
            scene  = device.SceneManager;

            sphere = scene.AddSphereSceneNode(5, 100);
            sphere.SetMaterialTexture(0, driver.GetTexture("../../media/earth.jpg"));
            sphere.TriangleSelector = scene.CreateTriangleSelector(sphere.Mesh, sphere);
            sphere.TriangleSelector.Drop();

            scene.AmbientLight = new Colorf(0.2f, 0.2f, 0.2f);
            LightSceneNode light = scene.AddLightSceneNode();

            light.Position = new Vector3Df(-10, 10, -10);

            camera             = new SphereCamera(device, new Vector3Df(0), 8, 20, 10, 0, 0);
            camera.Inclination = 200;

            path = new SpherePath(5.4f);

            GUIFont font = device.GUIEnvironment.BuiltInFont;

            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);
            device.PostEvent(new Event('r', KeyCode.KeyR, true));             // pretend user pressed [R]

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

                scene.DrawAll();

                path.Draw(driver);

                font.Draw("Press [Arrows], [LMB] and [Mouse Scroll] to change view", 10, 10, Color.SolidYellow);
                font.Draw("Press [RMB] on Earth to place new path point", 10, 20, Color.SolidYellow);
                font.Draw("Press [R] to reload path data from file", 10, 30, Color.SolidYellow);
                font.Draw("Press [C] to clean up", 10, 40, Color.SolidYellow);

                font.Draw(driver.FPS.ToString() + " fps", 10, driver.ScreenSize.Height - 40, Color.SolidYellow);
                font.Draw(path.PointCount.ToString() + " point(s)", 10, driver.ScreenSize.Height - 30, Color.SolidYellow);
                font.Draw(camera.ToString(), 10, driver.ScreenSize.Height - 20, Color.SolidYellow);

                driver.EndScene();
                device.Yield();
            }

            path.Drop();
            device.Drop();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            device = IrrlichtDevice.CreateDevice(DriverType.Direct3D8, new Dimension2Di(1024, 768));
            if (device == null)
            {
                return;
            }

            device.SetWindowCaption("Fractal Generator - Irrlicht Engine");
            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);

            VideoDriver driver = device.VideoDriver;
            GUIFont     font   = device.GUIEnvironment.GetFont("../../media/fontlucida.png");
            Color       fontBackgroundColor = new Color(0x7f000000);
            Color       fontNormalColor     = Color.OpaqueWhite;
            Color       fontActionColor     = Color.OpaqueYellow;

            fGen = new FractalGenerator(device);
            fGen.Generate(new Rectd(
                              -driver.ScreenSize.Width / 250.0,
                              -driver.ScreenSize.Height / 250.0,
                              driver.ScreenSize.Width / 250.0,
                              driver.ScreenSize.Height / 250.0));

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

                Vector2Di o = null;
                if (mouseMoveStart != null)
                {
                    o = device.CursorControl.Position - mouseMoveStart;
                }

                float w = fGen.DrawAll(o);

                // draw stats

                driver.Draw2DRectangle(new Recti(10, 10, 160, 56 + (w < 1 ? 16 : 0)), fontBackgroundColor);

                Vector2Di v = new Vector2Di(20, 16);
                font.Draw("Max iterations: " + fGen.GetMaxIterations(), v, fontNormalColor);
                v.Y += 16;
                font.Draw("Zoom: " + (long)fGen.GetZoomFactor().X + "x", v, fontNormalColor);
                if (w < 1)
                {
                    v.Y += 16;
                    font.Draw("Computing: " + (int)(w * 100) + "%...", v, fontActionColor);
                }

                // draw help

                int h = driver.ScreenSize.Height;
                driver.Draw2DRectangle(new Recti(10, showHelp ? h - 130 : h - 40, showHelp ? 220 : 160, h - 10), fontBackgroundColor);

                v.Y = h - 34;
                font.Draw("[F1] " + (showHelp ? "Hide" : "Show") + " help", v, fontNormalColor);

                if (showHelp)
                {
                    v.Y = h - 124;
                    font.Draw("[Mouse Left Button] Navigate", v, fontNormalColor);
                    v.Y += 16;
                    font.Draw("[Mouse Wheel] Zoom in/out", v, fontNormalColor);
                    v.Y += 16;
                    font.Draw("[+][-][*][/] Max iterations", v, fontNormalColor);
                    v.Y += 16;
                    font.Draw("[PrintScreen] Save screenshot", v, fontNormalColor);
                    v.Y += 16;
                    font.Draw("[Esc] Exit application", v, fontNormalColor);
                }

                driver.EndScene();
                device.Yield();
            }

            fGen.Drop();
            device.Drop();
        }
Beispiel #4
0
		static void Main(string[] args)
		{
			device = IrrlichtDevice.CreateDevice(DriverType.Direct3D8, new Dimension2Di(1024, 768));
			if (device == null)
				return;

			device.SetWindowCaption("Fractal Generator - Irrlicht Engine");
			device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);

			VideoDriver driver = device.VideoDriver;
			GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png");
			Color fontBackgroundColor = new Color(0x7f000000);
			Color fontNormalColor = Color.OpaqueWhite;
			Color fontActionColor = Color.OpaqueYellow;

			fGen = new FractalGenerator(device);
			fGen.Generate(new Rectd(
				-driver.ScreenSize.Width / 250.0,
				-driver.ScreenSize.Height / 250.0,
				driver.ScreenSize.Width / 250.0,
				driver.ScreenSize.Height / 250.0));

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

				Vector2Di o = null;
				if (mouseMoveStart != null)
					o = device.CursorControl.Position - mouseMoveStart;

				float w = fGen.DrawAll(o);

				// draw stats

				driver.Draw2DRectangle(new Recti(10, 10, 160, 56 + (w < 1 ? 16 : 0)), fontBackgroundColor);

				Vector2Di v = new Vector2Di(20, 16);
				font.Draw("Max iterations: " + fGen.GetMaxIterations(), v, fontNormalColor);
				v.Y += 16;
				font.Draw("Zoom: " + (long)fGen.GetZoomFactor().X + "x", v, fontNormalColor);
				if (w < 1)
				{
					v.Y += 16;
					font.Draw("Computing: " + (int)(w * 100) + "%...", v, fontActionColor);
				}

				// draw help

				int h = driver.ScreenSize.Height;
				driver.Draw2DRectangle(new Recti(10, showHelp ? h - 130 : h - 40, showHelp ? 220 : 160, h - 10), fontBackgroundColor);

				v.Y = h - 34;
				font.Draw("[F1] " + (showHelp ? "Hide" : "Show") + " help", v, fontNormalColor);

				if (showHelp)
				{
					v.Y = h - 124;
					font.Draw("[Mouse Left Button] Navigate", v, fontNormalColor);
					v.Y += 16;
					font.Draw("[Mouse Wheel] Zoom in/out", v, fontNormalColor);
					v.Y += 16;
					font.Draw("[+][-][*][/] Max iterations", v, fontNormalColor);
					v.Y += 16;
					font.Draw("[PrintScreen] Save screenshot", v, fontNormalColor);
					v.Y += 16;
					font.Draw("[Esc] Exit application", v, fontNormalColor);
				}

				driver.EndScene();
				device.Yield();
			}

			fGen.Drop();
			device.Drop();
		}
Beispiel #5
0
        static void Main(string[] args)
        {
            DriverType?driverType = AskForDriver();

            if (!driverType.HasValue)
            {
                return;
            }

            device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(800, 600), 16);
            if (device == null)
            {
                return;
            }

            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);
            device.SetWindowResizable(true);
            device.SetWindowCaption("Irrlicht Engine - Loading...");

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

            smgr.Attributes.SetValue(SceneParameters.COLLADA_CreateSceneInstances, true);

            driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true);

            smgr.AddLightSceneNode(null, new Vector3Df(200), new Colorf(1.0f, 1.0f, 1.0f), 2000);
            smgr.AmbientLight = new Colorf(0.3f, 0.3f, 0.3f);

            // add our media directory as "search path"
            device.FileSystem.AddFileArchive("../../media/");

            // read configuration from xml file
            // (we use .NET way to do this, since Lime doesn't support native Irrlicht' xml reader)
            XmlDocument xml = new XmlDocument();

            xml.Load("../../media/config.xml");
            startUpModelFile = xml.DocumentElement["startUpModel"].Attributes["file"].Value;
            caption          = xml.DocumentElement["messageText"].Attributes["caption"].Value;
            messageText      = xml.DocumentElement["messageText"].InnerText;

            if (args.Length > 0)
            {
                startUpModelFile = args[0];
            }

            // set a nicer font
            GUIFont font = env.GetFont("fonthaettenschweiler.bmp");

            if (font != null)
            {
                env.Skin.SetFont(font);
            }

            // load the irrlicht engine logo
            GUIImage img = env.AddImage(
                driver.GetTexture("irrlichtlogoalpha2.tga"),
                new Vector2Di(10, driver.ScreenSize.Height - 128));

            img.ID = (int)guiID.Logo;

            // lock the logo's edges to the bottom left corner of the screen
            img.SetAlignment(GUIAlignment.UpperLeft, GUIAlignment.UpperLeft, GUIAlignment.LowerRight, GUIAlignment.LowerRight);

            // create menu
            GUIContextMenu menu = env.AddMenu();

            menu.AddItem("File", -1, true, true);
            menu.AddItem("View", -1, true, true);
            menu.AddItem("Camera", -1, true, true);
            menu.AddItem("Help", -1, true, true);

            GUIContextMenu submenu;

            submenu = menu.GetSubMenu(0);
            submenu.AddItem("Open Model File & Texture...", (int)guiID.OpenModel);
            submenu.AddItem("Set Model Archive...", (int)guiID.SetModelArchive);
            submenu.AddItem("Load as Octree", (int)guiID.LoadAsOctree);
            submenu.AddSeparator();
            submenu.AddItem("Quit", (int)guiID.Quit);

            submenu = menu.GetSubMenu(1);
            submenu.AddItem("sky box visible", (int)guiID.SkyBoxVisible, true, false, true);
            submenu.AddItem("toggle model debug information", (int)guiID.ToggleDebugInfo, true, true);
            submenu.AddItem("model material", -1, true, true);

            submenu = submenu.GetSubMenu(1);
            submenu.AddItem("Off", (int)guiID.DebugOff);
            submenu.AddItem("Bounding Box", (int)guiID.DebugBoundingBox);
            submenu.AddItem("Normals", (int)guiID.DebugNormals);
            submenu.AddItem("Skeleton", (int)guiID.DebugSkeleton);
            submenu.AddItem("Wire overlay", (int)guiID.DebugWireOverlay);
            submenu.AddItem("Half-Transparent", (int)guiID.DebugHalfTransparent);
            submenu.AddItem("Buffers bounding boxes", (int)guiID.DebugBuffersBoundingBoxes);
            submenu.AddItem("All", (int)guiID.DebugAll);

            submenu = menu.GetSubMenu(1).GetSubMenu(2);
            submenu.AddItem("Solid", (int)guiID.ModelMaterialSolid);
            submenu.AddItem("Transparent", (int)guiID.ModelMaterialTransparent);
            submenu.AddItem("Reflection", (int)guiID.ModelMaterialReflection);

            submenu = menu.GetSubMenu(2);
            submenu.AddItem("Maya Style", (int)guiID.CameraMaya);
            submenu.AddItem("First Person", (int)guiID.CameraFirstPerson);

            submenu = menu.GetSubMenu(3);
            submenu.AddItem("About", (int)guiID.About);

            // create toolbar

            GUIToolBar bar = env.AddToolBar();

            Texture image = driver.GetTexture("open.png");

            bar.AddButton((int)guiID.ButtonOpenModel, null, "Open a model", image, null, false, true);

            image = driver.GetTexture("tools.png");
            bar.AddButton((int)guiID.ButtonShowToolbox, null, "Open Toolset", image, null, false, true);

            image = driver.GetTexture("zip.png");
            bar.AddButton((int)guiID.ButtonSelectArchive, null, "Set Model Archive", image, null, false, true);

            image = driver.GetTexture("help.png");
            bar.AddButton((int)guiID.ButtonShowAbout, null, "Open Help", image, null, false, true);

            // create a combobox with some senseless texts

            GUIComboBox box = env.AddComboBox(new Recti(250, 4, 350, 23), bar, (int)guiID.TextureFilter);

            box.AddItem("No filtering");
            box.AddItem("Bilinear");
            box.AddItem("Trilinear");
            box.AddItem("Anisotropic");
            box.AddItem("Isotropic");

            // disable alpha
            setSkinTransparency(255, env.Skin);

            // add a tabcontrol
            createToolBox();

            // create fps text
            GUIStaticText fpstext = env.AddStaticText("", new Recti(400, 4, 570, 23), true, false, bar);
            GUIStaticText postext = env.AddStaticText("", new Recti(10, 50, 470, 80), false, false, null, (int)guiID.PositionText);

            postext.Visible = false;

            // show about message box and load default model
            if (args.Length == 0)
            {
                showAboutText();
            }

            loadModel(startUpModelFile);

            // add skybox

            skybox = smgr.AddSkyBoxSceneNode(
                "irrlicht2_up.jpg", "irrlicht2_dn.jpg",
                "irrlicht2_lf.jpg", "irrlicht2_rt.jpg",
                "irrlicht2_ft.jpg", "irrlicht2_bk.jpg");

            // add a camera scene node

            camera[0]          = smgr.AddCameraSceneNodeMaya();
            camera[0].FarValue = 20000;
            // Maya cameras reposition themselves relative to their target,
            // so target the location where the mesh scene node is placed.
            camera[0].Target = new Vector3Df(0, 30, 0);

            camera[1]          = smgr.AddCameraSceneNodeFPS();
            camera[1].FarValue = 20000;
            camera[1].Position = new Vector3Df(0, 0, -70);
            camera[1].Target   = new Vector3Df(0, 30, 0);

            setActiveCamera(camera[0]);

            // set window caption
            caption = string.Format("{0} - [{1}]", caption, driver.Name);
            device.SetWindowCaption(caption);

            // remember state so we notice when the window does lose the focus
            bool hasFocus = device.WindowFocused;

            // draw everything
            while (device.Run() && driver != null)
            {
                // Catch focus changes (workaround until Irrlicht has events for this)
                bool focused = device.WindowFocused;
                if (hasFocus && !focused)
                {
                    onKillFocus();
                }

                hasFocus = focused;

                if (device.WindowActive)
                {
                    driver.BeginScene(ClearBufferFlag.All, new Color(50, 50, 50));
                    smgr.DrawAll();
                    env.DrawAll();
                    driver.EndScene();

                    string str = string.Format("FPS: {0} Tris: {1}", driver.FPS, driver.PrimitiveCountDrawn);
                    fpstext.Text = str;

                    CameraSceneNode cam = device.SceneManager.ActiveCamera;
                    str          = string.Format("Pos: {0} Tgt: {1}", cam.Position, cam.Target);
                    postext.Text = str;
                }
                else
                {
                    device.Yield();
                }
            }

            device.Drop();
        }
Beispiel #6
0
		static void Main(string[] args)
		{
			checkBulletSharpDllPresence();

			// setup Irrlicht

			device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1024, 768));
			if (device == null)
				return;

			device.SetWindowCaption("BulletSharp Test - Irrlicht Engine");
			device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);

			VideoDriver driver = device.VideoDriver;
			SceneManager scene = device.SceneManager;
			GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png");

			CameraSceneNode camera = scene.AddCameraSceneNodeFPS();
			camera.Position = new Vector3Df(100, 800, -1000);
			camera.Target = new Vector3Df(0, 100, 0);
			camera.FarValue = 30000;
			camera.AutomaticCulling = CullingType.FrustumBox;

			device.CursorControl.Visible = false;

			// setup physics

			physics = new Physics();
			physics.Setup(new Vector3Df(0, -worldGravity, 0));

			// setup particles

			particles = new Particles(device);

			// load quake level

			device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3");

			Mesh mesh = scene.GetMesh("20kdm2.bsp").GetMesh(0);
			SceneNode quakeLevel = scene.AddOctreeSceneNode(mesh, null, -1, 1024);
			quakeLevel.Position = new Vector3Df(-1300, -144, -1249);

			physics.AddShape(Physics.Shape.Mesh, quakeLevel);

			// generate dynamic objects

			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 30; j++)
				{
					for (int k = 0; k < 3; k++)
					{
						MeshSceneNode n = scene.AddCubeSceneNode(cubeSize);
						n.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp"));
						n.SetMaterialFlag(MaterialFlag.Lighting, false);
						n.Position = new Vector3Df(70 + i * cubeSize, 520 + j * cubeSize, -650 + k * cubeSize);

						physics.AddShape(Physics.Shape.Box, n, cubeMass);
					}
				}
			}

			// main loop

			uint curTime = 0;
			uint lastTime = 0;
			int simFps = 0;
			int simFrames = 0;
			uint simFramesTime = 0;

			while (device.Run())
			{
				if (device.WindowActive)
				{
					// simulate physics

					lastTime = curTime;
					curTime = device.Timer.Time;
					if (!simPaused)
					{
						float deltaTime = (curTime - lastTime) / 1000.0f;
						bool b = physics.StepSimulation(deltaTime);
						if (b) simFrames++;
					}

					if (curTime - simFramesTime > 1000)
					{
						simFramesTime = curTime;
						simFps = simFrames;
						simFrames = 0;
					}

					// winnow particles

					particles.Winnow(curTime, simPaused);

					// render scene

					driver.BeginScene(true, true, new Color(40, 80, 160));
					scene.DrawAll();

					Material material = new Material();
					material.Lighting = false;
					device.VideoDriver.SetMaterial(material);

					// display stats

					driver.Draw2DRectangle(new Recti(10, 10, 140, 180), new Color(0x7f000000));

					Vector2Di v = new Vector2Di(20, 20);
					font.Draw("Rendering", v, Color.OpaqueYellow);
					v.Y += 16;
					font.Draw(scene.Attributes.GetValue("calls") + " nodes", v, Color.OpaqueWhite);
					v.Y += 16;
					font.Draw(driver.FPS + " fps", v, Color.OpaqueWhite);
					v.Y += 16;
					font.Draw("[T]rails " + (useTrails ? "ON" : "OFF"), v, Color.OpaqueGreen);
					v.Y += 32;
					font.Draw("Physics" + (simPaused ? " (paused)" : ""), v, Color.OpaqueYellow);
					v.Y += 16;
					font.Draw(physics.NumCollisionObjects + " shapes", v, Color.OpaqueWhite);
					v.Y += 16;
					font.Draw(simFps + " fps", v, Color.OpaqueWhite);
					v.Y += 16;
					font.Draw("[Space] to pause", v, Color.OpaqueGreen);

					driver.EndScene();
				}

				device.Yield();
			}

			// drop

			physics.Drop();
			device.Drop();
		}
Beispiel #7
0
        static void Main(string[] args)
        {
            checkBulletSharpDllPresence();

            // setup Irrlicht

            device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1024, 768));
            if (device == null)
            {
                return;
            }

            device.SetWindowCaption("BulletSharp Test - Irrlicht Engine");
            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);

            VideoDriver  driver = device.VideoDriver;
            SceneManager scene  = device.SceneManager;
            GUIFont      font   = device.GUIEnvironment.GetFont("../../media/fontlucida.png");

            CameraSceneNode camera = scene.AddCameraSceneNodeFPS();

            camera.Position         = new Vector3Df(100, 800, -1000);
            camera.Target           = new Vector3Df(0, 100, 0);
            camera.FarValue         = 30000;
            camera.AutomaticCulling = CullingType.FrustumBox;

            device.CursorControl.Visible = false;

            // setup physics

            physics = new Physics();
            physics.Setup(new Vector3Df(0, -worldGravity, 0));

            // setup particles

            particles = new Particles(device);

            // load quake level

            device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3");

            Mesh      mesh       = scene.GetMesh("20kdm2.bsp").GetMesh(0);
            SceneNode quakeLevel = scene.AddOctreeSceneNode(mesh, null, -1, 1024);

            quakeLevel.Position = new Vector3Df(-1300, -144, -1249);

            physics.AddShape(Physics.Shape.Mesh, quakeLevel);

            // generate dynamic objects

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 30; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        MeshSceneNode n = scene.AddCubeSceneNode(cubeSize);
                        n.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp"));
                        n.SetMaterialFlag(MaterialFlag.Lighting, false);
                        n.Position = new Vector3Df(70 + i * cubeSize, 520 + j * cubeSize, -650 + k * cubeSize);

                        physics.AddShape(Physics.Shape.Box, n, cubeMass);
                    }
                }
            }

            // main loop

            uint curTime       = 0;
            uint lastTime      = 0;
            int  simFps        = 0;
            int  simFrames     = 0;
            uint simFramesTime = 0;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    // simulate physics

                    lastTime = curTime;
                    curTime  = device.Timer.Time;
                    if (!simPaused)
                    {
                        float deltaTime = (curTime - lastTime) / 1000.0f;
                        bool  b         = physics.StepSimulation(deltaTime);
                        if (b)
                        {
                            simFrames++;
                        }
                    }

                    if (curTime - simFramesTime > 1000)
                    {
                        simFramesTime = curTime;
                        simFps        = simFrames;
                        simFrames     = 0;
                    }

                    // winnow particles

                    particles.Winnow(curTime, simPaused);

                    // render scene

                    driver.BeginScene(true, true, new Color(40, 80, 160));
                    scene.DrawAll();

                    Material material = new Material();
                    material.Lighting = false;
                    device.VideoDriver.SetMaterial(material);

                    // display stats

                    driver.Draw2DRectangle(new Recti(10, 10, 140, 180), new Color(0x7f000000));

                    Vector2Di v = new Vector2Di(20, 20);
                    font.Draw("Rendering", v, Color.OpaqueYellow);
                    v.Y += 16;
                    font.Draw(scene.Attributes.GetValue("calls") + " nodes", v, Color.OpaqueWhite);
                    v.Y += 16;
                    font.Draw(driver.FPS + " fps", v, Color.OpaqueWhite);
                    v.Y += 16;
                    font.Draw("[T]rails " + (useTrails ? "ON" : "OFF"), v, Color.OpaqueGreen);
                    v.Y += 32;
                    font.Draw("Physics" + (simPaused ? " (paused)" : ""), v, Color.OpaqueYellow);
                    v.Y += 16;
                    font.Draw(physics.NumCollisionObjects + " shapes", v, Color.OpaqueWhite);
                    v.Y += 16;
                    font.Draw(simFps + " fps", v, Color.OpaqueWhite);
                    v.Y += 16;
                    font.Draw("[Space] to pause", v, Color.OpaqueGreen);

                    driver.EndScene();
                }

                device.Yield();
            }

            // drop

            physics.Drop();
            device.Drop();
        }
Beispiel #8
0
		static void Main(string[] args)
		{
			DriverType driverType;
			if (!AskUserForDriver(out driverType))
				return;

			device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(800, 600), 16);
			if (device == null)
				return;

			device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);
			device.SetWindowResizable(true);
			device.SetWindowCaption("Irrlicht Engine - Loading...");

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

			smgr.Attributes.SetValue(SceneParameters.COLLADA_CreateSceneInstances, true);

			driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true);

			smgr.AddLightSceneNode(null, new Vector3Df(200), new Colorf(1.0f, 1.0f, 1.0f), 2000);
			smgr.AmbientLight = new Colorf(0.3f, 0.3f, 0.3f);

			// add our media directory as "search path"
			device.FileSystem.AddFileArchive("../../media/");

			// read configuration from xml file
			// (we use .NET way to do this, since Lime doesn't support native Irrlicht' xml reader)
			XmlDocument xml = new XmlDocument();
			xml.Load("../../media/config.xml");
			startUpModelFile = xml.DocumentElement["startUpModel"].Attributes["file"].Value;
			caption = xml.DocumentElement["messageText"].Attributes["caption"].Value;
			messageText = xml.DocumentElement["messageText"].InnerText;

			if (args.Length > 0)
				startUpModelFile = args[0];

			// set a nicer font
			GUIFont font = env.GetFont("fonthaettenschweiler.bmp");
			if (font != null)
				env.Skin.SetFont(font);

			// load the irrlicht engine logo
			GUIImage img = env.AddImage(
				driver.GetTexture("irrlichtlogoalpha2.tga"),
				new Vector2Di(10, (int)driver.ScreenSize.Height - 128));
			img.ID = (int)guiID.Logo;

			// lock the logo's edges to the bottom left corner of the screen
			img.SetAlignment(GUIAlignment.UpperLeft, GUIAlignment.UpperLeft, GUIAlignment.LowerRight, GUIAlignment.LowerRight);

			// create menu
			GUIContextMenu menu = env.AddMenu();
			menu.AddItem("File", -1, true, true);
			menu.AddItem("View", -1, true, true);
			menu.AddItem("Camera", -1, true, true);
			menu.AddItem("Help", -1, true, true);

			GUIContextMenu submenu;
			submenu = menu.GetSubMenu(0);
			submenu.AddItem("Open Model File & Texture...", (int)guiID.OpenModel);
			submenu.AddItem("Set Model Archive...", (int)guiID.SetModelArchive);
			submenu.AddItem("Load as Octree", (int)guiID.LoadAsOctree);
			submenu.AddSeparator();
			submenu.AddItem("Quit", (int)guiID.Quit);

			submenu = menu.GetSubMenu(1);
			submenu.AddItem("sky box visible", (int)guiID.SkyBoxVisible, true, false, true);
			submenu.AddItem("toggle model debug information", (int)guiID.ToggleDebugInfo, true, true);
			submenu.AddItem("model material", -1, true, true);

			submenu = submenu.GetSubMenu(1);
			submenu.AddItem("Off", (int)guiID.DebugOff);
			submenu.AddItem("Bounding Box", (int)guiID.DebugBoundingBox);
			submenu.AddItem("Normals", (int)guiID.DebugNormals);
			submenu.AddItem("Skeleton", (int)guiID.DebugSkeleton);
			submenu.AddItem("Wire overlay", (int)guiID.DebugWireOverlay);
			submenu.AddItem("Half-Transparent", (int)guiID.DebugHalfTransparent);
			submenu.AddItem("Buffers bounding boxes", (int)guiID.DebugBuffersBoundingBoxes);
			submenu.AddItem("All", (int)guiID.DebugAll);

			submenu = menu.GetSubMenu(1).GetSubMenu(2);
			submenu.AddItem("Solid", (int)guiID.ModelMaterialSolid);
			submenu.AddItem("Transparent", (int)guiID.ModelMaterialTransparent);
			submenu.AddItem("Reflection", (int)guiID.ModelMaterialReflection);

			submenu = menu.GetSubMenu(2);
			submenu.AddItem("Maya Style", (int)guiID.CameraMaya);
			submenu.AddItem("First Person", (int)guiID.CameraFirstPerson);

			submenu = menu.GetSubMenu(3);
			submenu.AddItem("About", (int)guiID.About);

			// create toolbar

			GUIToolBar bar = env.AddToolBar();

			Texture image = driver.GetTexture("open.png");
			bar.AddButton((int)guiID.ButtonOpenModel, null, "Open a model", image, null, false, true);

			image = driver.GetTexture("tools.png");
			bar.AddButton((int)guiID.ButtonShowToolbox, null, "Open Toolset", image, null, false, true);

			image = driver.GetTexture("zip.png");
			bar.AddButton((int)guiID.ButtonSelectArchive, null, "Set Model Archive", image, null, false, true);

			image = driver.GetTexture("help.png");
			bar.AddButton((int)guiID.ButtonShowAbout, null, "Open Help", image, null, false, true);

			// create a combobox with some senseless texts

			GUIComboBox box = env.AddComboBox(new Recti(250, 4, 350, 23), bar, (int)guiID.TextureFilter);
			box.AddItem("No filtering");
			box.AddItem("Bilinear");
			box.AddItem("Trilinear");
			box.AddItem("Anisotropic");
			box.AddItem("Isotropic");

			// disable alpha
			setSkinTransparency(255, env.Skin);

			// add a tabcontrol
			createToolBox();

			// create fps text
			GUIStaticText fpstext = env.AddStaticText("", new Recti(400, 4, 570, 23), true, false, bar);
			GUIStaticText postext = env.AddStaticText("", new Recti(10, 50, 470, 80), false, false, null, (int)guiID.PositionText);
			postext.Visible = false;

			// show about message box and load default model
			if (args.Length == 0)
				showAboutText();

			loadModel(startUpModelFile);

			// add skybox

			skybox = smgr.AddSkyBoxSceneNode(
				"irrlicht2_up.jpg", "irrlicht2_dn.jpg",
				"irrlicht2_lf.jpg", "irrlicht2_rt.jpg",
				"irrlicht2_ft.jpg", "irrlicht2_bk.jpg");

			// add a camera scene node

			camera[0] = smgr.AddCameraSceneNodeMaya();
			camera[0].FarValue = 20000;
			// Maya cameras reposition themselves relative to their target,
			// so target the location where the mesh scene node is placed.
			camera[0].Target = new Vector3Df(0, 30, 0);

			camera[1] = smgr.AddCameraSceneNodeFPS();
			camera[1].FarValue = 20000;
			camera[1].Position = new Vector3Df(0, 0, -70);
			camera[1].Target = new Vector3Df(0, 30, 0);

			setActiveCamera(camera[0]);

			// set window caption
			caption = string.Format("{0} - [{1}]", caption, driver.Name);
			device.SetWindowCaption(caption);

			// remember state so we notice when the window does lose the focus
			bool hasFocus = device.WindowFocused;

			// draw everything
			while (device.Run() && driver != null)
			{
				// Catch focus changes (workaround until Irrlicht has events for this)
				bool focused = device.WindowFocused;
				if (hasFocus && !focused)
					onKillFocus();

				hasFocus = focused;

				if (device.WindowActive)
				{
					driver.BeginScene(true, true, new Color(50, 50, 50));
					smgr.DrawAll();
					env.DrawAll();
					driver.EndScene();

					string str = string.Format("FPS: {0} Tris: {1}", driver.FPS, driver.PrimitiveCountDrawn);
					fpstext.Text = str;

					CameraSceneNode cam = device.SceneManager.ActiveCamera;
					str = string.Format("Pos: {0} Tgt: {1}", cam.Position, cam.Target);
					postext.Text = str;
				}
				else
					device.Yield();
			}

			device.Drop();
		}
        /// <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!");
                }
                device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);

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

                var animText = "";
                if (Animations.AnimationNames.Count > 0 && currAnimIdx != -1)
                {
                    animText = "Animation: " + Animations.AnimationNames[currAnimIdx].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 = 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 && currAnimIdx != -1)
                    {
                        anims.Apply(skinnedMesh);
                    }
                }
                skinnedMesh.SetDirty(HardwareBufferType.VertexAndIndex);
                skinnedMesh.FinalizeMeshPopulation();

                AnimatedMeshSceneNode n = smgr.AddAnimatedMeshSceneNode(skinnedMesh);
                if (n == null)
                {
                    throw new Exception("Could not create animated scene node!");
                }
                else
                {
                    node = n;
                }

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

                SetMaterials(driver);

                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
                {
                    Lighting = false
                };

                resetDebugViewMenu();                                                       //reset debug view featchers
                smgr.Attributes.SetValue(SceneParameters.DebugNormalLength, scaleMul / 2);  //calculate normals length

                // main drawing loop
                while (device.Run() && driver != null)
                {
                    if (this.Visible)
                    {
                        driver.ViewPort = viewPort;
                        driver.BeginScene(ClearBufferFlag.All, new Color(100, 101, 140));

                        node.Position = modelPosition;
                        node.Rotation = modelAngle;

                        //update info box
                        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();


                        // draw xyz axis right bottom
                        driver.ViewPort = new Recti(this.ClientSize.Width - 100, this.ClientSize.Height - 80, this.ClientSize.Width, this.ClientSize.Height);

                        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.SolidGreen);
                        driver.Draw3DLine(0, 0, 0, 0, 30f, 0, Color.SolidBlue);
                        driver.Draw3DLine(0, 0, 0, 0, 0, 30f, Color.SolidRed);

                        driver.EndScene();
                    }
                    else
                    {
                        device.Yield();
                    }
                }

                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
        }
        void ProcessCommand()
        {
            queueSizeBar.Invoke((MethodInvoker) delegate
            {
                if (commandQueue.Count > queueSizeBar.Maximum)
                {
                    queueSizeBar.Maximum = commandQueue.Count;
                    queueSizeBar.Value   = queueSizeBar.Maximum;
                }
                else
                {
                    queueSizeBar.Value = commandQueue.Count;
                }
            });

            RenderMessage m;

            if (commandQueue.TryDequeue(out m))
            {
                switch (m.Message)
                {
                case MessageType.SHOW_NODE:
                {
                    m.Node.Visible = true;
                    var camera = smgr.ActiveCamera;

                    // just set the target
                    camera.Target      = m.Node.AbsolutePosition;
                    lightNode.Position = camera.Position;
                }
                break;

                case MessageType.HIDE_NODE:
                {
                    m.Node.Visible = false;
                }
                break;

                case MessageType.SELECT_NODE:
                {
                    // highlight and
                    smgr.SelectNode(m.Node);
                    var camera = smgr.ActiveCamera;

                    // just set the target
                    camera.Target      = m.Node.AbsolutePosition;
                    lightNode.Position = camera.Position;
                }
                break;

                case MessageType.ADD_MESH_NODE:
                {
                    IrrlichtLime.Scene.Mesh mesh = smgr.GetStaticMesh(depot + m.MeshName);
                    foreach (var mb in mesh.MeshBuffers)
                    {
                        totalVertexCount += mb.VertexCount;
                    }
                    MeshSceneNode meshNode = smgr.AddMeshSceneNode(mesh, worldNode, meshId++, m.Translation, m.Rotation);
#if DEBUG
                    meshNode.Name = m.MeshName;
#endif
                    meshNode.Grab();

                    RenderTreeNode rn = new RenderTreeNode(m.MeshName, meshNode);
                    if (m.TreeNode.GetNodeCount(false) > 0)
                    {
                        // TODO: does this need to be invoked?
                        sceneView.Invoke((MethodInvoker) delegate
                            {
                                m.TreeNode.Nodes.Add(rn);
                            });
                    }
                    else
                    {
                        sceneView.Invoke((MethodInvoker) delegate
                            {
                                sceneView.Nodes.Add(m.TreeNode);
                                m.TreeNode.Nodes.Add(rn);
                            });
                    }

                    ++totalMeshCount;

                    vertexCountText.Text = "Vertices: " + totalVertexCount.ToString();
                    meshCountText.Text   = "Meshes: " + totalMeshCount.ToString();
                }
                break;

                case MessageType.ADD_TERRAIN_NODE:
                {
                    var meshNode = smgr.AddTerrainSceneNodeWolvenKit(depot + m.MeshName, worldNode, meshId, m.TileRes, m.MaxHeight, m.MinHeight, m.TerrainSize, m.Translation);
                    meshNode.Grab();
                    foreach (var mb in meshNode.Mesh.MeshBuffers)
                    {
                        totalVertexCount += mb.VertexCount;
                    }

                    RenderTreeNode rn = new RenderTreeNode("Tile " + meshId.ToString(), meshNode);
                    meshId++;

                    if (m.TreeNode.GetNodeCount(false) > 0)
                    {
                        // TODO: does this need to be invoked?
                        sceneView.Invoke((MethodInvoker) delegate
                            {
                                m.TreeNode.Nodes.Add(rn);
                            });
                    }
                    else
                    {
                        sceneView.Invoke((MethodInvoker) delegate
                            {
                                sceneView.Nodes.Add(m.TreeNode);
                                m.TreeNode.Nodes.Add(rn);
                            });
                    }

                    ++totalMeshCount;

                    vertexCountText.Text = "Vertices: " + totalVertexCount.ToString();
                    meshCountText.Text   = "Meshes: " + totalMeshCount.ToString();
                }
                break;

                case MessageType.DESELECT_NODE:
                {
                    smgr.DeselectNode();
                }
                break;

                case MessageType.HIGHLIGHT_NODE:
                {
                    smgr.SelectNode(m.Node);
                }
                break;

                case MessageType.SHUTDOWN:
                {
                    device.Yield();
                }
                break;

                default:
                    break;
                }
            }
        }
Beispiel #12
0
        ParticleRotationAffector affRotation;       // its pointer back later :(

        void irrThreadMain(object args)
        {
            irrDevice = IrrlichtDevice.CreateDevice(args as IrrlichtCreationParameters);

            // Camera

            CameraSceneNode   camera = irrDevice.SceneManager.AddCameraSceneNode(null, new Vector3Df(0), new Vector3Df(0, 80, 0), (int)SceneNodeID.Camera);
            SceneNodeAnimator anim   = irrDevice.SceneManager.CreateFlyCircleAnimator(new Vector3Df(0, 100, 0), 200.0f, 0.0002f);

            camera.AddAnimator(anim);
            anim.Drop();

            // Skydome

            irrDevice.SceneManager.AddSkyDomeSceneNode(irrDevice.VideoDriver.GetTexture("../../media/skydome.jpg"), 16, 8, 0.95f, 2.0f);

            // Plane

            var m = irrDevice.SceneManager.AddHillPlaneMesh("plane", new Dimension2Df(1000), new Dimension2Di(1), null, 0, new Dimension2Df(0), new Dimension2Df(8));
            var n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.Plane);

            n.SetMaterialFlag(MaterialFlag.Lighting, false);
            n.SetMaterialTexture(0, irrDevice.VideoDriver.GetTexture("../../media/rockwall.jpg"));

            // Axes

            m = irrDevice.SceneManager.AddArrowMesh("axisX");
            n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.AxisX, new Vector3Df(), new Vector3Df(0, 0, -90), new Vector3Df(50, 120, 50));
            n.GetMaterial(0).EmissiveColor = new Color(250, 250, 250);
            n.GetMaterial(1).EmissiveColor = new Color(250, 0, 0);

            m = irrDevice.SceneManager.AddArrowMesh("axisY");
            n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.AxisY, new Vector3Df(), new Vector3Df(0, 0, 0), new Vector3Df(50, 120, 50));
            n.GetMaterial(0).EmissiveColor = new Color(250, 250, 250);
            n.GetMaterial(1).EmissiveColor = new Color(0, 250, 0);

            m = irrDevice.SceneManager.AddArrowMesh("axisZ");
            n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.AxisZ, new Vector3Df(), new Vector3Df(90, 0, 0), new Vector3Df(50, 120, 50));
            n.GetMaterial(0).EmissiveColor = new Color(250, 250, 250);
            n.GetMaterial(1).EmissiveColor = new Color(0, 0, 250);

            irrThreadShowAxes(false);

            // Particle system

            var ps = irrDevice.SceneManager.AddParticleSystemSceneNode(false, null, (int)SceneNodeID.ParticleSystem);

            ps.SetMaterialFlag(MaterialFlag.Lighting, false);
            ps.SetMaterialFlag(MaterialFlag.ZWrite, false);
            ps.SetMaterialTexture(0, irrDevice.VideoDriver.GetTexture("../../media/particle.bmp"));
            ps.SetMaterialType(MaterialType.TransparentAddColor);

            ParticleEmitter em = ps.CreateSphereEmitter(
                new Vector3Df(), 20,                                    // position and radius
                new Vector3Df(0.0f, 0.1f, 0.0f),                        // initial direction
                150, 300,                                               // emit rate
                new Color(255, 255, 255, 0),                            // darkest color
                new Color(255, 255, 255, 0),                            // brightest color
                750, 1500, 0,                                           // min and max age, angle
                new Dimension2Df(20.0f),                                // min size
                new Dimension2Df(40.0f));                               // max size

            ps.Emitter = em;
            em.Drop();

            // Particle affectors

            affFadeOut = ps.CreateFadeOutParticleAffector();
            ps.AddAffector(affFadeOut);
            affFadeOut.Drop();

            affGravity         = ps.CreateGravityAffector(new Vector3Df(0, -1, 0), 3000);
            affGravity.Enabled = false;
            ps.AddAffector(affGravity);
            affGravity.Drop();

            affRotation = ps.CreateRotationAffector(new Vector3Df(-90, 240, -120), new Vector3Df(0, 100, 0));
            ps.AddAffector(affRotation);
            affRotation.Drop();

            // Rendering loop

            uint rs = 0, re = 0;             // render frame time

            while (irrDevice.Run())
            {
                if (irrDevice.VideoDriver.ScreenSize.Area != 0)
                {
                    irrDevice.VideoDriver.BeginScene();
                    irrDevice.SceneManager.DrawAll();
                    re = irrDevice.Timer.Time;

                    irrThreadDrawText(new Vector2Di(8, 8),
                                      "Frame time: " + (irrDevice.VideoDriver.FPS > 1000 ? "< 1" : (re - rs).ToString()) + " ms");

                    irrDevice.VideoDriver.EndScene();
                    irrDevice.Yield();
                }
                else
                {
                    Thread.Sleep(50);
                }

                irrThreadProcessCommandQueue();
                rs = irrDevice.Timer.Time;
            }

            irrDevice.Drop();
        }