static void Main(string[] args) { IrrlichtDevice device = IrrlichtDevice.CreateDevice( DriverType.OpenGL, new Dimension2Di(640, 480), 16, false, false, false); device.SetWindowCaption("testing irrlicht engine lol"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; gui.AddStaticText("Hello World! This is the Irrlicht Software renderer!", new Recti(10, 10, 260, 22), true); smgr.AddCameraSceneNode(null, new Vector3Df(0, 30, -40), new Vector3Df(0, 5, 0)); while (device.Run()) { driver.BeginScene(ClearBufferFlag.All, new Color(100, 101, 140)); smgr.DrawAll(); gui.DrawAll(); driver.EndScene(); } device.Drop(); }
/// <summary> /// Irrlicht Instance. A handle to the Irrlicht device. /// </summary> //public IrrlichtDevice Device; //public VideoDriver Driver; //public SceneManager SceneManager; //public GUIEnvironment GuiEnvironment; //public IdealistUserControl ViewerControl; public RaegastRenderer(RadegastViewer viewer, IrrlichtDevice device) : base(viewer) { // ViewerControl = viewer.ViewerControl; m_viewer = viewer; Device = device; }
static void Main() { device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1280, 768)); // minimum: 1024 (which is 16x64) x 768 (which is 16x48) if (device == null) { return; } device.SetWindowCaption("Pathfinding - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); Color fontNormalColor = Color.SolidWhite; Color fontActionColor = Color.SolidYellow; Texture pathfindingTexture = driver.GetTexture("../../media/pathfinding.png"); int cellSize = pathfindingTexture.Size.Height; pathfinding = new Pathfinding(64, 48, cellSize, 0, 0); pathfinding.SetCell(4, 4, Pathfinding.CellType.Start); pathfinding.SetCell(pathfinding.Width - 5, pathfinding.Height - 5, Pathfinding.CellType.Finish); while (device.Run()) { driver.BeginScene(ClearBufferFlag.Color); pathfinding.FindPath(); pathfinding.Draw(driver, pathfindingTexture); // draw info panel Vector2Di v = new Vector2Di(pathfinding.Width * pathfinding.CellSize + 20, 20); font.Draw("FPS: " + driver.FPS, v, fontNormalColor); v.Y += 32; font.Draw("Map size: " + pathfinding.Width + " x " + pathfinding.Height, v, fontNormalColor); v.Y += 16; font.Draw("Shortest path: " + (pathfinding.PathLength == -1 ? "N/A" : pathfinding.PathLength.ToString()), v, fontNormalColor); v.Y += 16; font.Draw("Calculation time: " + pathfinding.PathCalcTimeMs + " ms", v, fontNormalColor); v.Y += 32; font.Draw(workMode ? "[LMB] Set cell impassable" : "[LMB] Set Start cell", v, fontActionColor); v.Y += 16; font.Draw(workMode ? "[RMB] Set cell passable" : "[RMB] Set Finish cell", v, fontActionColor); v.Y += 16; font.Draw("[Space] Change mode", v, fontActionColor); v.Y += 32; font.Draw("[F1] Clean up the map", v, fontActionColor); v.Y += 16; font.Draw("[F2] Add random blocks", v, fontActionColor); driver.EndScene(); } device.Drop(); }
private static Texture getDesktopTexture(IrrlichtDevice device) { int screenX = 0; int screenY = 0; int screenWidth = device.VideoDriver.ScreenSize.Width; int screenHeight = device.VideoDriver.ScreenSize.Height; Point p = new Point(); GetCursorPos(ref p); screenX = p.X - screenWidth / 2; screenY = p.Y - screenHeight / 2; // validate grabbing rect (note: works fine without validation too) {{ if (screenX < 0) screenX = 0; if (screenX + screenWidth > SystemInformation.VirtualScreen.Width) screenX = SystemInformation.VirtualScreen.Width - screenWidth; if (screenY < 0) screenY = 0; if (screenY + screenHeight > SystemInformation.VirtualScreen.Height) screenY = SystemInformation.VirtualScreen.Height - screenHeight; // }} Bitmap b = new Bitmap( screenWidth, screenHeight, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(b); g.CopyFromScreen( screenX, screenY, 0, 0, new Size(screenWidth, screenHeight), CopyPixelOperation.SourceCopy); MemoryStream s = new MemoryStream(); b.Save(s, ImageFormat.Bmp); byte[] c = s.ToArray(); s.Close(); LogLevel o = device.Logger.LogLevel; device.Logger.LogLevel = LogLevel.Error; // we hide all those "Loaded texture" messages in console {{ ReadFile f = device.FileSystem.CreateMemoryReadFile("screenTexture", c); Texture t = device.VideoDriver.GetTexture(f); f.Drop(); device.Logger.LogLevel = o; // }} return t; }
public FractalGenerator(IrrlichtDevice device) { this.device = device; driver = device.VideoDriver; screen = driver.ViewPort; regenerateTiles(); }
public FractalGenerator(IrrlichtDevice device) { this.device = device; driver = device.VideoDriver; screen = driver.ViewPort; regenerateTiles(); }
public Application(IrrlichtDevice dev) { device = dev; device.OnEvent += new IrrlichtDevice.EventHandler(OnEvent); initScene(); initGUI(128); createTexture(128); }
public Application(IrrlichtDevice dev) { device = dev; device.OnEvent += new IrrlichtDevice.EventHandler(OnEvent); initScene(); initGUI(128); createTexture(128); }
static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1280, 768)); if (device == null) return; device.SetWindowCaption("Pathfinding - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); Color fontNormalColor = Color.OpaqueWhite; Color fontActionColor = Color.OpaqueYellow; Texture pathfindingTexture = driver.GetTexture("../../media/pathfinding.png"); int cellSize = pathfindingTexture.Size.Height; pathfinding = new Pathfinding(64, 48, cellSize, 0, 0); pathfinding.SetCell(4, 4, Pathfinding.CellType.Start); pathfinding.SetCell(pathfinding.Width - 5, pathfinding.Height - 5, Pathfinding.CellType.Finish); while (device.Run()) { driver.BeginScene(true, false); pathfinding.FindPath(); pathfinding.Draw(driver, pathfindingTexture); // draw info panel Vector2Di v = new Vector2Di(pathfinding.Width * pathfinding.CellSize + 20, 20); font.Draw("FPS: " + driver.FPS, v, fontNormalColor); v.Y += 32; font.Draw("Map size: " + pathfinding.Width + " x " + pathfinding.Height, v, fontNormalColor); v.Y += 16; font.Draw("Shortest path: " + (pathfinding.PathLength == -1 ? "N/A" : pathfinding.PathLength.ToString()), v, fontNormalColor); v.Y += 16; font.Draw("Calculation time: " + pathfinding.PathCalcTimeMs + " ms", v, fontNormalColor); v.Y += 32; font.Draw(workMode ? "[LMB] Set cell impassable" : "[LMB] Set Start cell", v, fontActionColor); v.Y += 16; font.Draw(workMode ? "[RMB] Set cell passable" : "[RMB] Set Finish cell", v, fontActionColor); v.Y += 16; font.Draw("[Space] Change mode", v, fontActionColor); v.Y += 32; font.Draw("[F1] Clean up the map", v, fontActionColor); v.Y += 16; font.Draw("[F2] Add random blocks", v, fontActionColor); driver.EndScene(); } device.Drop(); }
public AbstractTrace(IrrlichtDevice device) { this.device = device; device.Grab(); cubeMaterial.Type = MaterialType.TransparentVertexAlpha; cubeMaterial.Lighting = false; for (int i = 0; i < layers.Length; i++) layers[i] = new GridLayer(); }
public Game(IrrlichtDevice device) { m_device = device; m_root = m_device.SceneManager.AddEmptySceneNode(); loadCellMesh(); loadFlagMesh(); loadBombMesh(); NewGame(10, 10); }
public Game(IrrlichtDevice device) { m_device = device; m_root = m_device.SceneManager.AddEmptySceneNode(); loadCellMesh(); loadFlagMesh(); loadBombMesh(); NewGame(10, 10); }
static void Main() { IrrlichtDevice device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(800, 600)); device.SetWindowCaption("RGB swirl example - Irrlicht Lime"); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; var camera = scene.AddCameraSceneNode(null, new Vector3Df(0, 0, -15), new Vector3Df()); camera.ViewMatrixAffector = camera.ProjectionMatrix.GetInverse(); var lightRed = scene.AddLightSceneNode(null, new Vector3Df(0, 40, 0)); lightRed.LightData.DiffuseColor = new Colorf(1, 0, 0); var a = scene.CreateFlyCircleAnimator(new Vector3Df(), 40, 0.0003f, new Vector3Df(0, 0, 1), 0.000f); lightRed.AddAnimator(a); a.Drop(); var lightGreen = scene.AddLightSceneNode(null, new Vector3Df(-30, -20, 0)); lightGreen.LightData.DiffuseColor = new Colorf(0, 1, 0); a = scene.CreateFlyCircleAnimator(new Vector3Df(), 40, 0.0003f, new Vector3Df(0, 0, 1), 0.333f); lightGreen.AddAnimator(a); a.Drop(); var lightBlue = scene.AddLightSceneNode(null, new Vector3Df(30, -20, 0)); lightBlue.LightData.DiffuseColor = new Colorf(0, 0, 1); a = scene.CreateFlyCircleAnimator(new Vector3Df(), 40, 0.0003f, new Vector3Df(0, 0, 1), 0.667f); lightBlue.AddAnimator(a); a.Drop(); var node = scene.AddSphereSceneNode(5.5f, 255); node.SetMaterialFlag(MaterialFlag.BackFaceCulling, false); node.SetMaterialFlag(MaterialFlag.PointCloud, true); node.GetMaterial(0).Thickness = 4; while (device.Run()) { node.Rotation = new Vector3Df(device.Timer.Time / 1, device.Timer.Time / 2, device.Timer.Time / 3); driver.BeginScene(ClearBufferFlag.Depth); scene.DrawAll(); driver.EndScene(); } device.Drop(); }
static void Main() { DriverSettingsForm driverSettings = new DriverSettingsForm( "Texture paint example", "This example shows how to use TexturePainter and render-to-texture (RTT) technique.\n\n" + "Use mouse to draw on the 2D image (texture) and see changes on the mesh and on RTT target."); if (!driverSettings.ShowDialog()) { return; } device = IrrlichtDevice.CreateDevice( driverSettings.DriverType, driverSettings.VideoMode.Resolution, driverSettings.VideoMode.Depth, driverSettings.Fullscreen); if (device == null) { Console.WriteLine("\nDevice creation failed!\n<Press any key to exit>"); Console.ReadKey(); return; } device.VideoDriver.SetTextureCreationFlag(TextureCreationFlag.AllowMemoryCopy, true); //workaround: bug in irrlicht Application app = new Application(device); int lastFPS = -1; while (device.Run()) { device.VideoDriver.BeginScene(); app.Render(); device.VideoDriver.EndScene(); int fps = device.VideoDriver.FPS; if (fps != lastFPS) { device.SetWindowCaption(string.Format( "Texture painting example - Irrlicht Lime [{0}] {1} fps", device.VideoDriver.Name, fps)); lastFPS = fps; } } device.Drop(); }
public MyEventReceiver(IrrlichtDevice device, SceneNode terrain, SceneNode skybox, SceneNode skydome) { this.terrain = terrain; this.skybox = skybox; this.skydome = skydome; showBox = true; showDebug = false; skybox.Visible = true; skydome.Visible = false; device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); }
public AbstractTrace(IrrlichtDevice device) { this.device = device; device.Grab(); cubeMaterial.Type = MaterialType.TransparentVertexAlpha; cubeMaterial.Lighting = false; for (int i = 0; i < layers.Length; i++) { layers[i] = new GridLayer(); } }
static void Main() { device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1280, 720)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; device.SetWindowCaption("Abstract Trace - Irrlicht Engine"); device.OnEvent += Device_OnEvent; GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); Color textColor = Color.SolidWhite; CameraSceneNode camera = scene.AddCameraSceneNode(); camera.FarValue = 20000; SceneNodeAnimator a = scene.CreateFlyCircleAnimator(new Vector3Df(), (AbstractTrace.CubeSize * AbstractTrace.GridDim) / 1.25f, 0.000025f, new Vector3Df(0.1f, 1, 0)); camera.AddAnimator(a); a.Drop(); trace = new AbstractTrace(device); trace.Init(); while (device.Run()) { driver.BeginScene(); scene.DrawAll(); if (!isPaused) { trace.Step(); } trace.Draw(drawGenerator); font.Draw("[G]enerator: " + (drawGenerator ? "ON" : "OFF"), new Vector2Di(20, 20), textColor); font.Draw("[P]ause: " + (isPaused ? "ON" : "OFF"), new Vector2Di(20, 35), textColor); font.Draw("Cubes: " + trace.GetTotalCubeCount(), new Vector2Di(20, 50), textColor); font.Draw("FPS: " + driver.FPS, new Vector2Di(20, 65), textColor); driver.EndScene(); } trace.Drop(); device.Drop(); }
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(); }
static void Main(string[] args) { int N = AskUserForN(); bool B = AskUserForB(); DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(800, 600)); if (device == null) { return; } device.CursorControl.Visible = false; CameraSceneNode camera = device.SceneManager.AddCameraSceneNodeFPS(); camera.FarValue = 20000; camera.Position = new Vector3Df(-200); camera.Target = new Vector3Df(0); MeshBuffersBatch batch = new MeshBuffersBatch(device, N, B); while (device.Run()) { device.VideoDriver.BeginScene(); device.SceneManager.DrawAll(); batch.Draw(); device.VideoDriver.EndScene(); device.SetWindowCaption( "Fast static rendering - Irrlicht Lime - " + device.VideoDriver.Name + " | " + device.VideoDriver.FPS + " fps | " + N * N * N + " cubes | " + device.VideoDriver.PrimitiveCountDrawn + " primitives | " + MemUsageText + " of physical memory used"); } batch.Drop(); device.Drop(); }
static void Main() { IrrlichtDevice device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(512, 512)); device.SetWindowCaption("Screenshot to texture - Irrlicht Lime"); // set up very simple scene {{ CameraSceneNode cam = device.SceneManager.AddCameraSceneNode(); cam.Target = new Vector3Df(0); SceneNodeAnimator anim = device.SceneManager.CreateFlyCircleAnimator(new Vector3Df(0, 16, 0), 30, 0.0004f); cam.AddAnimator(anim); anim.Drop(); SceneNode cube = device.SceneManager.AddCubeSceneNode(20); cube.SetMaterialFlag(MaterialFlag.Lighting, false); // }} while (device.Run()) { cube.SetMaterialTexture(0, null); device.VideoDriver.RemoveAllTextures(); Texture t = getDesktopTexture(device); cube.SetMaterialTexture(0, t); device.VideoDriver.BeginScene(ClearBufferFlag.Depth); device.VideoDriver.Draw2DImage(t, device.VideoDriver.ViewPort, new Recti(new Vector2Di(0), t.Size)); device.VideoDriver.Draw2DRectangle(device.VideoDriver.ViewPort, new IrrlichtLime.Video.Color(0, 0, 0, 160)); device.SceneManager.DrawAll(); device.GUIEnvironment.BuiltInFont.Draw( device.Timer.ToString() + "\nMemory: " + (System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / (1 << 20)).ToString() + " Mb" + "\nFPS: " + device.VideoDriver.FPS.ToString(), new Vector2Di(16), new IrrlichtLime.Video.Color(255, 255, 255)); device.VideoDriver.EndScene(); } device.Drop(); }
public SphereCamera(IrrlichtDevice device, Vector3Df target, double minRadius, double maxRadius, double initRadius, double initInclination, double initAzimuth) { this.target = target; this.camera = device.SceneManager.AddCameraSceneNode(); this.minRadius = minRadius; this.maxRadius = maxRadius; this.radius = initRadius; this.inclination = initInclination; this.azimuth = initAzimuth; setupCameraProperties(); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) return; device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) return; device.SetWindowCaption("Irrlicht Engine - User Interface Demo"); device.SetWindowResizable(true); VideoDriver driver = device.VideoDriver; GUIEnvironment env = device.GUIEnvironment; GUISkin skin = env.Skin; GUIFont font = env.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) skin.SetFont(font); skin.SetFont(env.BuiltInFont, GUIDefaultFont.Tooltip); env.AddButton(new Recti(10, 240, 110, 240 + 32), null, GUI_ID_ButtonQuit, "Quit", "Exits Program"); env.AddButton(new Recti(10, 280, 110, 280 + 32), null, GUI_ID_ButtonWindowNew, "New Window", "Launches a new Window"); env.AddButton(new Recti(10, 320, 110, 320 + 32), null, GUI_ID_ButtonFileOpen, "File Open", "Opens a file"); env.AddStaticText("Transparent Control:", new Recti(150, 20, 350, 40), true); GUIScrollBar scrollbar = env.AddScrollBar(true, new Recti(150, 45, 350, 60), null, GUI_ID_ScrollbarTransparency); scrollbar.MaxValue = 255; scrollbar.Position = (int)env.Skin.GetColor(GUIDefaultColor.WindowBackground).Alpha; GUIStaticText trq = env.AddStaticText("Logging ListBox:", new Recti(50,110,250,130), true); listbox = env.AddListBox(new Recti(50, 140, 250, 210)); env.AddEditBox("Editable Text", new Recti(350, 80, 550, 100)); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10, 10)); while (device.Run()) if (device.WindowActive) { driver.BeginScene(true, true, new Color(200, 200, 200)); env.DrawAll(); driver.EndScene(); } device.Drop(); }
static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 600)); device.SetWindowCaption("LightningShots - Irrlicht Engine"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh mesh = smgr.GetMesh("20kdm2.bsp"); MeshSceneNode node = smgr.AddMeshSceneNode(mesh.GetMesh(0)); node.Position = new Vector3Df(-1300, -144, -1249); node.SetMaterialType(MaterialType.LightMapLightingM4); node.SetMaterialFlag(MaterialFlag.Lighting, true); node.TriangleSelector = smgr.CreateTriangleSelector(node.Mesh, node); node.TriangleSelector.Drop(); smgr.AmbientLight = new Colorf(0.15f, 0.14f, 0.13f); CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(); lightningShot = new LightningShot(smgr, node.TriangleSelector); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.CursorControl.Visible = false; while (device.Run()) { driver.BeginScene(true, true, new Color(100, 80, 75)); smgr.DrawAll(); lightningShot.Draw(device.Timer.Time); GUIFont f = device.GUIEnvironment.BuiltInFont; f.Draw("Use [LMB] to shoot", 10, 10, Color.OpaqueYellow); f.Draw("Total lightnings: " + lightningShot.TotalLightnings, 10, 20, Color.OpaqueWhite); f.Draw("Total shots: " + lightningShot.TotalShots, 10, 30, Color.OpaqueWhite); f.Draw(driver.FPS + " fps", 10, 40, Color.OpaqueWhite); driver.EndScene(); } lightningShot.Drop(); device.Drop(); }
static void Main(string[] args) { 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.OpaqueYellow); font.Draw("Press [RMB] on Earth to place new path point", 10, 20, Color.OpaqueYellow); font.Draw("Press [R] to reload path data from file", 10, 30, Color.OpaqueYellow); font.Draw("Press [C] to clean up", 10, 40, Color.OpaqueYellow); font.Draw(driver.FPS.ToString() + " fps", 10, driver.ScreenSize.Height - 40, Color.OpaqueYellow); font.Draw(path.PointCount.ToString() + " point(s)", 10, driver.ScreenSize.Height - 30, Color.OpaqueYellow); font.Draw(camera.ToString(), 10, driver.ScreenSize.Height - 20, Color.OpaqueYellow); driver.EndScene(); } path.Drop(); device.Drop(); }
static public LODItem Create(IrrlichtDevice device, List <Mesh> meshLODs, Matrix transformation, Vector3Df rotationVector) { LODItem n = new LODItem(); n.device = device; n.meshLODs = meshLODs; n.transformation = transformation; n.rotationVector = rotationVector; n.currentLOD = meshLODs.Count - 1; // we cache some really frequently accessed values (which will never get changed anyway) n.driver = device.VideoDriver; n.screenSize = device.VideoDriver.ScreenSize; return(n); }
public SphereCamera(IrrlichtDevice device, Vector3Df target, double minRadius, double maxRadius, double initRadius, double initInclination, double initAzimuth) { this.device = device; this.target = target; this.camera = device.SceneManager.AddCameraSceneNode(); this.minRadius = minRadius; this.maxRadius = maxRadius; this.radius = initRadius; this.inclination = initInclination; this.azimuth = initAzimuth; setupCameraProperties(); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); }
static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 600)); device.SetWindowCaption("LightningShots - Irrlicht Engine"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh mesh = smgr.GetMesh("20kdm2.bsp"); MeshSceneNode node = smgr.AddMeshSceneNode(mesh.GetMesh(0)); node.Position = new Vector3Df(-1300, -144, -1249); node.SetMaterialType(MaterialType.LightMapLightingM4); node.SetMaterialFlag(MaterialFlag.Lighting, true); node.TriangleSelector = smgr.CreateTriangleSelector(node.Mesh, node); node.TriangleSelector.Drop(); smgr.AmbientLight = new Colorf(0.15f, 0.14f, 0.13f); CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(); lightningShot = new LightningShot(smgr, node.TriangleSelector); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.CursorControl.Visible = false; while (device.Run()) { driver.BeginScene(true, true, new Color(100, 80, 75)); smgr.DrawAll(); lightningShot.Draw(device.Timer.Time); GUIFont f = device.GUIEnvironment.BuiltInFont; f.Draw("Use [LMB] to shoot", 10, 10, Color.OpaqueYellow); f.Draw("Total lightnings: " + lightningShot.TotalLightnings, 10, 20, Color.OpaqueWhite); f.Draw("Total shots: " + lightningShot.TotalShots, 10, 30, Color.OpaqueWhite); f.Draw(driver.FPS + " fps", 10, 40, Color.OpaqueWhite); driver.EndScene(); } lightningShot.Drop(); device.Drop(); }
public MyEventReceiver(IrrlichtDevice device, SceneNode room, SceneNode earth) { device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); // store pointer to room so we can change its drawing mode this.driver = device.VideoDriver; this.room = room; this.earth = earth; GUIEnvironment env = device.GUIEnvironment; // set a nicer font GUIFont font = env.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) { env.Skin.SetFont(font); } // add window and listbox GUIWindow window = env.AddWindow(new Recti(460, 375, 630, 470), false, "Use 'E' + 'R' to change"); this.listBox = env.AddListBox(new Recti(2, 22, 165, 88), window); this.listBox.AddItem("Diffuse"); this.listBox.AddItem("Bump mapping"); this.listBox.AddItem("Parallax mapping"); this.listBox.SelectedIndex = 1; // create problem text this.problemText = env.AddStaticText( "Your hardware or this renderer is not able to use the needed shaders for this material. Using fall back materials.", new Recti(150, 20, 470, 80)); this.problemText.OverrideColor = new Color(255, 255, 255, 100); // set start material (prefer parallax mapping if available) MaterialRenderer renderer = this.driver.GetMaterialRenderer(MaterialType.ParallaxMapSolid); if (renderer != null && renderer.Capability == 0) { this.listBox.SelectedIndex = 2; } // set the material which is selected in the listbox setMaterial(); }
/// <summary> /// Sets up the device to run in a <see cref="Control"/> with the specified <see cref="Irrlicht.Video.DriverType"/>. /// </summary> /// <param name="c">Winforms <see cref="Control"/> that Irrlicht is to render in.</param> /// <param name="driver"><see cref="Irrlicht.Video.DriverType"/> to use when setting up the IrrlichtDevice.</param> /// <returns>True if the setup went well, False otherwise.</returns> private bool SetDevice(Control c, video.DriverType driverType) { if (quitting) { return(false); } if (device != null) { device.CloseDevice(); } CreatePanel(); device = new IrrlichtDevice(driverType, new core.Dimension2D(c.ClientRectangle.Width, c.ClientRectangle.Height), 32, false, false, false, true, c.Handle); if (device == null) { return(false); } device.ResizeAble = true; gui.IGUIEnvironment env = device.GUIEnvironment; video.IVideoDriver driver = device.VideoDriver; scene.ISceneManager smgr = device.SceneManager; driver.SetTextureCreationFlag(video.TextureCreationFlag.ALWAYS_32_BIT, true); // This sets the gui font from a bmp file. gui.IGUISkin skin = env.Skin; gui.IGUIFont font = env.GetFont(path + "fonthaettenschweiler.bmp"); if (font != null) { skin.Font = font; } // This is loaded with the default values for the native engine. smgr.AddCameraSceneNodeMaya(null, -1500, 500, 1500, -1); irrLogo = driver.GetTexture(path + "irrlichtlogoaligned.jpg"); caption = captBase + " (using " + driver.Name + " driver)"; this.Text = caption; return(true); }
static void Main(string[] args) { IrrlichtDevice device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(640, 480), 16, false); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; smgr.AddCameraSceneNode(null, new Vector3Df(0, -40, 0), new Vector3Df(0)); CSampleSceneNode myNode = new CSampleSceneNode(smgr.RootNode, smgr, 667); SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0.8f, 0, 0.8f)); if (anim != null) { myNode.AddAnimator(anim); anim.Drop(); anim = null; } myNode.Drop(); myNode = null; int frames = 0; while (device.Run()) { driver.BeginScene(true, true, new Color(100, 100, 100)); smgr.DrawAll(); driver.EndScene(); if (++frames == 100) { device.SetWindowCaption(String.Format( "Custom Scene Node - Irrlicht Engine [{0}] fps: {1}", driver.Name, driver.FPS)); frames = 0; } } device.Drop(); }
static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1280, 720)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; CameraSceneNode camera = scene.AddCameraSceneNode(); camera.FarValue = 20000; SceneNodeAnimator a = scene.CreateFlyCircleAnimator(new Vector3Df(), (AbstractTrace.CubeSize * AbstractTrace.GridDim) / 1.25f, 0.000025f, new Vector3Df(0.1f, 1, 0)); camera.AddAnimator(a); a.Drop(); trace = new AbstractTrace(device); trace.Init(); int lastFps = -1; while (device.Run()) { driver.BeginScene(); scene.DrawAll(); trace.Step(); trace.Draw(); driver.EndScene(); int fps = driver.FPS; if (fps != lastFps) { device.SetWindowCaption("Abstract Trace - Irrlicht Engine [" + fps + " fps; " + trace.GetTotalCubeCount() + " cubes]"); lastFps = fps; } } trace.Drop(); device.Drop(); }
void runIrrlichtInWindowsFormTest() { // testing irrlicht running embedded in a windows form System.Windows.Forms.Form f = new System.Windows.Forms.Form(); f.Text = "Irrlicht running embedded in Windows.Form"; device = new IrrlichtDevice(SelectedDriverType, new Dimension2D(800, 600), 16, false, false, false, true, f.Handle); f.Show(); // set up a simple scene ICameraSceneNode cam = device.SceneManager.AddCameraSceneNode(null, new Vector3D(), new Vector3D(), -1); ISceneNodeAnimator anim = device.SceneManager.CreateFlyCircleAnimator( new Vector3D(0, 10, 0), 30.0f, 0.003f); cam.AddAnimator(anim); ISceneNode cube = device.SceneManager.AddCubeSceneNode(25, null, -1, new Vector3D()); cube.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/rockwall.bmp")); cube.SetMaterialFlag(Irrlicht.Video.MaterialFlag.LIGHTING, false); // draw everything device.Run(); // fix for a temporary bug where quit messages are not be removed in the queue while (device.Run() && f.Visible) { if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(255, 0, 0, 50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } } }
public FNGame() { var param = new IrrlichtCreationParameters() { AntiAliasing = 8, DeviceType = DeviceType.Best, DriverType = DriverType.OpenGL, VSync = true, WindowSize = new Dimension2Di(1200, 700) }; device = IrrlichtDevice.CreateDevice(param); device.OnEvent += device_OnEvent; Driver = device.VideoDriver; Scene = device.SceneManager; Gui = device.GUIEnvironment; }
public bool ShowDialog() { device = IrrlichtDevice.CreateDevice(DriverType.BurningsVideo, new Dimension2Di(320, 320)); device.FileSystem.AddFileArchive("../../media/"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.SetWindowCaption(windowCaption); initGUI(); while (device.Run()) { device.VideoDriver.BeginScene(ClearBufferFlag.All, new Color(40, 180, 80)); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } device.Drop(); return(run); }
public bool InitDevices(Control target_window) { _target_window = target_window; Dimension2D dim = new Dimension2D(target_window.Size.Width, target_window.Size.Height); _device = new IrrlichtDevice(DriverType.OpenGL, dim, 32, false, false, false, false, target_window.Handle); _device.Resizeable = true; //_device.OnEvent += new OnEventDelegate(_device_OnEvent); _scene = _device.SceneManager; _driver = _device.VideoDriver; return(true); }
/// <summary> /// Initiates Irrlicht and prepares the scene for rendering /// </summary> /// <param name="renderTo">Control will display the model</param> public MD2Viewer(Control renderTo) { renderingTo = renderTo; Dimension2Di displayDimensions = new Dimension2Di(renderTo.ClientSize.Width, renderTo.ClientSize.Height); IrrlichtCreationParameters creationParams = new IrrlichtCreationParameters(); creationParams.BitsPerPixel = 16; creationParams.DoubleBuffer = false; creationParams.DriverType = DriverType.Software; creationParams.WindowSize = new Dimension2Di(renderingTo.Width, renderingTo.Height); creationParams.WindowID = renderingTo.Handle; creationParams.Fullscreen = false; irrlichtDevice = IrrlichtDevice.CreateDevice(creationParams); ClearScene(); backgroundColour = new Color(150, 150, 150, 0); }
static void Main(string[] args) { IrrlichtDevice device = IrrlichtDevice.CreateDevice( DriverType.Software, new Dimension2Di(640, 480), 16, false, false, false); device.SetWindowCaption("Hello World! - Irrlicht Engine Demo"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; gui.AddStaticText("Hello World! This is the Irrlicht Software renderer!", new Recti(10, 10, 260, 22), true); // AnimatedMesh mesh = smgr.GetMesh("../../media/sydney.md2"); // AnimatedMeshSceneNode node = smgr.AddAnimatedMeshSceneNode(mesh); // // if (node != null) // { // node.SetMaterialFlag(MaterialFlag.Lighting, false); // node.SetMD2Animation(AnimationTypeMD2.Stand); // node.SetMaterialTexture(0, driver.GetTexture("../../media/sydney.bmp")); // } smgr.AddCameraSceneNode(null, new Vector3Df(0, 30, -40), new Vector3Df(0, 5, 0)); while (device.Run()) { driver.BeginScene(true, true, new Color(100, 101, 140)); smgr.DrawAll(); gui.DrawAll(); driver.EndScene(); } device.Drop(); }
private static void Main() { IrrlichtDevice device = IrrlichtDevice.CreateDevice( DriverType.OpenGL, new Dimension2Di(640, 480), 16, false, false, false); device.SetWindowCaption("Rockplanets BUILD 16 (DEBUG MODE)"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; CameraSceneNode cam = smgr.AddCameraSceneNode(); cam.Target = new Vector3Df(0); SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 15, 0), 30.0f); cam.AddAnimator(anim); anim.Drop(); SceneNode cube = smgr.AddCubeSceneNode(20f); cube.SetMaterialFlag(MaterialFlag.Lighting, false); while (device.Run()) { driver.BeginScene(ClearBufferFlag.All, new Color(235, 235, 235)); smgr.DrawAll(); gui.DrawAll(); driver.EndScene(); } device.Drop(); }
static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1280, 720)); if (device == null) return; VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; CameraSceneNode camera = scene.AddCameraSceneNode(); camera.FarValue = 20000; SceneNodeAnimator a = scene.CreateFlyCircleAnimator(new Vector3Df(), (AbstractTrace.CubeSize * AbstractTrace.GridDim) / 1.25f, 0.000025f, new Vector3Df(0.1f, 1, 0)); camera.AddAnimator(a); a.Drop(); trace = new AbstractTrace(device); trace.Init(); int lastFps = -1; while (device.Run()) { driver.BeginScene(); scene.DrawAll(); trace.Step(); trace.Draw(); driver.EndScene(); int fps = driver.FPS; if (fps != lastFps) { device.SetWindowCaption("Abstract Trace - Irrlicht Engine [" + fps + " fps; " + trace.GetTotalCubeCount() + " cubes]"); lastFps = fps; } } trace.Drop(); device.Drop(); }
public MeshBuffersBatch(IrrlichtDevice device, int N, bool B) { this.device = device; material = new Material(); material.Lighting = false; matrix = new Matrix(); mesh = Mesh.Create(); if (B) { generateMultiple16bitMeshbuffers(N); } else { generateSingle32BitMeshbuffer(N); } mesh.RecalculateBoundingBox(); device.Logger.Log("Collecting garbage..."); GC.Collect(); }
void runIrrlichtInWindowsFormTest(Control c) { device = new IrrlichtDevice(Irrlicht.Video.DriverType.DIRECT3D9, new Dimension2D(c.Width, c.Height), 32, false, false, false, true, c.Handle); ICameraSceneNode cam = device.SceneManager.AddCameraSceneNode(null, new Vector3D(), new Vector3D(), -1); ISceneNodeAnimator anim = device.SceneManager.CreateFlyCircleAnimator(new Vector3D(0, 10, 0), 30.0f, 0.003f); cam.AddAnimator(anim); ISceneNode cube = device.SceneManager.AddTestSceneNode(25, null, -1, new Vector3D()); cube.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../../media/rockwall.bmp")); cube.SetMaterialFlag(MaterialFlag.LIGHTING, false); // draw everything // Note, using device.WindowActive will not work on a control, since we don't // really activate controls.. while (device.Run() && c.Enabled) { device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(255, 0, 0, 50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } }
static void Main() { IrrlichtDevice device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9); device.SetWindowCaption("Analogue Clock - Irrlicht Lime"); device.CursorControl.Visible = false; ClockNode.AddClockNode(device.SceneManager.RootNode); CameraSceneNode camera = device.SceneManager.AddCameraSceneNodeFPS(null, 100, 0.1f); camera.Position = new Vector3Df(40, -20, -100); // start up position camera.Target = new Vector3Df(); // prev position change has also moved target, so we update it while (device.Run()) { device.VideoDriver.BeginScene(); device.SceneManager.DrawAll(); string s = string.Format( "{0}\n{1}\n{2}\n{3} tris\n{4} fps", device.Timer.RealTimeAndDate, device.VideoDriver.VendorInfo, device.VideoDriver.Name, device.VideoDriver.PrimitiveCountDrawn, device.VideoDriver.FPS); device.GUIEnvironment.BuiltInFont.Draw(s, 11, 11, new Color(0, 0, 0)); device.GUIEnvironment.BuiltInFont.Draw(s, 10, 10, new Color(255, 255, 255)); device.VideoDriver.EndScene(); } device.Drop(); }
public void runIndoorTest() { device = new IrrlichtDevice(SelectedDriverType, new Dimension2D(800,600), 16, false, true, false); device.EventReceiver = this; device.ResizeAble = true; device.WindowCaption = "Irrlicht.NET indoor test"; // load some textures and meshes ITexture texSydney = device.VideoDriver.GetTexture(@"..\..\media\sydney.bmp"); ITexture texWall = device.VideoDriver.GetTexture(@"..\..\media\wall.jpg"); ITexture texLogo = device.VideoDriver.GetTexture(@"..\..\media\irrlichtlogoaligned.jpg"); Irrlicht.Scene.IAnimatedMesh mesh = device.SceneManager.GetMesh(@"..\..\media\sydney.md2"); if (mesh == null) { System.Windows.Forms.MessageBox.Show( @"Could not load mesh ..\..\media\sydney.md2, exiting.", "Problem starting program"); return; } // add a cube to the scene ISceneNode node = device.SceneManager.AddCubeSceneNode(15, null, -1, new Vector3D(30,-15,0)); node.SetMaterialTexture(0, texWall); node.SetMaterialFlag(Irrlicht.Video.MaterialFlag.LIGHTING, false); // add an animator to the cube to make it rotate ISceneNodeAnimator anim = device.SceneManager.CreateRotationAnimator(new Vector3D(0.2f, 0.2f, 0)); node.AddAnimator(anim); // add animated mesh IAnimatedMeshSceneNode anode = device.SceneManager.AddAnimatedMeshSceneNode(mesh, null, -1); anode.SetMaterialTexture(0, texSydney); anode.SetMaterialFlag(MaterialFlag.LIGHTING, false); anode.Scale = new Vector3D(2,2,2); anode.Position = new Vector3D(0, -20, 0); // add a shadow Shadow = anode.AddShadowVolumeSceneNode(); if (Shadow != null) Shadow.Visible = false; // where no light there no shadow device.SceneManager.AddLightSceneNode(null, new Vector3D(20,100,-50), new Colorf(255,0,0), 200, -1); // add quake 3 level device.FileSystem.AddZipFileArchive("../../media/map-20kdm2.pk3"); IAnimatedMesh q3levelmesh = device.SceneManager.GetMesh("20kdm2.bsp"); ISceneNode q3node = device.SceneManager.AddOctTreeSceneNode(q3levelmesh, null, -1); q3node.Position = new Vector3D(-1370,-130,-1400); // create octtree triangle selector for q3 mesh ITriangleSelector selector = device.SceneManager.CreateOctTreeTriangleSelector( q3levelmesh.GetMesh(0), q3node, 128); // add billboard IBillboardSceneNode bill = device.SceneManager.AddBillboardSceneNode(null, new Dimension2Df(20,20), new Vector3D(0,0,0), -1); bill.SetMaterialType(MaterialType.TRANSPARENT_ADD_COLOR); bill.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/particle.bmp")); bill.SetMaterialFlag(MaterialFlag.LIGHTING, false); bill.SetMaterialFlag(MaterialFlag.ZBUFFER, false); // create camera ICameraSceneNode cam = device.SceneManager.AddCameraSceneNodeFPS(null, 100, 300, -1); cam.Position = new Vector3D(20,300,-50); // make cursor invisible device.CursorControl.Visible = false; // create collision animator and add it to the camera ISceneNodeAnimator collAnim = device.SceneManager.CreateCollisionResponseAnimator( selector, cam, new Vector3D(30,50,30), // size of ellipsoid around camera new Vector3D(0, -3, 0), // gravity new Vector3D(0, 50, 0), // translation 0.0005f); // sliding value cam.AddAnimator(collAnim); // load some font and set it into the skin IGUIFont font = device.GUIEnvironment.GetFont("../../media/fonthaettenschweiler.bmp"); device.GUIEnvironment.Skin.Font = font; // add some gui stuff device.GUIEnvironment.AddMessageBox("Hello World", "I'm a Irrlicht.NET MessageBox. Please press SPACE to close me.", true, MessageBoxFlag.OK | MessageBoxFlag.CANCEL, null, -1); // start drawing loop int fps = 0; device.Run(); // fix for a temporary bug where quit messages are not be removed in the queue while(device.Run()) if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(255,0,0,50)); // draw scene device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); // do some collision testing Line3D line = new Line3D(); line.start = cam.Position; line.end = ((cam.Target - line.start).Normalize() * 1000.0f ) + line.start; Vector3D intersection = new Vector3D(); Triangle3D tri = new Triangle3D(); if (device.SceneManager.SceneCollisionManager.GetCollisionPoint( line, selector, out intersection, out tri)) { bill.Position = intersection; Material mat = new Material(); mat.Lighting = false; device.VideoDriver.SetTransform(TransformationState.WORLD, new Matrix4()); device.VideoDriver.SetMaterial(mat); device.VideoDriver.Draw3DTriangle(tri, new Color(0,255,0,0)); } // draw 2d logo device.VideoDriver.Draw2DImage( texLogo, new Position2D(10,10), new Rect(0,0,88,31), new Rect(new Position2D(0,0),device.VideoDriver.ScreenSize), new Color(0xffffff), false); // draw some text font.Draw("Press 'S' to toggle the visibility of the realtime shadow.", new Position2D(120,20), new Color(100,150,200,200)); device.VideoDriver.EndScene(); if (fps != device.VideoDriver.FPS) { fps = device.VideoDriver.FPS; device.WindowCaption = "Irrlicht.NET test (primitives:" + device.VideoDriver.PrimitiveCountDrawn + ") fps:" + fps; } } }
public void run() { /* At first, we let the user select the driver type, then start up the engine, set a caption, and get a pointer to the video driver. */ // ask user for driver DriverType driverType; // Ask user to select driver: StringBuilder sb = new StringBuilder(); sb.Append("Please select the driver you want for this example:\n"); sb.Append("\n(a) Direct3D 9.0c\n(b) Direct3D 8.1\n(c) OpenGL 1.5"); sb.Append("\n(d) Software Renderer\n(e) Apfelbaum Software Renderer"); sb.Append("\n(f) Null Device\n(otherKey) exit\n\n"); // Get the user's input: TextReader tIn = Console.In; TextWriter tOut = Console.Out; tOut.Write(sb.ToString()); string input = tIn.ReadLine(); // Select device based on user's input: switch (input) { case "a": driverType = DriverType.DIRECT3D9; break; case "b": driverType = DriverType.DIRECT3D8; break; case "c": driverType = DriverType.OPENGL; break; case "d": driverType = DriverType.SOFTWARE; break; case "e": driverType = DriverType.SOFTWARE2; break; case "f": driverType = DriverType.NULL_DRIVER; break; default: return; } // Create device and exit if creation fails: device = new IrrlichtDevice(driverType, new Dimension2D(1024, 768), 32, false, true, true); if (device == null) { tOut.Write("Device creation failed."); return; } /* Get a pointer to the video driver and the SceneManager so that we do not always have to write device->getVideoDriver() and device->getSceneManager(). */ ISceneManager smgr=device.SceneManager; IVideoDriver driver=device.VideoDriver; device.FileSystem.AddZipFileArchive(path+"map-20kdm2.pk3"); IAnimatedMesh q3levelmesh = smgr.GetMesh("20kdm2.bsp"); ISceneNode q3node = null; if (q3levelmesh!=null) q3node=smgr.AddOctTreeSceneNode(q3levelmesh.GetMesh(0),null,0); /*So far so good, we've loaded the quake 3 level like in tutorial 2. Now, here comes something different: We create a triangle selector. A triangle selector is a class which can fetch the triangles from scene nodes for doing different things with them, for example collision detection. There are different triangle selectors, and all can be created with the ISceneManager. In this example, we create an OctTreeTriangleSelector, which optimizes the triangle output a little bit by reducing it like an octree. This is very useful for huge meshes like quake 3 levels. After we created the triangle selector, we attach it to the q3node. This is not necessary, but in this way, we do not need to care for the selector, for example dropping it after we do not need it anymore.*/ ITriangleSelector selector = null; if (q3node!=null) { q3node.Position= new Vector3D(-1370,-130,-1400); selector=smgr.CreateOctTreeTriangleSelector( q3levelmesh.GetMesh(0),q3node,128); // not implemented but not necessary //q3node.TriangleSelector=selector; } /*We add a first person shooter camera to the scene for being able to move in the quake 3 level like in tutorial 2. But this, time, we add a special animator to the camera: A Collision Response animator. This thing modifies the scene node to which it is attached to in that way, that it may no more move through walls and is affected by gravity. The only thing we have to tell the animator is how the world looks like, how big the scene node is, how gravity and so on. After the collision response animator is attached to the camera, we do not have to do anything more for collision detection, anything is done automaticly, all other collision detection code below is for picking. And please note another cool feature: The collsion response animator can be attached also to all other scene nodes, not only to cameras. And it can be mixed with other scene node animators. In this way, collision detection and response in the Irrlicht engine is really, really easy. Now we'll take a closer look on the parameters of createCollisionResponseAnimator(). The first parameter is the TriangleSelector, which specifies how the world, against collision detection is done looks like. The second parameter is the scene node, which is the object, which is affected by collision detection, in our case it is the camera. The third defines how big the object is, it is the radius of an ellipsoid. Try it out and change the radius to smaller values, the camera will be able to move closer to walls after this. The next parameter is the direction and speed of gravity. You could set it to (0,0,0) to disable gravity. And the last value is just a translation: Without this, the ellipsoid with which collision detection is done would be around the camera, and the camera would be in the middle of the ellipsoid. But as human beings, we are used to have our eyes on top of the body, with which we collide with our world, not in the middle of it. So we place the scene node 50 units over the center of the ellipsoid with this parameter. And that's it, collision detection works now. */ ICameraSceneNode camera = smgr.AddCameraSceneNodeFPS(null,100,300,0); camera.Position=new Vector3D(-100,50,-150); ISceneNodeAnimator anim = smgr.CreateCollisionResponseAnimator( selector,camera,new Vector3D(30,50,30), new Vector3D(0,-3,0),new Vector3D(0,50,0),0); camera.AddAnimator(anim); /*Because collision detection is no big deal in irrlicht, I'll describe how to do two different types of picking in the next section. But before this, I'll prepare the scene a little. I need three animated characters which we could pick later, a dynamic light for lighting them, a billboard for drawing where we found an intersection, and, yes, I need to get rid of this mouse cursor. :)*/ //disable mouse cursor device.CursorControl.Visible=false; // add billboard IBillboardSceneNode bill = smgr.AddBillboardSceneNode( null,new Dimension2Df(20,20),new Vector3D(),0); bill.SetMaterialType(MaterialType.TRANSPARENT_ADD_COLOR); bill.SetMaterialTexture(0,driver.GetTexture( path+"particle.bmp")); bill.SetMaterialFlag(MaterialFlag.LIGHTING,false); bill.SetMaterialFlag(MaterialFlag.ZBUFFER,false); Material material = new Material(); material.Texture1= driver.GetTexture( path+"faerie2.bmp"); material.Lighting=true; IAnimatedMeshSceneNode node = null; IAnimatedMesh faerie = smgr.GetMesh( path+"faerie.md2"); if (faerie!=null) { node=smgr.AddAnimatedMeshSceneNode(faerie,null,0); node.Position=new Vector3D(-70,0,-90); node.SetMD2Animation(MD2AnimationType.RUN); node.SetMaterial(0,material); node=smgr.AddAnimatedMeshSceneNode(faerie,null,0); node.Position=new Vector3D(-70,0,-30); node.SetMD2Animation(MD2AnimationType.SALUTE); node.SetMaterial(0,material); node=smgr.AddAnimatedMeshSceneNode(faerie,null,0); node.Position=new Vector3D(-70,0,-60); node.SetMD2Animation(MD2AnimationType.JUMP); node.SetMaterial(0,material); } material.Texture1=null; material.Lighting=false; //Add a light smgr.AddLightSceneNode(null,new Vector3D(-60,100,400), new Colorf(1.0f,1.0f,1.0f,1.0f),600,0); /*For not making it too complicated, I'm doing picking inside the drawing loop. We take two pointers for storing the current and the last selected scene node and start the loop.*/ ISceneNode selectedSceneNode =null; ISceneNode lastSelectedSceneNode =null; int lastFPS=-1; while (device.Run()) { if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(0, 200, 200, 200)); device.SceneManager.DrawAll(); /*After we've drawn the whole scene whit smgr->drawAll(), we'll do the first picking: We want to know which triangle of the world we are looking at. In addition, we want the exact point of the quake 3 level we are looking at. For this, we create a 3d line starting at the position of the camera and going through the lookAt-target of it. Then we ask the collision manager if this line collides with a triangle of the world stored in the triangle selector. If yes, we draw the 3d triangle and set the position of the billboard to the intersection point.*/ Line3D line = new Line3D(); line.start=camera.Position; line.end=line.start+ (camera.Target - line.start).Normalize() * 1000; Vector3D intersection; Triangle3D tri; if (smgr.SceneCollisionManager.GetCollisionPoint( line,selector,out intersection, out tri)) { bill.Position=intersection; driver.SetTransform(TransformationState.WORLD, new Matrix4()); driver.SetMaterial(material); driver.Draw3DTriangle(tri,new Color(0,255,0,0)); } /*Another type of picking supported by the Irrlicht Engine is scene node picking based on bouding boxes. Every scene node has got a bounding box, and because of that, it's very fast for example to get the scene node which the camera looks at. Again, we ask the collision manager for this, and if we've got a scene node, we highlight it by disabling Lighting in its material, if it is not the billboard or the quake 3 level.*/ selectedSceneNode=smgr.SceneCollisionManager. GetSceneNodeFromCameraBB(camera,0); if (lastSelectedSceneNode!=null) lastSelectedSceneNode.SetMaterialFlag( MaterialFlag.LIGHTING, true); if (selectedSceneNode==q3node|| selectedSceneNode==bill) selectedSceneNode=null; if(selectedSceneNode!=null) selectedSceneNode.SetMaterialFlag( MaterialFlag.LIGHTING,false); lastSelectedSceneNode=selectedSceneNode; /*That's it, we just have to finish drawing.*/ driver.EndScene(); int fps = device.VideoDriver.FPS; if (lastFPS != fps) { device.WindowCaption = "Irrlicht Engine - Quake 3 Map example [" + device.VideoDriver.Name + "] FPS:" + fps.ToString(); lastFPS = fps; } } } /* In the end, delete the Irrlicht device. */ // Instead of device->drop, we'll use: GC.Collect(); }
public Particles(IrrlichtDevice device) { this.device = device; particleNodes = new List<ParticleNode>(); }
public void runTerrainTest() { device = new IrrlichtDevice(SelectedDriverType, new Dimension2D(800,600), 16, false, false, false); device.EventReceiver = this; device.ResizeAble = true; device.WindowCaption = "Irrlicht.NET terrain test"; // create a camera ICameraSceneNode cam = device.SceneManager.AddCameraSceneNodeFPS(null, 100, 1200, -1); cam.Position = new Vector3D(1900*2, 255*2, 3700*2); cam.Target = new Vector3D(2397*2, 343*2, 2700*2); cam.FarValue = 12000.0f; // create the terrain ITerrainSceneNode terrain = device.SceneManager.AddTerrainSceneNode( "../../media/terrain-heightmap.bmp", null, -1, new Vector3D(), new Vector3D(40, 4.4f, 40), new Color(255,255,255,255)); terrain.SetMaterialFlag(MaterialFlag.LIGHTING, false); terrain.SetMaterialType(MaterialType.DETAIL_MAP); terrain.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/terrain-texture.jpg")); terrain.SetMaterialTexture(1, device.VideoDriver.GetTexture("../../media/detailmap3.jpg")); terrain.ScaleTexture( 1.0f, 20.0f ); // create terrain triangle selector for collision ITriangleSelector selector = device.SceneManager.CreateTerrainTriangleSelector( terrain, 0 ); // create collision animator and add it to the camera ISceneNodeAnimator collAnim = device.SceneManager.CreateCollisionResponseAnimator( selector, cam, new Vector3D(30,50,30), // size of ellipsoid around camera new Vector3D(0, 0, 0), // gravity new Vector3D(0, 50, 0), // translation 0.0005f); // sliding value cam.AddAnimator(collAnim); // add sky box device.SceneManager.AddSkyBoxSceneNode( device.VideoDriver.GetTexture("../../media/irrlicht2_up.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_dn.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_lf.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_rt.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_ft.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_bk.jpg"), null, -1); // make cursor invisible device.CursorControl.Visible = false; // draw everything device.Run(); // fix for a temporary bug where quit messages are not be removed in the queue while(device.Run()) { if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(255,0,0,50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } } }
public void runShaderTest() { // testing irrlicht with shaders device = new IrrlichtDevice(SelectedDriverType, new Dimension2D(800,600), 16, false, true, false); device.EventReceiver = this; device.ResizeAble = true; device.WindowCaption = "Irrlicht.NET shader test"; String vsFileName = ""; String psFileName = ""; UseHighLevelShaders = false; switch(SelectedDriverType) { case DriverType.DIRECT3D8: psFileName = "../../media/d3d8.psh"; vsFileName = "../../media/d3d8.vsh"; break; case DriverType.DIRECT3D9: if (UseHighLevelShaders) { psFileName = "../../media/d3d9.hlsl"; vsFileName = psFileName; // both shaders are in the same file } else { psFileName = "../../media/d3d9.psh"; vsFileName = "../../media/d3d9.vsh"; } break; case DriverType.OPENGL: if (UseHighLevelShaders) { psFileName = "../../media/opengl.frag"; vsFileName = "../../media/opengl.vert"; } else { psFileName = "../../media/opengl.psh"; vsFileName = "../../media/opengl.vsh"; } break; } // create materials int newMaterialType1 = 0; int newMaterialType2 = 0; if ( device.VideoDriver.GPUProgrammingServices != null ) { IShaderConstantSetCallBack callBack = this; if (UseHighLevelShaders) { newMaterialType1 = device.VideoDriver.GPUProgrammingServices.AddHighLevelShaderMaterialFromFiles( vsFileName, "vertexMain", VertexShaderType.VST_VS_1_1, psFileName, "pixelMain", PixelShaderType.PST_PS_1_1, callBack, MaterialType.SOLID); newMaterialType2 = device.VideoDriver.GPUProgrammingServices.AddHighLevelShaderMaterialFromFiles( vsFileName, "vertexMain", VertexShaderType.VST_VS_1_1, psFileName, "pixelMain", PixelShaderType.PST_PS_1_1, callBack, MaterialType.TRANSPARENT_ADD_COLOR); } else { newMaterialType1 = device.VideoDriver.GPUProgrammingServices.AddShaderMaterialFromFiles( vsFileName, psFileName, callBack, MaterialType.SOLID ); newMaterialType2 = device.VideoDriver.GPUProgrammingServices.AddShaderMaterialFromFiles( vsFileName, psFileName, callBack, MaterialType.TRANSPARENT_ADD_COLOR ); } } // create test scene node 1, with the new created material type 1 ISceneNode node = device.SceneManager.AddCubeSceneNode(50, null, -1, new Vector3D(0,0,0)); node.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/wall.bmp")); node.SetMaterialType((MaterialType)newMaterialType1); node.SetMaterialFlag(Irrlicht.Video.MaterialFlag.LIGHTING, false); //device.SceneManager.AddTextSceneNode( device.GUIEnvironment.BuiltInFont, // "PS & VS & EMT_SOLID", new Color(255,255,255,255), node, new Vector3D(0,0,0), -1); ISceneNodeAnimator anim = device.SceneManager.CreateRotationAnimator( new Vector3D(0,0.3f,0) ); node.AddAnimator(anim); // create test scene node 1, with the new created material type 1 node = device.SceneManager.AddCubeSceneNode(50, null, -1, new Vector3D(0,-10,50)); node.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/wall.bmp")); node.SetMaterialType((MaterialType)newMaterialType2); node.SetMaterialFlag(Irrlicht.Video.MaterialFlag.LIGHTING, false); //device.SceneManager.AddTextSceneNode( device.GUIEnvironment.BuiltInFont, // "PS & VS & EMT_TRANSPARENT", new Color(255,255,255,255), node, new Vector3D(0,0,0), -1); anim = device.SceneManager.CreateRotationAnimator( new Vector3D(0,0.3f,0) ); node.AddAnimator(anim); //Then we add a third cube without a shader on it, to be able to compare the //cubes. node = device.SceneManager.AddCubeSceneNode(50, null, -1, new Vector3D(0,50,25)); node.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/wall.bmp")); node.SetMaterialFlag(Irrlicht.Video.MaterialFlag.LIGHTING, false); //device.SceneManager.AddTextSceneNode( device.GUIEnvironment.BuiltInFont, // "NO SHADER", new Color(255,255,255,255), node, new Vector3D(0,0,0), -1); // And last, we add a skybox and a user controlled camera to the scene. device.SceneManager.AddSkyBoxSceneNode( device.VideoDriver.GetTexture("../../media/irrlicht2_up.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_dn.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_lf.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_rt.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_ft.jpg"), device.VideoDriver.GetTexture("../../media/irrlicht2_bk.jpg"), null, -1 ); ICameraSceneNode cam = device.SceneManager.AddCameraSceneNodeFPS(); cam.Target = new Vector3D(0,0,0); cam.Position = new Vector3D(-100,50,100); device.CursorControl.Visible = false; device.Run(); // fix for a temporary bug where quit messages are not be removed in the queue while(device.Run()) if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(255,0,0,50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } }
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(); }
void runIrrlichtInWindowsFormTest(Control c) { device = new IrrlichtDevice(Irrlicht.Video.DriverType.DIRECT3D9, new Dimension2D(c.Width, c.Height), 32, false, false, false, true, c.Handle); ICameraSceneNode cam = device.SceneManager.AddCameraSceneNode(null, new Vector3D(), new Vector3D(), -1); ISceneNodeAnimator anim = device.SceneManager.CreateFlyCircleAnimator(new Vector3D(0, 10, 0), 30.0f, 0.003f); cam.AddAnimator(anim); ISceneNode cube = device.SceneManager.AddTestSceneNode(25, null, -1, new Vector3D()); cube.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../../media/rockwall.bmp")); cube.SetMaterialFlag(MaterialFlag.LIGHTING, false); // draw everything // Note, using device.WindowActive will not work on a control, since we don't // really activate controls.. while (device.Run() && c.Enabled) { device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(255, 0, 0, 50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } }
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(); }
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(); } else { Thread.Sleep(50); } irrThreadProcessCommandQueue(); rs = irrDevice.Timer.Time; } irrDevice.Drop(); }
static void Main(string[] args) { int lodItemCount = AskUserForLODItemCount(); DriverType driverType; if (!AskUserForDriver(out driverType)) return; device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(800, 600)); if (device == null) return; device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.SetWindowCaption("Simple LOD - Irrlicht Lime"); device.CursorControl.Visible = false; VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; // generate all LODs of mesh List<Mesh> lodMesh = new List<Mesh>(); Material meshMaterial = null; List<int> lodTriangleCount = new List<int>(); int[] p = new int[] { 100, 50, 32, 20, 12, 6, 3 }; for (int i = 0; i < p.Length; i++) { Mesh m = scene.GeometryCreator.CreateSphereMesh(50, p[i], p[i]); MeshBuffer mb = m.GetMeshBuffer(0); mb.Material.Type = MaterialType.Solid; mb.Material.SetTexture(0, driver.GetTexture("../../media/earth.jpg")); m.SetMaterialFlag(MaterialFlag.Lighting, false); lodMesh.Add(m); if (meshMaterial == null) meshMaterial = m.GetMeshBuffer(0).Material; lodTriangleCount.Add(mb.IndexCount / 3); } // generate world, // we generate a lot of objects with random positions in huge virtual cube int virtualCubeSide = 20000; LODItem[] lodItems = new LODItem[lodItemCount]; Random r = new Random(12345000); for (int i = 0; i < lodItemCount; i++) { Matrix tmat = new Matrix( new Vector3Df( // translation r.Next(virtualCubeSide) - virtualCubeSide / 2, r.Next(virtualCubeSide) - virtualCubeSide / 2, r.Next(virtualCubeSide) - virtualCubeSide / 2)); Vector3Df rvect = new Vector3Df( (float)r.NextDouble() / 200.0f, (float)r.NextDouble() / 200.0f, (float)r.NextDouble() / 200.0f); lodItems[i] = LODItem.Create(device, lodMesh, tmat, rvect); } // split world on virtual sectors (cubes) for faster visibility check int lodSectorSide = 6; // total number of sectors will be lodSectorSide^3, so for 6 it is 216 int lodSectorSize = virtualCubeSide / lodSectorSide; LODSector[,,] lodSectors = new LODSector[lodSectorSide, lodSectorSide, lodSectorSide]; for (int i = 0; i < lodSectorSide; i++) { for (int j = 0; j < lodSectorSide; j++) { for (int k = 0; k < lodSectorSide; k++) { AABBox dimension = new AABBox( new Vector3Df(i * lodSectorSize, j * lodSectorSize, k * lodSectorSize), new Vector3Df((i + 1) * lodSectorSize, (j + 1) * lodSectorSize, (k + 1) * lodSectorSize)); dimension.MinEdge -= virtualCubeSide / 2; dimension.MaxEdge -= virtualCubeSide / 2; LODSector s = LODSector.Create(dimension); lodSectors[i, j, k] = s; } } } for (int i = 0; i < lodItems.Length; i++) { Vector3Df pos = lodItems[i].Position; pos += virtualCubeSide / 2; pos /= lodSectorSize; int ix = (int)pos.X; int iy = (int)pos.Y; int iz = (int)pos.Z; if (ix < 0) ix = 0; if (ix > lodSectorSide - 1) ix = lodSectorSide - 1; if (iy < 0) ix = 0; if (iy > lodSectorSide - 1) iy = lodSectorSide - 1; if (iz < 0) iz = 0; if (iz > lodSectorSide - 1) iz = lodSectorSide - 1; lodSectors[ix, iy, iz].AddLODItem(lodItems[i]); } // camera CameraSceneNode camera = scene.AddCameraSceneNodeFPS(); camera.FarValue = 30000; // font, which we are going to use to show any text we need IrrlichtLime.GUI.GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); // render loop while (device.Run()) { driver.BeginScene(); scene.DrawAll(); if (isLabelMode) { LODItem.LabelPositions = new List<Vector2Di>(); LODItem.LabelTexts = new List<string>(); } else { LODItem.LabelPositions = null; LODItem.LabelTexts = null; } meshMaterial.Wireframe = isWireframeMode; device.VideoDriver.SetMaterial(meshMaterial); uint timer = device.Timer.Time; Vector3Df cameraPosition = camera.AbsolutePosition; AABBox cameraViewBox = camera.ViewFrustum.BoundingBox; for (int i = 0; i < lodSectorSide; i++) { for (int j = 0; j < lodSectorSide; j++) { for (int k = 0; k < lodSectorSide; k++) { lodSectors[i, j, k].Draw(timer, cameraPosition, cameraViewBox); } } } if (isLabelMode) { for (int i = 0; i < LODItem.LabelPositions.Count; i++) { driver.Draw2DLine( LODItem.LabelPositions[i] - new Vector2Di(10, 0), LODItem.LabelPositions[i] + new Vector2Di(50, 0), Color.OpaqueGreen); driver.Draw2DLine( LODItem.LabelPositions[i] - new Vector2Di(0, 10), LODItem.LabelPositions[i] + new Vector2Di(0, 50), Color.OpaqueGreen); font.Draw(LODItem.LabelTexts[i], LODItem.LabelPositions[i], Color.OpaqueGreen); } } if (isStatsMode) { // show LOD stats int[] lodCount = new int[7] { 0, 0, 0, 0, 0, 0, 0 }; for (int i = 0; i < lodItems.Length; i++) lodCount[lodItems[i].CurrentLOD]++; string f = ""; for (int i = 0; i < lodCount.Length; i++) { int n = lodCount[i]; f += "LOD" + i.ToString() + ": " + n.ToString() + " [" + ((n * 100) / lodItemCount).ToString() + "%] objects\n"; } string l = "------------------------"; font.Draw( string.Format("Stats\n{0}\n{1}{2}\nTotal: {3} [100%] objects", l, f, l, lodItemCount), new Vector2Di(10, 140), Color.OpaqueMagenta); } // show general stats font.Draw(string.Format( "Camera position: {0}\nTotal LOD 0 triangles: {1}\nTriangles currently drawn: {2}\nDriver: {3}\nFPS: {4}", camera.AbsolutePosition, lodTriangleCount[0] * lodItemCount, driver.PrimitiveCountDrawn, driver.Name, driver.FPS), 10, 10, Color.OpaqueYellow); // show active keys font.Draw( "[S] Toggle stats\n[W] Toggle wireframe\n[L] Toggle labels (only for LODs from 0 to 4)\n[Esc] Exit application", 10, driver.ScreenSize.Height - 80, Color.OpaqueCyan); driver.EndScene(); } // drop device.Drop(); }
public MeshBuffersBatch(IrrlichtDevice device, int N, bool B) { this.device = device; material = new Material(); material.Lighting = false; matrix = new Matrix(); mesh = Mesh.Create(); if (B) generateMultiple16bitMeshbuffers(N); else generateSingle32BitMeshbuffer(N); mesh.RecalculateBoundingBox(); device.Logger.Log("Collecting garbage..."); GC.Collect(); }
/// <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(); }
public static void takeScreenshot(IrrlichtDevice device) { VideoDriver driver = device.VideoDriver; Image screenshot = driver.CreateScreenShot(); string filename = "screenshot_" + device.Timer.RealTime + ".png"; driver.WriteImage(screenshot, filename); }
static public LODItem Create(IrrlichtDevice device, List<Mesh> meshLODs, Matrix transformation, Vector3Df rotationVector) { LODItem n = new LODItem(); n.device = device; n.meshLODs = meshLODs; n.transformation = transformation; n.rotationVector = rotationVector; n.currentLOD = meshLODs.Count - 1; // we cache some really frequently accessed values (which will never get changed anyway) n.driver = device.VideoDriver; n.screenSize = device.VideoDriver.ScreenSize; return n; }
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(); }
void runIrrlichtInWindowsFormTest() { // testing irrlicht running embedded in a windows form System.Windows.Forms.Form f = new System.Windows.Forms.Form(); f.Text = "Irrlicht running embedded in Windows.Form"; device = new IrrlichtDevice(SelectedDriverType, new Dimension2D(800,600), 16, false, false, false, true, f.Handle); f.Show(); // set up a simple scene ICameraSceneNode cam = device.SceneManager.AddCameraSceneNode( null, new Vector3D(), new Vector3D(), -1); ISceneNodeAnimator anim = device.SceneManager.CreateFlyCircleAnimator( new Vector3D(0,10,0), 30.0f, 0.003f); cam.AddAnimator(anim); ISceneNode cube = device.SceneManager.AddCubeSceneNode(25, null, -1, new Vector3D()); cube.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/rockwall.bmp")); cube.SetMaterialFlag(Irrlicht.Video.MaterialFlag.LIGHTING, false); // draw everything device.Run(); // fix for a temporary bug where quit messages are not be removed in the queue while(device.Run() && f.Visible) if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(255,0,0,50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } }
public void displayMainMenu() { device = new IrrlichtDevice(DriverType.SOFTWARE, new Dimension2D(512, 384), 16, false, false, false); // set event receiver device.EventReceiver = this; // set text device.WindowCaption = "Irrlicht .NET test demos - main menu"; // load font IGUIFont font = device.GUIEnvironment.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) device.GUIEnvironment.Skin.Font = font; // add images device.GUIEnvironment.AddImage( device.VideoDriver.GetTexture("../../media/dotnetback.jpg"), new Position2D(0,0), false, null, -1, ""); // add list box Rect pos = new Rect(150,60,350,135); IGUIListBox box = device.GUIEnvironment.AddListBox( pos, null, -1, true ); box.AddItem("Irrlicht Software Renderer 1.0"); box.AddItem("Apfelbaum Software Renderer 1.0"); box.AddItem("Direct3D 8.1"); box.AddItem("Direct3D 9.0c"); box.AddItem("OpenGL 1.5"); box.Selected = ((int)SelectedDriverType)-1; // add terrain button pos.LowerRightCorner.Y += 50; pos.UpperLeftCorner.Y += 100; device.GUIEnvironment.AddButton( pos, null, (int)TestScenarios.TERRAIN_TEST, "Start Terrain Test" ); // add indoor button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton( pos, null, (int)TestScenarios.INDOOR_TEST, "Start Indoor Test" ); // add windows forms button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton( pos, null, (int)TestScenarios.WINDOWS_FORMS_TEST, "Start Windows.Forms Test" ); // add shader test button pos.LowerRightCorner.Y += 30; pos.UpperLeftCorner.Y += 30; device.GUIEnvironment.AddButton( pos, null, (int)TestScenarios.SHADER_TEST, "Start Shader Test" ); // add copyright stuff IGUIStaticText text = device.GUIEnvironment.AddStaticText( "Background 3D scene created by Alvaro F. Celis, rendered using Irrlicht", new Rect(2,368,500,384), false, false, null, -1); text.OverrideColor = new Color(100,150,150,150); // draw everything while(device.Run() && ClickedButton == TestScenarios.NONE) if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(255,0,0,50)); device.SceneManager.DrawAll(); device.GUIEnvironment.DrawAll(); device.VideoDriver.EndScene(); } device.CloseDevice(); return; }
static void Main(string[] args) { // start up the engine IrrlichtDevice device = new IrrlichtDevice(DriverType.OPENGL); device.ResizeAble = true; device.WindowCaption = "Irrlicht.NET C# example 01 - Hello World"; // load some textures ITexture texSydney = device.VideoDriver.GetTexture(@"..\..\media\sydney.bmp"); ITexture texWall = device.VideoDriver.GetTexture(@"..\..\media\wall.bmp"); ITexture texLogo = device.VideoDriver.GetTexture(@"..\..\media\irrlichtlogoaligned.jpg"); // load the animated mesh of sydney Irrlicht.Scene.IAnimatedMesh mesh = device.SceneManager.GetMesh(@"..\..\media\sydney.md2"); if (mesh == null) { System.Windows.Forms.MessageBox.Show( @"Could not load mesh ..\..\media\sydney.md2, exiting.", "Problem starting program"); return; } // add a camera, a test scene node and the animated mesh to the scene ICameraSceneNode cam = device.SceneManager.AddCameraSceneNodeFPS(null, 100, 100, -1); cam.Position = new Vector3D(20,0,-50); ISceneNode node = device.SceneManager.AddCubeSceneNode(15, null, -1, new Vector3D(30,-15,0)); node.SetMaterialTexture(0, texWall); node = device.SceneManager.AddAnimatedMeshSceneNode(mesh, null, -1); node.SetMaterialTexture(0, texSydney); node.SetMaterialFlag(MaterialFlag.LIGHTING, false); // make cursor invisible device.CursorControl.Visible = false; // start drawing loop int fps = 0; while(device.Run()) { if (device.WindowActive) { device.VideoDriver.BeginScene(true, true, new Color(0,100,100,100)); device.SceneManager.DrawAll(); // draw the logo device.VideoDriver.Draw2DImage( texLogo, new Position2D(10,10), new Rect(0,0,88,31), new Rect(new Position2D(0,0),device.VideoDriver.ScreenSize), new Color(0xffffff), false); device.VideoDriver.EndScene(); if (fps != device.VideoDriver.FPS) { fps = device.VideoDriver.FPS; device.WindowCaption = "Irrlicht.NET C# example 01 - Hello World ["+ device.VideoDriver.Name + "] fps:" + fps; } } } // end drawing-loop }