static void Main(string[] args) { //We choosed OpenGL because it is cross-platform and GUI does not need //Amazing performances... IrrlichtDevice device = new IrrlichtDevice(DriverType.OpenGL, new Dimension2D(640, 480), 16, false, false, false, false); //Delegate that will catch our events device.OnEvent += new OnEventDelegate(device_OnEvent); //Does not seem to work on Linux but well... device.Resizeable = false; //We set a basic caption device.WindowCaption = "Irrlicht .NET CP General User Interface Example"; //We set our handlers driver = device.VideoDriver; guienv = device.GUIEnvironment; //We set the skin as a metallic windows skin guienv.Skin = guienv.CreateSkin(GUISkinTypes.WindowsMetallic); guienv.Skin.SetColor(GuiDefaultColor.ButtonText, Color.White); TTFont font = new TTFont(device.VideoDriver); font.Antialias = true; TTFace face = new TTFace(); face.Load("../../medias/FreeSans.ttf"); font.Attach(face, 14); guienv.Skin.Font = font; //Our fader. We set it as first because we don't want him to hide our buttons. guienv.AddInOutFader(null, (int)GUIItems.Fader); //We add several buttons with the IDs we defined downwards guienv.AddButton(new Rect(new Position2D(250, 0), new Dimension2D(140, 100)), null, (int)GUIItems.ClickMe, "Click me !"); guienv.AddButton(new Rect(new Position2D(250, 380), new Dimension2D(140, 100)), null, (int)GUIItems.DontClickMe, "Don't click me !"); guienv.AddButton(new Rect(new Position2D(0, 190), new Dimension2D(140, 100)), null, (int)GUIItems.FadeMe, "Fade me !"); guienv.AddButton(new Rect(new Position2D(500, 190), new Dimension2D(140, 100)), null, (int)GUIItems.FunnyEffect, "Funny effect !"); guienv.AddStaticText ("Move this scrollbar and you'll see the miracle !", new Rect(new Position2D(220, 240), new Dimension2D(240, 30)), false, true, null, -1, false); guienv.AddSpinBox ("", new Rect(new Position2D (220, 270), new Dimension2D (120, 30)), null, -1); guienv.AddEditBox ("", new Rect(new Position2D (220, 300), new Dimension2D (120, 30)), true, null, -1); listbox = guienv.AddListBox(new Rect(new Position2D(400, 20), new Dimension2D(220, 150)), null, -1, true); //Our logo guienv.AddImage(driver.GetTexture("../../medias/NETCPlogo.png"), new Position2D(0, 0), true, null, -1, ""); //And now the scrollbar GUIScrollBar scroll = guienv.AddScrollBar(true, new Rect(new Position2D(220, 220), new Dimension2D(240, 20)), null, (int)GUIItems.ScrollBar); el = new CustomElement(guienv, null, -1, new Rect(new Position2D(220, 120), new Dimension2D(160, 100))); //Var for the funny effects int toAdd = 1; //While the device is running and we don't want him to exit while (device.Run() && !Exit) { //If our funny effect is enabled, we just scroll the scrollbar //It may seems strange but the "ScrollBarChanged" event is NOT fired //When we manually change the position... It's a gift and a cursed, depending on the situation. if (FunnyEffectEnabled) { scroll.Pos += toAdd; if(scroll.Pos >= 100 || scroll.Pos <= 0) toAdd = -toAdd; BackColor = Color.From(255, 255-scroll.Pos * 5 / 2, 255 - (scroll.Pos * 5 / 2), scroll.Pos * 5 / 2); } //Here we are, we begin the scene //Notice that we DO NOT use the ZBuffer because we have only two dimensions driver.BeginScene(true, false, BackColor); //We draw all the GUI guienv.DrawAll(); //And we end driver.EndScene(); } //As in the first example, we need to release main resources device.DumpElements(); device.Close(); }
public static void Main(string[] args) { // Do a usuall setup DriverType driverType = DriverType.OpenGL; device = new IrrlichtDevice(driverType, new Dimension2D(640, 480), 32, false, true, true, true); device.FileSystem.WorkingDirectory = "../../medias"; device.OnEvent += new OnEventDelegate(device_OnEvent); SceneManager smgr = device.SceneManager; VideoDriver driver = device.VideoDriver; GUIEnvironment guienv = device.GUIEnvironment; guienv.Skin.SetColor(GuiDefaultColor.ButtonText, Color.White); guienv.AddImage(driver.GetTexture("NETCPlogo.png"), new Position2D(10, 10), true, null, 0, ""); // Static camera should be enough CameraSceneNode camera = smgr.AddCameraSceneNode(null); camera.Position = new Vector3D(0,40,-60); camera.Target = new Vector3D(0,40,0); smgr.AddLightSceneNode(null, new Vector3D(10, 9, 0), Colorf.White, 10.0f, -1); smgr.AddSkyBoxSceneNode(null, new Texture[] { driver.GetTexture("irrlicht2_up.jpg"), driver.GetTexture("irrlicht2_dn.jpg"), driver.GetTexture("irrlicht2_rt.jpg"), driver.GetTexture("irrlicht2_lf.jpg"), driver.GetTexture("irrlicht2_ft.jpg"), driver.GetTexture("irrlicht2_bk.jpg")}, 0); // The interesting part // First load the mesh with bones. AnimatedMesh mesh = smgr.GetMesh("dwarf.x"); // Check, whether our mesh has bones if (mesh.MeshType == AnimatedMeshType.Skinned) { // Create an animatedmesh scene node from it AnimatedMeshSceneNode mesh_node = smgr.AddAnimatedMeshSceneNode(mesh); // set joints to controllable state, or irrlicht will try to animate them mesh_node.JointMode = JointUpdateOnRenderMode.Control; // Get our bones by name bone1 = mesh_node.GetJointNode("spine2"); bone2 = mesh_node.GetJointNode("head"); bone3 = mesh_node.GetJointNode("rsholda"); // We add three scrollbars to control our bones guienv.AddStaticText("Torso", new Rect(new Position2D(40, driver.ViewPort.Height-110), new Dimension2D(240, 20)), false, false, null, -1, false); GUIScrollBar scroll = guienv.AddScrollBar(true, new Rect(new Position2D(40, driver.ViewPort.Height-100), new Dimension2D(240, 20)), null, 1); scroll.Max = 180; // Initial rotation of each bone is 0, so set the scrollbar position to the middle // to make controlling more cool scroll.Pos = 90; guienv.AddStaticText("Head", new Rect(new Position2D(40, driver.ViewPort.Height-80), new Dimension2D(240, 20)), false, false, null, -1, false); scroll = guienv.AddScrollBar(true, new Rect(new Position2D(40, driver.ViewPort.Height-70), new Dimension2D(240, 20)), null, 2); scroll.Max = 160; scroll.Pos = 80; guienv.AddStaticText("Axe", new Rect(new Position2D(40, driver.ViewPort.Height-50), new Dimension2D(240, 20)), false, false, null, -1, false); scroll = guienv.AddScrollBar(true, new Rect(new Position2D(40, driver.ViewPort.Height-40), new Dimension2D(240, 20)), null, 3); scroll.Max = 90; scroll.Pos = 45; } int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(true, true, new Color(0, 200, 200, 200)); smgr.DrawAll(); guienv.DrawAll(); driver.EndScene(); int fps = device.VideoDriver.FPS; if (lastFPS != fps) { device.WindowCaption = "Skinned Mesh - Irrlicht.NET CP Engine " + "FPS:" + fps.ToString(); lastFPS = fps; } } } device.DumpElements(); device.Close(); }
static void Main(string[] args) { IrrlichtDevice device = new IrrlichtDevice(DriverType.OpenGL, new Dimension2D(640, 480), 32, false, false, false, false); string basecaption = "Irrlicht .NET CP Examples - Custom Scene Node feature"; _scene = device.SceneManager; _driver = device.VideoDriver; CustomSceneNode myNode = new CustomSceneNode(null, _scene, 666); _scene.AddCameraSceneNode(null); _scene.ActiveCamera.Position = new Vector3D(0, -40, 0); _scene.ActiveCamera.Target = new Vector3D(); myNode.AddAnimator(new CustomAnimator(new Vector3D(0.8f, 0, 0.8f))); int lastfps = -1, fps = 0; while (device.Run()) { _driver.BeginScene(true, true, Color.Gray); _scene.DrawAll(); _driver.EndScene(); fps = _driver.FPS; if(fps != lastfps) { device.WindowCaption = basecaption + " - FPS : " + fps; lastfps = fps; } } device.DumpElements(); device.Close(); }