/// <summary> /// Létrehoz egy sizex*sizey méretű ablakot, windowCaption címmel és deviceType renderelési eszközzel. /// </summary> /// <param name="windowCaption">Ablak címe</param> /// <param name="sizex">Ablak szélessége</param> /// <param name="sizey">Ablak magassága</param> /// <param name="deviceType">A render eszköz típusa ("DriverType.OpenGL;" (OpenGL) vagy "DriverType.Direct3D8;"/"DriverType.Direct3D9;" (DirectX))</param> /// <param name="mapName">Betöltendő pálya neve a kiterjesztés nélkül (pl. "devmap")</param> /// <param name="pak0">A pak0 fájl neve (pl. "pak0" vagy "pack1")</param> /// <param name="pak1">A pak1 fájl neve (pl. "pak1" vagy "pack4")</param> /// <param name="pak2">A pak2 fájl neve (pl. "pak2" vagy "pack2")</param> public static void createScreen(string windowCaption, int sizex, int sizey, DriverType deviceType, string mapName, string pak0, string pak1, string pak2, bool isFullScreen) { //Ablakot megjeleníteni if (isFullScreen == true) { device = IrrlichtDevice.CreateDevice(deviceType, new Dimension2Di(sizex, sizey), 32, true, false, true); } else { device = IrrlichtDevice.CreateDevice(deviceType, new Dimension2Di(sizex, sizey), 32, false, false, true); } if (device == null) return; AnimatedMesh q3levelmesh = null; device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.SetWindowCaption(Property.modName + " Build " + Property.modVersion); driver = device.VideoDriver; smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; //fadein GUIInOutFader fader = device.GUIEnvironment.AddInOutFader(); fader.SetColor(new Color(0, 0, 0, 255)); fader.FadeIn(2000); //hurtOverlay = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/Overlays/hurt.png"), new Vector2Di(0, 0)); //hurtOverlay.Visible = false; GUIImage copyrightScreen = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/exit.tga"), new Vector2Di(0, 0)); float guiScalex = sizex / 800; float guiScaley = sizey / 600; copyrightScreen.Visible = false; copyrightScreen.ScaleImage = true; copyrightScreen.SetMaxSize(new Dimension2Di(sizex, sizey)); copyrightScreen.SetMinSize(new Dimension2Di(sizex, sizey)); //Betölteni a mapot try { device.FileSystem.AddFileArchive("./Content/PK3/" + pak0 + ".edsf"); } catch (Exception ex) { Logger.Log("pak0 fajl betoltese sikertelen vagy nem talalhato, a jatek nem tud betoltodni"); string error = ex.ToString(); Logger.Log(error); Environment.Exit(0); } try { device.FileSystem.AddFileArchive("./Content/PK3/" + pak1 + ".edsf"); } catch (Exception ex) { Logger.Log("pak1 fajl betoltese sikertelen vagy nem talalhato, ignoralva"); string error = ex.ToString(); Logger.Log(error); } try { device.FileSystem.AddFileArchive("./Content/PK3/" + pak2 + ".edsf"); } catch (Exception ex) { Logger.Log("pak2 fajl betoltese sikertelen vagy nem talalhato, ignoralva"); string error = ex.ToString(); Logger.Log(error); } try { q3levelmesh = smgr.GetMesh(mapName + ".bsp"); } catch (Exception ex) { Logger.Log("Palya betoltese sikertelen vagy nem talalhato, a jatek nem tud betoltodni"); string error = ex.ToString(); Logger.Log(error); Environment.Exit(0); } MeshSceneNode q3node = null; q3node = smgr.AddOctreeSceneNode(q3levelmesh.GetMesh(0), null, IDFlag_IsPickable); q3node.Position = new Vector3Df(-1350, -130, -1400); SceneNode node = null; if (mapName == "rpg") { IsRPG = true; } //LightSceneNode light = smgr.AddLightSceneNode(q3node, new Vector3Df(-1319, -118, -1410), new Color(255, 255, 255), 600.0, 10); //Half-Life Headcrab AnimatedMeshSceneNode anode3 = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/headcrab.mdl")); if (IsRPG) { anode3.Position = new Vector3Df(-1212, -180, -1346); Audio.playWave("./Content/Music/rpg.mp3"); } else { anode3.Position = new Vector3Df(-1372.951f, -145.9882f, -1319.71f); } anode3.Rotation = new Vector3Df(0, 0, 0); anode3.AnimationSpeed = 1; Scenes.changeAnimation(anode3, 1, 31); anode3.SetMaterialFlag(MaterialFlag.Lighting, true); anode3.GetMaterial(0).NormalizeNormals = true; anode3.GetMaterial(0).Lighting = false; //Yodan anode2 = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/yodan.mdl")); anode2.Position = new Vector3Df(-1355, -200, -1410); anode2.AnimationSpeed = 15; anode2.SetMaterialFlag(MaterialFlag.Lighting, true); anode2.GetMaterial(0).NormalizeNormals = true; anode2.GetMaterial(0).Lighting = false; anode2.SetTransitionTime(3); Scenes.changeYodanAnimation(anode2, "idle"); //SkyBox SceneNode skybox = smgr.AddSkyBoxSceneNode("./Contents/2D/Skybox/mountains_up.jpg", "./Contents/2D/Skybox/mountains_dn.jpg", "./Contents/2D/Skybox/mountains_lf.jpg", "./Contents/2D/Skybox/mountains_rt.jpg", "./Contents/2D/Skybox/mountains_ft.jpg", "./Contents/2D/Skybox/mountains_bk.jpg"); skybox.Visible = true; //FPS kamera hozzáadása camera = smgr.AddCameraSceneNodeFPS(); camera.Position = new Vector3Df(-1625.723f, -145.9937f, -1532.087f); camera.Target = new Vector3Df(-1491.555f, -1434.106f, -1368.737f); //fegyver AnimatedMesh weaponmesh = smgr.GetMesh("./Content/3D/blades.mdl"); AnimatedMeshSceneNode weapon = smgr.AddAnimatedMeshSceneNode(weaponmesh, camera, 30); weapon.Scale = new Vector3Df(0.5f, 0.5f, 0.5f); weapon.Position = new Vector3Df(0, 0, 15); weapon.Rotation = new Vector3Df(0, -90, 0); Scenes.changeAnimation(weapon, 1, 1); weapon.Visible = true; //fizika TriangleSelector selector; selector = smgr.CreateOctreeTriangleSelector(q3levelmesh.GetMesh(0), q3node, 128); q3node.TriangleSelector = selector; anim = smgr.CreateCollisionResponseAnimator(selector, camera, new Vector3Df(30, 50, 30), new Vector3Df(0, -10, 0), new Vector3Df(0, 30, 0)); //Overlay GUIImage overlay = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/Overlays/vignette.png"), new Vector2Di(0, 0)); overlay.ScaleImage = true; overlay.SetMaxSize(new Dimension2Di(sizex, sizey)); overlay.SetMinSize(new Dimension2Di(sizex, sizey)); selector.Drop(); camera.AddAnimator(anim); anim.Drop(); // fény lightMovementHelperNode = smgr.AddEmptySceneNode(); q3node = smgr.AddSphereSceneNode(2, 6, lightMovementHelperNode, -1, new Vector3Df(15, -10, 15)); q3node.SetMaterialFlag(MaterialFlag.Lighting, false); lightNode = q3node; //A Portré anode = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/portrait.mdl")); anode.Position = new Vector3Df(-1177.601f, -137.975f, -1238.015f); anode.Rotation = new Vector3Df(0,0,0); anode.Scale = new Vector3Df(3); anode.AnimationSpeed = 1500; anode.SetMaterialFlag(MaterialFlag.Lighting, true); anode.GetMaterial(0).NormalizeNormals = true; anode.GetMaterial(0).Lighting = false; AnimatedMeshSceneNode anode4 = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/waiter.mdl")); anode4.Position = new Vector3Df(-1130, -375, -1724); anode4.Rotation = new Vector3Df(0, -90, 0); anode4.Scale = new Vector3Df(2, 2, 2); anode4.SetMaterialFlag(MaterialFlag.Lighting, false); Scenes.changeAnimation(anode4, 0, 1); //Egér elrejtése device.CursorControl.Visible = false; GUIFont font = device.GUIEnvironment.BuiltInFont; SceneCollisionManager collMan = smgr.SceneCollisionManager; TextSceneNode headcrabName = smgr.AddTextSceneNode(font, "Yodan Lebegö Headcrab-je <Level 10>", new Color(255, 255, 0), null, anode3.Position + new Vector3Df(0, 25, 0), 0); TextSceneNode waiterName = smgr.AddTextSceneNode(font, "John <Level 15>", new Color(0, 255, 0), null, anode4.Position + new Vector3Df(0, 125, 0), 0); uint then = device.Timer.Time; float MOVEMENT_SPEED = 100.0f; //Energiagömb /*AnimatedMeshSceneNode anode5 = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/core.mdl")); anode5.Position = new Vector3Df(-1355, 0, -1410); Scenes.changeAnimation(anode5, 0, 90); anode5.Scale = new Vector3Df(2.0f); Line3Df coreray = new Line3Df(-1355, 0, -1410, -1355, -500, -1410); driver.SetMaterial(anode5.GetMaterial(1)); driver.SetTransform(TransformationState.World, Matrix.Identity); driver.Draw3DLine(coreray, new Color(255,0,0));*/ GUIImage bartenderForm = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/bartender.png"), new Vector2Di(10, 10)); bartenderForm.ScaleImage = true; bartenderForm.Visible = false; bartenderForm.SetMinSize(new Dimension2Di(sizex - 10, sizey - 10)); bartenderForm.SetMaxSize(new Dimension2Di(sizex - 10, sizey - 10)); bool BartenderFormIsOpen = false; GUIImage ActionBar = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/Hud/Actionbar.tga"), new Vector2Di(0, 600 - 128)); //330, 110 790, 120 Recti expbarrect = new Recti(); ExperienceBar expbar = new ExperienceBar(gui, expbarrect,0, ActionBar); expbar.SetProgress(0); expbar.SetColors(new Color(255, 255, 0), new Color(255, 255, 255)); expbar.AddBorder(5, new Color(0, 0, 0)); expbar.SetMinSize(new Dimension2Di(128, 64)); expbar.SetMaxSize(new Dimension2Di(128, 64)); //Mi minek a része q3node.AddChild(anode); q3node.AddChild(anode2); q3node.AddChild(anode3); q3node.AddChild(anode4); TextSceneNode yodanName = smgr.AddTextSceneNode(font, "Yodan a Bérgyilkos <Level 90>", new Color(255, 0, 0), null, anode2.Position + new Vector3Df(0, 50, 0), 0); while (device.Run()) { driver.BeginScene(true, true, new Color(135, 206, 235)); smgr.DrawAll(); gui.DrawAll(); string printDate = dateTime.ToShortTimeString(); uint now = device.Timer.Time; float frameDeltaTime = (float)(now - then) / 1000.0f; then = now; Vector3Df nodePosition = camera.Position; if (font != null) { /*font.Draw("Build " + Property.modVersion, 5, 5, new Color(0, 0, 255)); font.Draw("pos= " + camera.Position, 5, 578 - 16, new Color(0, 0, 255)); font.Draw("tar= " + camera.Target, 5, 594 - 16, new Color(0, 0, 255));*/ font.Draw(Player.Experience(), new Vector2Di(505, 582), new Color(0,0,0)); } if (camera.Position.Z >= 10000) { font.Draw("Kiestél a Világból!", new Vector2Di(400, 300), new Color (0, 0, 0)); camera.Position = anode.Position; } if (Quest1Done) { yodanName.SetTextColor(new Color(255, 255, 0)); } if (IsKeyDown(KeyCode.Space)) { nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime; } else if (IsKeyDown(KeyCode.LControl)) { nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime; } if (IsKeyDown(KeyCode.LShift)) { MOVEMENT_SPEED = 200.0f; } else { MOVEMENT_SPEED = 100.0f; } if (IsKeyDown(KeyCode.Esc)) { copyrightScreen.Visible = true; } if (IsKeyDown(KeyCode.KeyM)) { //Yodan.Run(new Vector3Df(-1642, -172, -1421), new Vector3Df(-1053, -167, -1416)); } if (IsKeyDown(KeyCode.KeyB)) { // Yodan.Wave(); Scripting.RunScript(Scripting.LoadScript()); } if (IsKeyDown(KeyCode.KeyV)) { //Yodan.Speak("./Content/Sound/vo/yodan/yo_20ft.mp3"); } else if (IsKeyDown(KeyCode.KeyN)) { //Yodan.Stand(); } else if (IsKeyDown(KeyCode.KeyC)) { //Yodan.WaveAndGreet(); } //Actionbar START //Auto-Attack if (IsKeyDown(KeyCode.Key1)) { if (!AutoAttack) { Delay(100); AutoAttack = true; if (currentWeapon == 1) { Scenes.changeAnimation(weapon, 11 + 24 + 25, 11 + 24 + 25 + 31 + 30); } else if (currentWeapon == 2) { Scenes.changeAnimation(weapon, 91 + 31 + 81 + 31, 91 + 31 + 81 + 31+90); } } else if (AutoAttack) { Delay(100); AutoAttack = false; if (currentWeapon == 1) { Scenes.changeAnimation(weapon, 1, 1); } else if (currentWeapon == 2) { Scenes.changeAnimation(weapon, 1, 90); } } } //Blades if (IsKeyDown(KeyCode.Key2)) { AnimatedMesh bladesmesh = smgr.GetMesh("./Content/3D/blades.mdl"); weapon.Mesh = bladesmesh; weapon.Scale = new Vector3Df(0.5f, 0.5f, 0.5f); weapon.Position = new Vector3Df(0, 0, 15); weapon.Rotation = new Vector3Df(0, -90, 0); Scenes.changeAnimation(weapon, 1, 1); currentWeapon = 1; } //Crossbow if (IsKeyDown(KeyCode.Key3)) { AnimatedMesh crossbowmesh = smgr.GetMesh("./Content/3D/crossbow.mdl"); weapon.Mesh = crossbowmesh; Scenes.changeAnimation(weapon, 1, 90); weapon.Scale = new Vector3Df(3.0f, 3.0f, 3.0f); currentWeapon = 2; } if (IsKeyDown(KeyCode.Key4)) { if (IsEtlapPickedUp) { bartenderForm.Visible = true; BartenderFormIsOpen = true; Audio.playWave("./Content/sound/paper_pickup.mp3"); } } //Actionbar END //elteszi/előveszi a fegyvert if(IsKeyDown(KeyCode.Tab)) { if(weaponHolster) { weapon.Visible = false; Audio.playWave("./Content/sound/weapon.mp3"); weaponHolster = false; } else { weapon.Visible = true; Audio.playWave("./Content/sound/weapon.mp3"); weaponHolster = true; } } if (IsKeyDown(KeyCode.MouseLButton)) { AutoAttack = true; if (currentWeapon == 1) { Scenes.changeAnimation(weapon, 11 + 24 + 25, 11 + 24 + 25 + 31 + 30); } else if (currentWeapon == 2) { Scenes.changeAnimation(weapon, 91 + 31 + 81 + 31, 91 + 31 + 81 + 31 + 90); } } else if (!IsKeyDown(KeyCode.MouseLButton)) { AutoAttack = false; if (currentWeapon == 1) { Scenes.changeAnimation(weapon, 1, 1); } else if (currentWeapon == 2) { Scenes.changeAnimation(weapon, 1, 90); } } if (IsKeyDown(KeyCode.KeyX)) { Texture yodanMissing = driver.GetTexture("./Content/2D/yodanmissing.tga"); Dimension2Di yodanMisSiz = yodanMissing.Size; yodanMisSiz = anode.GetMaterial(0).GetTexture(0).Size; anode.SetMaterialTexture(0, yodanMissing); } if (IsKeyDown(KeyCode.KeyE)) { //Bartender Johh On-Use Vector3Df camtarget = camera.Target; if (!BartenderFormIsOpen) { if (new Vector3Df(727, 221, -986) <= camtarget) { if (new Vector3Df(763, 276, -2329) >= camtarget) { if (camtarget > new Vector3Df(184, -1843, -1255)) { if (camtarget > new Vector3Df(138, -1837, -2318)) { bartenderForm.Visible = true; BartenderFormIsOpen = true; if (!IsEtlapPickedUp) { ActionBar.Image = driver.GetTexture("./Content/2D/Hud/Actionbar_etlap.tga"); Audio.playWave("./Content/sound/vo/waiter_john/teatime.mp3"); } IsEtlapPickedUp = true; Audio.playWave("./Content/sound/paper_pickup.mp3"); } } } } } else if (BartenderFormIsOpen) { bartenderForm.Visible = false; BartenderFormIsOpen = false; Audio.playWave("./Content/sound/paper_pickup.mp3"); } } if (IsKeyDown(KeyCode.KeyK)) { //Yodan.GoGhost(); } if (IsKeyDown(KeyCode.KeyJ)) { //Yodan.GoNormal(); } if (IsKeyDown(KeyCode.KeyL)) { } if (IsKeyDown(KeyCode.F7)) { Delay(500); takeScreenshot(device); } if (IsKeyDown(KeyCode.F9)) { Delay(500); string campos = camera.Position.ToString(); Logger.Log("position:" + campos); string camtar = camera.Target.ToString(); Logger.Log("target: " + camtar); } if (IsKeyDown(KeyCode.LShift)) { if (IsKeyDown(KeyCode.KeyY)) { Environment.Exit(0); } else if (IsKeyDown(KeyCode.KeyN)) { copyrightScreen.Visible = false; } } camera.Position = nodePosition; driver.EndScene(); } device.Drop(); }
static void Main(string[] args) { DriverType driverType; Console.Write("Please select the driver you want for this example:\n" + " (a) OpenGL\n (b) Direct3D 9.0c\n (c) Direct3D 8.1\n" + " (d) Burning's Software Renderer\n (e) Software Renderer\n" + " (f) NullDevice\n (otherKey) exit\n\n"); ConsoleKeyInfo i = Console.ReadKey(); switch (i.Key) { case ConsoleKey.A: driverType = DriverType.OpenGL; break; case ConsoleKey.B: driverType = DriverType.Direct3D9; break; case ConsoleKey.C: driverType = DriverType.Direct3D8; break; case ConsoleKey.D: driverType = DriverType.BurningsVideo; break; case ConsoleKey.E: driverType = DriverType.Software; break; case ConsoleKey.F: driverType = DriverType.Null; break; default: return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh mesh = smgr.GetMesh("20kdm2.bsp"); SceneNode node = null; if (mesh != null) { node = smgr.AddOctreeSceneNode(mesh.GetMesh(0), null, -1, 1024); } if (node != null) { node.Position = new Vector3Df(-1300, -144, -1249); } smgr.AddCameraSceneNodeFPS(); device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(true, true, new Color(200, 200, 200)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Quake 3 Map Example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh q3levelmesh = smgr.GetMesh("20kdm2.bsp"); MeshSceneNode q3node = null; // The Quake mesh is pickable, but doesn't get highlighted. if (q3levelmesh != null) { q3node = smgr.AddOctreeSceneNode(q3levelmesh.GetMesh(0), null, IDFlag_IsPickable); } TriangleSelector selector = null; if (q3node != null) { q3node.Position = new Vector3Df(-1350, -130, -1400); selector = smgr.CreateOctreeTriangleSelector(q3node.Mesh, q3node, 128); q3node.TriangleSelector = selector; // We're not done with this selector yet, so don't drop it. } // Set a jump speed of 3 units per second, which gives a fairly realistic jump // when used with the gravity of (0, -1000, 0) in the collision response animator. CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(null, 100.0f, 0.3f, ID_IsNotPickable, null, true, 3.0f); camera.Position = new Vector3Df(50, 50, -60); camera.Target = new Vector3Df(-70, 30, -60); if (selector != null) { SceneNodeAnimator anim = smgr.CreateCollisionResponseAnimator( selector, camera, new Vector3Df(30, 50, 30), new Vector3Df(0, -1000, 0), new Vector3Df(0, 30, 0)); selector.Drop(); // As soon as we're done with the selector, drop it. camera.AddAnimator(anim); anim.Drop(); // And likewise, drop the animator when we're done referring to it. } // Now I create three animated characters which we can pick, a dynamic light for // lighting them, and a billboard for drawing where we found an intersection. // First, let's get rid of the mouse cursor. We'll use a billboard to show what we're looking at. device.CursorControl.Visible = false; // Add the billboard. BillboardSceneNode bill = smgr.AddBillboardSceneNode(); bill.SetMaterialType(MaterialType.TransparentAddColor); bill.SetMaterialTexture(0, driver.GetTexture("../../media/particle.bmp")); bill.SetMaterialFlag(MaterialFlag.Lighting, false); bill.SetMaterialFlag(MaterialFlag.ZBuffer, false); bill.SetSize(20, 20, 20); bill.ID = ID_IsNotPickable; // This ensures that we don't accidentally ray-pick it AnimatedMeshSceneNode node = null; // Add an MD2 node, which uses vertex-based animation. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/faerie.md2"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Position = new Vector3Df(-90, -15, -140); // Put its feet on the floor. node.Scale = new Vector3Df(1.6f); // Make it appear realistically scaled node.SetMD2Animation(AnimationTypeMD2.Point); node.AnimationSpeed = 20.0f; node.GetMaterial(0).SetTexture(0, driver.GetTexture("../../media/faerie2.bmp")); node.GetMaterial(0).Lighting = true; node.GetMaterial(0).NormalizeNormals = true; // Now create a triangle selector for it. The selector will know that it // is associated with an animated node, and will update itself as necessary. selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // We're done with this selector, so drop it now. // And this B3D file uses skinned skeletal animation. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/ninja.b3d"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Scale = new Vector3Df(10); node.Position = new Vector3Df(-75, -66, -80); node.Rotation = new Vector3Df(0, 90, 0); node.AnimationSpeed = 8.0f; node.GetMaterial(0).NormalizeNormals = true; // Just do the same as we did above. selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // This X files uses skeletal animation, but without skinning. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/dwarf.x"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Position = new Vector3Df(-70, -66, -30); // Put its feet on the floor. node.Rotation = new Vector3Df(0, -90, 0); // And turn it towards the camera. node.AnimationSpeed = 20.0f; selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // And this mdl file uses skinned skeletal animation. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/yodan.mdl"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Position = new Vector3Df(-90, -25, 20); node.Scale = new Vector3Df(0.8f); node.GetMaterial(0).Lighting = true; node.AnimationSpeed = 20.0f; // Just do the same as we did above. selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // Add a light, so that the unselected nodes aren't completely dark. LightSceneNode light = smgr.AddLightSceneNode(null, new Vector3Df(-60, 100, 400), new Colorf(1.0f, 1.0f, 1.0f), 600.0f); light.ID = ID_IsNotPickable; // Make it an invalid target for selection. // Remember which scene node is highlighted SceneNode highlightedSceneNode = null; SceneCollisionManager collMan = smgr.SceneCollisionManager; int lastFPS = -1; // draw the selection triangle only as wireframe Material material = new Material(); material.Lighting = false; material.Wireframe = true; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); smgr.DrawAll(); // Unlight any currently highlighted scene node if (highlightedSceneNode != null) { highlightedSceneNode.SetMaterialFlag(MaterialFlag.Lighting, true); highlightedSceneNode = null; } // All intersections in this example are done with a ray cast out from the camera to // a distance of 1000. You can easily modify this to check (e.g.) a bullet // trajectory or a sword's position, or create a ray from a mouse click position using // collMan.GetRayFromScreenCoordinates() Line3Df ray = new Line3Df(); ray.Start = camera.Position; ray.End = ray.Start + (camera.Target - ray.Start).Normalize() * 1000.0f; // This call is all you need to perform ray/triangle collision on every scene node // that has a triangle selector, including the Quake level mesh. It finds the nearest // collision point/triangle, and returns the scene node containing that point. // Irrlicht provides other types of selection, including ray/triangle selector, // ray/box and ellipse/triangle selector, plus associated helpers. // See the methods of ISceneCollisionManager SceneNode selectedSceneNode = collMan.GetSceneNodeAndCollisionPointFromRay( ray, out Vector3Df intersection, // This will be the position of the collision out Triangle3Df hitTriangle, // This will be the triangle hit in the collision IDFlag_IsPickable); // This ensures that only nodes that we have set up to be pickable are considered // If the ray hit anything, move the billboard to the collision position // and draw the triangle that was hit. if (selectedSceneNode != null) { bill.Position = intersection; // We need to reset the transform before doing our own rendering. driver.SetTransform(TransformationState.World, Matrix.Identity); driver.SetMaterial(material); driver.Draw3DTriangle(hitTriangle, new Color(255, 0, 0)); // We can check the flags for the scene node that was hit to see if it should be // highlighted. The animated nodes can be highlighted, but not the Quake level mesh if ((selectedSceneNode.ID & IDFlag_IsHighlightable) == IDFlag_IsHighlightable) { highlightedSceneNode = selectedSceneNode; // Highlighting in this case means turning lighting OFF for this node, // which means that it will be drawn with full brightness. highlightedSceneNode.SetMaterialFlag(MaterialFlag.Lighting, false); } } // We're all done drawing, so end the scene. driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Collision detection example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh mesh = smgr.GetMesh("20kdm2.bsp"); SceneNode node = null; if (mesh != null) { node = smgr.AddOctreeSceneNode(mesh.GetMesh(0), null, -1, 1024); } if (node != null) { node.Position = new Vector3Df(-1300, -144, -1249); } smgr.AddCameraSceneNodeFPS(); device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(200, 200, 200)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Quake 3 Map Example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
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(); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(ResX, ResY), 32, fullScreen); if (device == null) { return; } device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; // load model AnimatedMesh model = smgr.GetMesh("../../media/sydney.md2"); if (model == null) { return; } AnimatedMeshSceneNode model_node = smgr.AddAnimatedMeshSceneNode(model); // load texture if (model_node != null) { Texture texture = driver.GetTexture("../../media/sydney.bmp"); model_node.SetMaterialTexture(0, texture); model_node.SetMD2Animation(AnimationTypeMD2.Run); model_node.SetMaterialFlag(MaterialFlag.Lighting, false); } // load map device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh map = smgr.GetMesh("20kdm2.bsp"); if (map != null) { SceneNode map_node = smgr.AddOctreeSceneNode(map.GetMesh(0)); map_node.Position = new Vector3Df(-850, -220, -850); } // create 3 fixed and one user-controlled cameras camera[0] = smgr.AddCameraSceneNode(null, new Vector3Df(50, 0, 0), new Vector3Df(0)); // font camera[1] = smgr.AddCameraSceneNode(null, new Vector3Df(0, 50, 0), new Vector3Df(0)); // top camera[2] = smgr.AddCameraSceneNode(null, new Vector3Df(0, 0, 50), new Vector3Df(0)); // left camera[3] = smgr.AddCameraSceneNodeFPS(); // user-controlled camera[3].Position = new Vector3Df(-50, 0, -50); device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { // set the viewpoint to the whole screen and begin scene driver.ViewPort = new Recti(0, 0, ResX, ResY); driver.BeginScene(true, true, new Color(100, 100, 100)); if (splitScreen) { smgr.ActiveCamera = camera[0]; driver.ViewPort = new Recti(0, 0, ResX / 2, ResY / 2); // top left smgr.DrawAll(); smgr.ActiveCamera = camera[1]; driver.ViewPort = new Recti(ResX / 2, 0, ResX, ResY / 2); // top right smgr.DrawAll(); smgr.ActiveCamera = camera[2]; driver.ViewPort = new Recti(0, ResY / 2, ResX / 2, ResY); // bottom left smgr.DrawAll(); driver.ViewPort = new Recti(ResX / 2, ResY / 2, ResX, ResY); // bottom right } smgr.ActiveCamera = camera[3]; smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Split Screen example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } device.Drop(); }
static void Main() { // setup Irrlicht device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 768), 32, false, true); if (device == null) { return; } device.SetWindowCaption("Stencil Shadows - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIFont statsFont = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); cameraNode = scene.AddCameraSceneNodeFPS(); cameraNode.FarValue = 20000; device.CursorControl.Visible = false; // setup shadows shadows = new Shadows(new Color(0xa0000000), 4000); // load quake level device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); Mesh m = scene.GetMesh("20kdm2.bsp").GetMesh(0); MeshSceneNode n = scene.AddOctreeSceneNode(m, null, -1, 1024); n.Position = new Vector3Df(-1300, -144, -1249); quakeLevelNode = n; // add faerie faerieNode = scene.AddAnimatedMeshSceneNode( scene.GetMesh("../../media/faerie.md2"), null, -1, new Vector3Df(100, -40, 80), new Vector3Df(0, 30, 0), new Vector3Df(1.6f)); faerieNode.SetMD2Animation(AnimationTypeMD2.Wave); faerieNode.AnimationSpeed = 20; faerieNode.GetMaterial(0).SetTexture(0, driver.GetTexture("../../media/faerie2.bmp")); faerieNode.GetMaterial(0).Lighting = false; faerieNode.GetMaterial(0).NormalizeNormals = true; shadows.AddObject(faerieNode); // add light lightMovementHelperNode = scene.AddEmptySceneNode(); n = scene.AddSphereSceneNode(2, 6, lightMovementHelperNode, -1, new Vector3Df(15, -10, 15)); n.SetMaterialFlag(MaterialFlag.Lighting, false); lightNode = n; shadows.AddLight(lightNode); // add flashlight m = scene.GetMesh("../../media/flashlight.obj"); n = scene.AddMeshSceneNode(m, lightNode, -1, new Vector3Df(0), new Vector3Df(0), new Vector3Df(5)); n.SetMaterialFlag(MaterialFlag.Lighting, false); flashlightNode = n; flashlightNode.Visible = false; // render uint shdFrameTime = 0; uint shdFrames = 0; uint shdFps = 0; while (device.Run()) { if (useShadowsRebuilding && shadows.BuildShadowVolume()) { shdFrames++; } uint t = device.Timer.Time; if (t - shdFrameTime > 1000) { shdFrameTime = t; shdFps = shdFrames; shdFrames = 0; } if (useLightBinding) { lightMovementHelperNode.Position = cameraNode.AbsolutePosition.GetInterpolated(lightMovementHelperNode.Position, 0.1); lightMovementHelperNode.Rotation = cameraNode.AbsoluteTransformation.Rotation; } driver.BeginScene(ClearBufferFlag.All, new Color(0xff112244)); scene.DrawAll(); if (useShadowsRendering) { shadows.DrawShadowVolume(driver); } // display stats driver.Draw2DRectangle(new Recti(10, 10, 150, 220), new Color(0x7f000000)); Vector2Di v = new Vector2Di(20, 20); statsFont.Draw("Rendering", v, Color.SolidYellow); v.Y += 16; statsFont.Draw(driver.FPS + " fps", v, Color.SolidWhite); v.Y += 16; statsFont.Draw("[S]hadows " + (useShadowsRendering ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 16; statsFont.Draw("[L]ight binding " + (useLightBinding ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 16; statsFont.Draw("[F]lashlight " + (useFlashlight ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 32; statsFont.Draw("Shadows", v, Color.SolidYellow); v.Y += 16; statsFont.Draw(shdFps + " fps", v, Color.SolidWhite); v.Y += 16; statsFont.Draw(shadows.VerticesBuilt + " vertices", v, Color.SolidWhite); v.Y += 16; statsFont.Draw("[R]ebuilding " + (useShadowsRebuilding ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 16; statsFont.Draw("[Q]uake level " + (useShadowsQuakeLevel ? "ON" : "OFF"), v, Color.SolidGreen); driver.EndScene(); } shadows.Drop(); device.Drop(); }