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(); }
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(); }
public void Drop() { if (IsLocked()) { throw new InvalidOperationException(); } device.Drop(); }
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(); }
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() { 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() { 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(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(); }
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(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 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) { 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(); }
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(); }
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() { 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(); }
static void Main(string[] args) { // Initialize device. DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) { return; } // Add event handling. device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); // Save important pointers. VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; Logger logger = device.Logger; // Initialize joysticks and print info about them. List <JoystickInfo> joystickList = device.ActivateJoysticks(); if (joystickList != null) { logger.Log("Joystick support is enabled and " + joystickList.Count.ToString() + " joystick(s) are present."); foreach (JoystickInfo j in joystickList) { logger.Log("Joystick " + j.Joystick.ToString() + ":"); logger.Log("\tName: \"" + j.Name + "\""); logger.Log("\tAxisCount: " + j.AxisCount.ToString()); logger.Log("\tButtonCount: " + j.ButtonCount.ToString()); logger.Log("\tPovHat: " + j.PovHat.ToString()); } } else { logger.Log("Joystick support is not enabled."); } device.SetWindowCaption("Mouse and joystick - Irrlicht Lime - " + joystickList.Count.ToString() + " joystick(s)"); // Create an arrow mesh and move it around either with the joystick axis/hat, // or make it follow the mouse pointer (when no joystick movement). SceneNode node = smgr.AddMeshSceneNode( smgr.AddArrowMesh( "Arrow", new Color(255, 0, 0), new Color(0, 255, 0), 16, 16, 2.0f, 1.3f, 0.1f, 0.6f ) ); node.SetMaterialFlag(MaterialFlag.Lighting, false); CameraSceneNode camera = smgr.AddCameraSceneNode(); camera.Position = new Vector3Df(0, 0, -10); // As in example #4, we'll use framerate independent movement. uint then = device.Timer.Time; const float MovementSpeed = 5.0f; // Run main cycle. while (device.Run()) { // Work out a frame delta time. uint now = device.Timer.Time; float frameDeltaTime = (float)(now - then) / 1000.0f; // in seconds then = now; bool movedWithJoystick = false; Vector3Df nodePosition = node.Position; if (joystickList.Count > 0) { float moveHorizontal = 0.0f; // range is -1.0 for full left to +1.0 for full right float moveVertical = 0.0f; // range is -1.0 for full down to +1.0 for full up // We receive the full analog range of the axes, and so have to implement our own dead zone. // This is an empirical value, since some joysticks have more jitter or creep around the center // point than others. We'll use 5% of the range as the dead zone, but generally you would want // to give the user the option to change this. float DeadZone = 0.05f; moveHorizontal = joystickState.Axis[0] / 32767.0f; // "0" for X axis if (Math.Abs(moveHorizontal) < DeadZone) { moveHorizontal = 0.0f; } moveVertical = joystickState.Axis[1] / -32767.0f; // "1" for Y axis if (Math.Abs(moveVertical) < DeadZone) { moveVertical = 0.0f; } // POV will contain 65535 if POV hat info no0t supported, so we can check its range. ushort povDegrees = (ushort)(joystickState.POV / 100); if (povDegrees < 360) { if (povDegrees > 0 && povDegrees < 180) { moveHorizontal = +1.0f; } else if (povDegrees > 180) { moveHorizontal = -1.0f; } if (povDegrees > 90 && povDegrees < 270) { moveVertical = -1.0f; } else if (povDegrees > 270 || povDegrees < 90) { moveVertical = +1.0f; } } // If we have any movement, apply it. if (Math.Abs(moveHorizontal) > 0.0001f || Math.Abs(moveVertical) > 0.0001f) { float m = frameDeltaTime * MovementSpeed; nodePosition = new Vector3Df(moveHorizontal * m, moveVertical * m, nodePosition.Z); movedWithJoystick = true; } } // If the arrow node isn't being moved with the joystick, then have it follow the mouse cursor. if (!movedWithJoystick) { // Create a ray through the mouse cursor. Line3Df ray = smgr.SceneCollisionManager.GetRayFromScreenCoordinates(mouseState.Position, camera); // And intersect the ray with a plane around the node facing towards the camera. Plane3Df plane = new Plane3Df(nodePosition, new Vector3Df(0, 0, -1)); Vector3Df mousePosition; if (plane.GetIntersectionWithLine(ray.Start, ray.Vector, out mousePosition)) { // We now have a mouse position in 3d space; move towards it. Vector3Df toMousePosition = mousePosition - nodePosition; float availableMovement = frameDeltaTime * MovementSpeed; if (toMousePosition.Length <= availableMovement) { nodePosition = mousePosition; // jump to the final position } else { nodePosition += toMousePosition.Normalize() * availableMovement; // move towards it } } } node.Position = nodePosition; // Turn lighting on and off depending on whether the left mouse button is down. node.SetMaterialFlag(MaterialFlag.Lighting, mouseState.IsLeftButtonDown); // Draw all. driver.BeginScene(true, true, new Color(113, 113, 133)); smgr.DrawAll(); driver.EndScene(); } // Drop the device. device.Drop(); }
private void backgroundRendering_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; DeviceSettings settings = e.Argument as DeviceSettings; // create irrlicht device using provided settings IrrlichtDevice dev = IrrlichtDevice.CreateDevice(settings); if (dev == null) { throw new Exception("Failed to create Irrlicht device."); } VideoDriver drv = dev.VideoDriver; SceneManager smgr = dev.SceneManager; // setup a simple 3d scene CameraSceneNode cam = smgr.AddCameraSceneNode(); cam.Target = new Vector3Df(0); SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 15, 0), 30.0f); cam.AddAnimator(anim); anim.Drop(); SceneNode cube = smgr.AddCubeSceneNode(20); cube.SetMaterialTexture(0, drv.GetTexture("../../media/wall.bmp")); cube.SetMaterialTexture(1, drv.GetTexture("../../media/water.jpg")); cube.SetMaterialFlag(MaterialFlag.Lighting, false); cube.SetMaterialType(MaterialType.Reflection2Layer); if (settings.BackColor == null) { smgr.AddSkyBoxSceneNode( "../../media/irrlicht2_up.jpg", "../../media/irrlicht2_dn.jpg", "../../media/irrlicht2_lf.jpg", "../../media/irrlicht2_rt.jpg", "../../media/irrlicht2_ft.jpg", "../../media/irrlicht2_bk.jpg"); } dev.GUIEnvironment.AddImage( drv.GetTexture("../../media/lime_logo_alpha.png"), new Vector2Di(30, 0)); // draw all int lastFPS = -1; while (dev.Run()) { if (settings.BackColor == null) { // indeed, we do not need to spend time on cleaning color buffer if we use skybox drv.BeginScene(false); } else { drv.BeginScene(true, true, settings.BackColor); } smgr.DrawAll(); dev.GUIEnvironment.DrawAll(); drv.EndScene(); int fps = drv.FPS; if (lastFPS != fps) { // report progress using common BackgroundWorker' method // note: we cannot do just labelRenderingStatus.Text = "...", // because we are running another thread worker.ReportProgress(fps, drv.Name); lastFPS = fps; } // if we requested to stop, we close the device if (worker.CancellationPending) { dev.Close(); } } // drop device dev.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment env = device.GUIEnvironment; // load and display animated fairy mesh AnimatedMeshSceneNode fairy = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/faerie.md2")); if (fairy != null) { fairy.SetMaterialTexture(0, driver.GetTexture("../../media/faerie2.bmp")); // set diffuse texture fairy.SetMaterialFlag(MaterialFlag.Lighting, true); // enable dynamic lighting fairy.GetMaterial(0).Shininess = 20.0f; // set size of specular highlights fairy.Position = new Vector3Df(-10, 0, -100); fairy.SetMD2Animation(AnimationTypeMD2.Stand); } // add white light smgr.AddLightSceneNode(null, new Vector3Df(-15, 5, -105), new Colorf(1, 1, 1)); // set ambient light smgr.AmbientLight = new Colorf(0.25f, 0.25f, 0.25f); // add fps camera CameraSceneNode fpsCamera = smgr.AddCameraSceneNodeFPS(); fpsCamera.Position = new Vector3Df(-50, 50, -150); // disable mouse cursor device.CursorControl.Visible = false; // create test cube SceneNode test = smgr.AddCubeSceneNode(60); // let the cube rotate and set some light settings SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0.3f, 0.3f, 0)); test.Position = new Vector3Df(-100, 0, -100); test.SetMaterialFlag(MaterialFlag.Lighting, false); // disable dynamic lighting test.AddAnimator(anim); anim.Drop(); // create render target Texture rt = null; CameraSceneNode fixedCam = null; if (driver.QueryFeature(VideoDriverFeature.RenderToTarget)) { rt = driver.AddRenderTargetTexture(new Dimension2Di(256), "RTT1"); test.SetMaterialTexture(0, rt); // set material of cube to render target // add fixed camera fixedCam = smgr.AddCameraSceneNode(null, new Vector3Df(10, 10, -80), new Vector3Df(-10, 10, -100)); } else { // create problem text GUIFont font = env.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) { env.Skin.SetFont(font); } GUIStaticText text = env.AddStaticText( "Your hardware or this renderer is not able to use the " + "render to texture feature. RTT Disabled.", new Recti(150, 20, 470, 60)); text.OverrideColor = new Color(255, 255, 255, 100); } int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); if (rt != null) { // draw scene into render target // set render target texture driver.SetRenderTarget(rt, ClearBufferFlag.All, new Color(0, 0, 255)); // make cube invisible and set fixed camera as active camera test.Visible = false; smgr.ActiveCamera = fixedCam; // draw whole scene into render buffer smgr.DrawAll(); // set back old render target // The buffer might have been distorted, so clear it driver.SetRenderTarget(null, ClearBufferFlag.All, new Color(0)); // make the cube visible and set the user controlled camera as active one test.Visible = true; smgr.ActiveCamera = fpsCamera; } // draw scene normally smgr.DrawAll(); env.DrawAll(); driver.EndScene(); // display frames per second in window title int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Render to Texture and Specular Highlights example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; IrrlichtCreationParameters p = new IrrlichtCreationParameters(); p.DriverType = DriverType.Direct3D9; p.WindowID = (IntPtr)e.Argument; IrrlichtDevice device = IrrlichtDevice.CreateDevice(p); if (device == null) { // if device cannot be created by any reason - we just leave this thread, // after all IsRedering will report false, so it is all OK. return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; // setup a simple 3d scene CameraSceneNode cam = smgr.AddCameraSceneNode(); cam.Target = new Vector3Df(0); SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 15, 0), 30.0f); cam.AddAnimator(anim); anim.Drop(); SceneNode cube = smgr.AddCubeSceneNode(20); cube.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); cube.SetMaterialTexture(1, driver.GetTexture("../../media/water.jpg")); cube.SetMaterialFlag(MaterialFlag.Lighting, false); cube.SetMaterialType(MaterialType.Reflection2Layer); smgr.AddSkyBoxSceneNode( "../../media/irrlicht2_up.jpg", "../../media/irrlicht2_dn.jpg", "../../media/irrlicht2_lf.jpg", "../../media/irrlicht2_rt.jpg", "../../media/irrlicht2_ft.jpg", "../../media/irrlicht2_bk.jpg"); gui.AddImage( driver.GetTexture("../../media/lime_logo_alpha.png"), new Vector2Di(30, 0)); // draw all while (device.Run()) { driver.BeginScene(false); smgr.DrawAll(); gui.DrawAll(); // draw stats int x = 20; int y = driver.ScreenSize.Height - 50; driver.Draw2DRectangle( new Recti(x, y, x + driver.ScreenSize.Width - 2 * x, y + 30), new IrrlichtLime.Video.Color(0, 0, 0, 128)); device.GUIEnvironment.BuiltInFont.Draw( "Driver: " + driver.Name, new Vector2Di(x + 5, y + 5), new IrrlichtLime.Video.Color(255, 255, 255)); device.GUIEnvironment.BuiltInFont.Draw( "FPS: " + driver.FPS.ToString(), new Vector2Di(x + 5, y + 15), new IrrlichtLime.Video.Color(255, 255, 255)); driver.EndScene(); // check for cancellation if (worker.CancellationPending) { device.Close(); } // check for new command lock (backgroundCommand) { switch (backgroundCommand.Type) { case Command.Kind.Resized: driver.ResizeNotify(backgroundCommand.Value as Dimension2Di); backgroundCommand.Clear(); break; } } } // drop the device device.Drop(); }
static void Main(string[] args) { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(800, 600), 16); if (device == null) { return; } device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.SetWindowResizable(true); device.SetWindowCaption("Irrlicht Engine - Loading..."); VideoDriver driver = device.VideoDriver; GUIEnvironment env = device.GUIEnvironment; SceneManager smgr = device.SceneManager; smgr.Attributes.SetValue(SceneParameters.COLLADA_CreateSceneInstances, true); driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true); smgr.AddLightSceneNode(null, new Vector3Df(200), new Colorf(1.0f, 1.0f, 1.0f), 2000); smgr.AmbientLight = new Colorf(0.3f, 0.3f, 0.3f); // add our media directory as "search path" device.FileSystem.AddFileArchive("../../media/"); // read configuration from xml file // (we use .NET way to do this, since Lime doesn't support native Irrlicht' xml reader) XmlDocument xml = new XmlDocument(); xml.Load("../../media/config.xml"); startUpModelFile = xml.DocumentElement["startUpModel"].Attributes["file"].Value; caption = xml.DocumentElement["messageText"].Attributes["caption"].Value; messageText = xml.DocumentElement["messageText"].InnerText; if (args.Length > 0) { startUpModelFile = args[0]; } // set a nicer font GUIFont font = env.GetFont("fonthaettenschweiler.bmp"); if (font != null) { env.Skin.SetFont(font); } // load the irrlicht engine logo GUIImage img = env.AddImage( driver.GetTexture("irrlichtlogoalpha2.tga"), new Vector2Di(10, driver.ScreenSize.Height - 128)); img.ID = (int)guiID.Logo; // lock the logo's edges to the bottom left corner of the screen img.SetAlignment(GUIAlignment.UpperLeft, GUIAlignment.UpperLeft, GUIAlignment.LowerRight, GUIAlignment.LowerRight); // create menu GUIContextMenu menu = env.AddMenu(); menu.AddItem("File", -1, true, true); menu.AddItem("View", -1, true, true); menu.AddItem("Camera", -1, true, true); menu.AddItem("Help", -1, true, true); GUIContextMenu submenu; submenu = menu.GetSubMenu(0); submenu.AddItem("Open Model File & Texture...", (int)guiID.OpenModel); submenu.AddItem("Set Model Archive...", (int)guiID.SetModelArchive); submenu.AddItem("Load as Octree", (int)guiID.LoadAsOctree); submenu.AddSeparator(); submenu.AddItem("Quit", (int)guiID.Quit); submenu = menu.GetSubMenu(1); submenu.AddItem("sky box visible", (int)guiID.SkyBoxVisible, true, false, true); submenu.AddItem("toggle model debug information", (int)guiID.ToggleDebugInfo, true, true); submenu.AddItem("model material", -1, true, true); submenu = submenu.GetSubMenu(1); submenu.AddItem("Off", (int)guiID.DebugOff); submenu.AddItem("Bounding Box", (int)guiID.DebugBoundingBox); submenu.AddItem("Normals", (int)guiID.DebugNormals); submenu.AddItem("Skeleton", (int)guiID.DebugSkeleton); submenu.AddItem("Wire overlay", (int)guiID.DebugWireOverlay); submenu.AddItem("Half-Transparent", (int)guiID.DebugHalfTransparent); submenu.AddItem("Buffers bounding boxes", (int)guiID.DebugBuffersBoundingBoxes); submenu.AddItem("All", (int)guiID.DebugAll); submenu = menu.GetSubMenu(1).GetSubMenu(2); submenu.AddItem("Solid", (int)guiID.ModelMaterialSolid); submenu.AddItem("Transparent", (int)guiID.ModelMaterialTransparent); submenu.AddItem("Reflection", (int)guiID.ModelMaterialReflection); submenu = menu.GetSubMenu(2); submenu.AddItem("Maya Style", (int)guiID.CameraMaya); submenu.AddItem("First Person", (int)guiID.CameraFirstPerson); submenu = menu.GetSubMenu(3); submenu.AddItem("About", (int)guiID.About); // create toolbar GUIToolBar bar = env.AddToolBar(); Texture image = driver.GetTexture("open.png"); bar.AddButton((int)guiID.ButtonOpenModel, null, "Open a model", image, null, false, true); image = driver.GetTexture("tools.png"); bar.AddButton((int)guiID.ButtonShowToolbox, null, "Open Toolset", image, null, false, true); image = driver.GetTexture("zip.png"); bar.AddButton((int)guiID.ButtonSelectArchive, null, "Set Model Archive", image, null, false, true); image = driver.GetTexture("help.png"); bar.AddButton((int)guiID.ButtonShowAbout, null, "Open Help", image, null, false, true); // create a combobox with some senseless texts GUIComboBox box = env.AddComboBox(new Recti(250, 4, 350, 23), bar, (int)guiID.TextureFilter); box.AddItem("No filtering"); box.AddItem("Bilinear"); box.AddItem("Trilinear"); box.AddItem("Anisotropic"); box.AddItem("Isotropic"); // disable alpha setSkinTransparency(255, env.Skin); // add a tabcontrol createToolBox(); // create fps text GUIStaticText fpstext = env.AddStaticText("", new Recti(400, 4, 570, 23), true, false, bar); GUIStaticText postext = env.AddStaticText("", new Recti(10, 50, 470, 80), false, false, null, (int)guiID.PositionText); postext.Visible = false; // show about message box and load default model if (args.Length == 0) { showAboutText(); } loadModel(startUpModelFile); // add skybox skybox = smgr.AddSkyBoxSceneNode( "irrlicht2_up.jpg", "irrlicht2_dn.jpg", "irrlicht2_lf.jpg", "irrlicht2_rt.jpg", "irrlicht2_ft.jpg", "irrlicht2_bk.jpg"); // add a camera scene node camera[0] = smgr.AddCameraSceneNodeMaya(); camera[0].FarValue = 20000; // Maya cameras reposition themselves relative to their target, // so target the location where the mesh scene node is placed. camera[0].Target = new Vector3Df(0, 30, 0); camera[1] = smgr.AddCameraSceneNodeFPS(); camera[1].FarValue = 20000; camera[1].Position = new Vector3Df(0, 0, -70); camera[1].Target = new Vector3Df(0, 30, 0); setActiveCamera(camera[0]); // set window caption caption = string.Format("{0} - [{1}]", caption, driver.Name); device.SetWindowCaption(caption); // remember state so we notice when the window does lose the focus bool hasFocus = device.WindowFocused; // draw everything while (device.Run() && driver != null) { // Catch focus changes (workaround until Irrlicht has events for this) bool focused = device.WindowFocused; if (hasFocus && !focused) { onKillFocus(); } hasFocus = focused; if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(50, 50, 50)); smgr.DrawAll(); env.DrawAll(); driver.EndScene(); string str = string.Format("FPS: {0} Tris: {1}", driver.FPS, driver.PrimitiveCountDrawn); fpstext.Text = str; CameraSceneNode cam = device.SceneManager.ActiveCamera; str = string.Format("Pos: {0} Tgt: {1}", cam.Position, cam.Target); postext.Text = str; } else { device.Yield(); } } device.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; scene.GUIEnvironment.AddStaticText("Press Space to hide occluder.", new Recti(10, 10, 200, 50)); // Create the node to be occluded. We create a sphere node with high poly count. MeshSceneNode node = scene.AddSphereSceneNode(10, 64); if (node != null) { node.Position = new Vector3Df(0, 0, 60); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); node.SetMaterialFlag(MaterialFlag.Lighting, false); } // Now we create another node, the occluder. It's a simple plane. SceneNode plane = scene.AddMeshSceneNode( scene.AddHillPlaneMesh("plane", new Dimension2Df(10), new Dimension2Di(2)), // mesh null, // parent -1, // id new Vector3Df(0, 0, 20), // position new Vector3Df(270, 0, 0)); // rotation if (plane != null) { plane.SetMaterialTexture(0, driver.GetTexture("../../media/t351sml.jpg")); plane.SetMaterialFlag(MaterialFlag.Lighting, false); plane.SetMaterialFlag(MaterialFlag.BackFaceCulling, true); } // Here we create the occlusion query. Because we don't have a plain mesh scene node // (SceneNodeType.Mesh or SceneNodeType.AnimatedMesh), we pass the base geometry as well. Instead, // we could also pass a simpler mesh or the bounding box. But we will use a time // based method, where the occlusion query renders to the frame buffer and in case // of success (occlusion), the mesh is not drawn for several frames. driver.AddOcclusionQuery(node, node.Mesh); // We have done everything, just a camera and draw it. We also write the // current frames per second and the name of the driver to the caption of the // window to examine the render speedup. // We also store the time for measuring the time since the last occlusion query ran // and store whether the node should be visible in the next frames. scene.AddCameraSceneNode(); uint timeNow = device.Timer.Time; bool nodeVisible = true; while (device.Run()) { plane.Visible = !IsKeyDown(KeyCode.Space); driver.BeginScene(ClearBufferFlag.All, new Color(113, 113, 133)); // First, we draw the scene, possibly without the occluded element. This is necessary // because we need the occluder to be drawn first. You can also use several scene // managers to collect a number of possible occluders in a separately rendered scene. node.Visible = nodeVisible; scene.DrawAll(); scene.GUIEnvironment.DrawAll(); // Once in a while, here every 100 ms, we check the visibility. We run the queries, // update the pixel value, and query the result. Since we already rendered the node // we render the query invisible. The update is made blocking, as we need the result // immediately. If you don't need the result immediately, e.g. because oyu have other // things to render, you can call the update non-blocking. This gives the GPU more // time to pass back the results without flushing the render pipeline. // If the update was called non-blocking, the result from getOcclusionQueryResult is // either the previous value, or 0xffffffff if no value has been generated at all, yet. // The result is taken immediately as visibility flag for the node. if (device.Timer.Time - timeNow > 100) { driver.RunAllOcclusionQueries(false); driver.UpdateAllOcclusionQueries(); nodeVisible = driver.GetOcclusionQueryResult(node) > 0; timeNow = device.Timer.Time; } driver.EndScene(); device.SetWindowCaption(String.Format( "Occlusion Query Example - Irrlicht Engine [{0}] fps: {1} (primitives: {2})", driver.Name, driver.FPS, driver.PrimitiveCountDrawn)); } device.Drop(); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } useHighLevelShaders = AskUserForHighLevelShaders(driverType); if (useHighLevelShaders) { useCgShaders = AskUserForCgShaders(driverType); } device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; string vsFileName = null; // filename for the vertex shader string psFileName = null; // filename for the pixel shader switch (driverType) { case DriverType.Direct3D8: psFileName = "../../media/d3d8.psh"; vsFileName = "../../media/d3d8.vsh"; break; case DriverType.Direct3D9: if (useHighLevelShaders) { // Cg can also handle this syntax 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) { if (useCgShaders) { // Use HLSL syntax for Cg psFileName = "../../media/d3d9.hlsl"; vsFileName = psFileName; // both shaders are in the same file } else { psFileName = "../../media/opengl.frag"; vsFileName = "../../media/opengl.vert"; } } else { psFileName = "../../media/opengl.psh"; vsFileName = "../../media/opengl.vsh"; } break; } if (!driver.QueryFeature(VideoDriverFeature.PixelShader_1_1) && !driver.QueryFeature(VideoDriverFeature.ARB_FragmentProgram_1)) { device.Logger.Log("WARNING: Pixel shaders disabled because of missing driver/hardware support."); } if (!driver.QueryFeature(VideoDriverFeature.VertexShader_1_1) && !driver.QueryFeature(VideoDriverFeature.ARB_VertexProgram_1)) { device.Logger.Log("WARNING: Vertex shaders disabled because of missing driver/hardware support."); } // create materials GPUProgrammingServices gpu = driver.GPUProgrammingServices; MaterialType newMaterialType1 = MaterialType.Solid; MaterialType newMaterialType2 = MaterialType.TransparentAddColor; if (gpu != null) { gpu.OnSetConstants += new GPUProgrammingServices.SetConstantsHandler(gpu_OnSetConstants); // create the shaders depending on if the user wanted high level or low level shaders if (useHighLevelShaders) { GPUShadingLanguage shadingLanguage = useCgShaders ? GPUShadingLanguage.Cg : GPUShadingLanguage.Default; newMaterialType1 = gpu.AddHighLevelShaderMaterialFromFiles( vsFileName, "vertexMain", VertexShaderType.VS_1_1, psFileName, "pixelMain", PixelShaderType.PS_1_1, MaterialType.Solid, 0, shadingLanguage); newMaterialType2 = gpu.AddHighLevelShaderMaterialFromFiles( vsFileName, "vertexMain", VertexShaderType.VS_1_1, psFileName, "pixelMain", PixelShaderType.PS_1_1, MaterialType.TransparentAddColor, 0, shadingLanguage); } else { // create material from low level shaders (asm or arb_asm) newMaterialType1 = gpu.AddShaderMaterialFromFiles(vsFileName, psFileName, MaterialType.Solid); newMaterialType2 = gpu.AddShaderMaterialFromFiles(vsFileName, psFileName, MaterialType.TransparentAddColor); } } if ((int)newMaterialType1 == -1) { newMaterialType1 = MaterialType.Solid; } if ((int)newMaterialType2 == -1) { newMaterialType2 = MaterialType.TransparentAddColor; } // create test scene node 1, with the new created material type 1 SceneNode node = smgr.AddCubeSceneNode(50); node.Position = new Vector3Df(0); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); node.SetMaterialFlag(MaterialFlag.Lighting, false); node.SetMaterialType(newMaterialType1); smgr.AddTextSceneNode(device.GUIEnvironment.BuiltInFont, "PS & VS & EMT_SOLID", new Color(255, 255, 255), node); SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0, 0.3f, 0)); node.AddAnimator(anim); anim.Drop(); // create test scene node 2, with the new created material type 2 node = smgr.AddCubeSceneNode(50); node.Position = new Vector3Df(0, -10, 50); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); node.SetMaterialFlag(MaterialFlag.Lighting, false); node.SetMaterialFlag(MaterialFlag.BlendOperation, true); node.SetMaterialType(newMaterialType2); smgr.AddTextSceneNode(device.GUIEnvironment.BuiltInFont, "PS & VS & EMT_TRANSPARENT", new Color(255, 255, 255), node); anim = smgr.CreateRotationAnimator(new Vector3Df(0, 0.3f, 0)); node.AddAnimator(anim); anim.Drop(); // create test scene node 3, with no shader node = smgr.AddCubeSceneNode(50); node.Position = new Vector3Df(0, 50, 25); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); node.SetMaterialFlag(MaterialFlag.Lighting, false); smgr.AddTextSceneNode(device.GUIEnvironment.BuiltInFont, "NO SHADER", new Color(255, 255, 255), node); // add a nice skybox driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, false); SceneNode skybox = smgr.AddSkyBoxSceneNode( "../../media/irrlicht2_up.jpg", "../../media/irrlicht2_dn.jpg", "../../media/irrlicht2_lf.jpg", "../../media/irrlicht2_rt.jpg", "../../media/irrlicht2_ft.jpg", "../../media/irrlicht2_bk.jpg"); driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, true); // add a camera and disable the mouse cursor CameraSceneNode cam = smgr.AddCameraSceneNodeFPS(); cam.Position = new Vector3Df(-100, 50, 100); cam.Target = new Vector3Df(0); device.CursorControl.Visible = false; // draw everything int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(true, true, new Color(0)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Vertex and pixel shader example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 768), 32, false, true); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.SetWindowCaption("Minesweeper - Irrlicht Engine"); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; device.FileSystem.AddFileArchive("../../media/minesweeper.media.files"); game = new Game(device); // set up camera camera = scene.AddCameraSceneNode(); // Maya(null, -500, 50, 200); setupCameraPositionAndTarget(); // set up background Mesh m = scene.GetMesh("back.obj"); scene.MeshManipulator.Scale(m, new Vector3Df(80)); scene.MeshManipulator.FlipSurfaces(m); scene.MeshManipulator.RecalculateNormals(m); scene.MeshManipulator.SetVertexColors(m, new Color(80, 80, 80)); Material t = new Material(); t.Type = MaterialType.Reflection2Layer; t.Lighting = false; t.SetTexture(0, device.VideoDriver.GetTexture("TEXTURE-ref.jpg")); t.SetTexture(1, device.VideoDriver.GetTexture("TEXTURE-ref.jpg")); MeshSceneNode n = scene.AddMeshSceneNode(m, null, 7777); n.SetMaterial(0, t); n.Position = game.CenterOfTheBoard; SceneNodeAnimator a = scene.CreateRotationAnimator(new Vector3Df(0.07f, 0.01f, 0.05f)); n.AddAnimator(a); a.Drop(); // set up light light = scene.AddLightSceneNode(null, game.CenterOfTheBoard, new Colorf(1, 1, 1), 200); m = scene.AddVolumeLightMesh("lvol1", 32, 32, new Color(5, 5, 5)); scene.MeshManipulator.Scale(m, new Vector3Df(15, 30, 15)); n = scene.AddMeshSceneNode(m, light); n.Position = new Vector3Df(0, -10, 0); n.Rotation = new Vector3Df(180, 0, 0); n.SetMaterialType(MaterialType.TransparentAddColor); m = scene.AddVolumeLightMesh("lvol2", 32, 32, new Color(5, 5, 5)); scene.MeshManipulator.Scale(m, new Vector3Df(15, 30, 15)); n = scene.AddMeshSceneNode(m, light); n.Position = new Vector3Df(0, -10, 0); n.SetMaterialType(MaterialType.TransparentAddColor); // add gui hint text = gui.AddStaticText(TextStart, new Recti(10, 10, 200, 40)); text.OverrideColor = Color.OpaqueYellow; // main loop while (device.Run()) { driver.BeginScene(); scene.DrawAll(); gui.DrawAll(); if (optionFPS) gui.BuiltInFont.Draw(driver.FPS + " FPS", driver.ScreenSize.Width - 50, 10, Color.OpaqueWhite); driver.EndScene(); } device.Drop(); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(512, 384)); if (device == null) { return; } device.SetWindowCaption("Irrlicht Engine - 2D Graphics Demo"); VideoDriver driver = device.VideoDriver; Texture images = driver.GetTexture("../../media/2ddemo.png"); driver.MakeColorKeyTexture(images, new Vector2Di(0, 0)); GUIFont font = device.GUIEnvironment.BuiltInFont; GUIFont font2 = device.GUIEnvironment.GetFont("../../media/fonthaettenschweiler.bmp"); Recti imp1 = new Recti(349, 15, 385, 78); Recti imp2 = new Recti(387, 15, 423, 78); driver.Material2D.Layer[0].BilinearFilter = true; driver.Material2D.AntiAliasing = AntiAliasingMode.FullBasic; while (device.Run()) { if (device.WindowActive) { int time = (int)device.Timer.Time; driver.BeginScene(true, true, new Color(120, 102, 136)); // draw fire & dragons background world driver.Draw2DImage(images, new Vector2Di(50, 50), new Recti(0, 0, 342, 224), null, new Color(255, 255, 255), true); // draw flying imp driver.Draw2DImage(images, new Vector2Di(164, 125), (time / 500 % 2) == 1 ? imp1 : imp2, null, new Color(255, 255, 255), true); // draw second flying imp with colorcylce driver.Draw2DImage(images, new Vector2Di(270, 105), (time / 500 % 2) == 1 ? imp1 : imp2, null, new Color(time % 255, 255, 255), true); // draw some text if (font != null) { font.Draw("This demo shows that Irrlicht is also capable of drawing 2D graphics.", 130, 10, new Color(255, 255, 255)); } // draw some other text if (font2 != null) { font2.Draw("Also mixing with 3d graphics is possible.", 130, 20, new Color(time % 255, time % 255, 255)); } driver.EnableMaterial2D(); driver.Draw2DImage(images, new Recti(10, 10, 108, 48), new Recti(354, 87, 442, 118)); driver.EnableMaterial2D(false); Vector2Di m = device.CursorControl.Position; driver.Draw2DRectangle(new Recti(m.X - 20, m.Y - 20, m.X + 20, m.Y + 20), new Color(255, 255, 255, 100)); driver.EndScene(); } } device.Drop(); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; // load the scene if (args.Length > 0) { smgr.LoadScene(args[0]); } else { smgr.LoadScene("../../media/example.irr"); } CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(null, 50, 0.1f); // create a meta triangle selector to hold several triangle selectors MetaTriangleSelector meta = smgr.CreateMetaTriangleSelector(); List <SceneNode> nodes = smgr.GetSceneNodesFromType(SceneNodeType.Any); // find all nodes foreach (SceneNode n in nodes) { TriangleSelector selector = null; switch (n.Type) { case SceneNodeType.Cube: case SceneNodeType.AnimatedMesh: // because the selector won't animate with the mesh, // and is only being used for camera collision, we'll just use an approximate // bounding box instead of "(node as AnimatedMeshSceneNode).GetMesh(0)" selector = smgr.CreateTriangleSelectorFromBoundingBox(n); break; case SceneNodeType.Mesh: case SceneNodeType.Sphere: // derived from MeshSceneNode selector = smgr.CreateTriangleSelector((n as MeshSceneNode).Mesh, n); break; case SceneNodeType.Terrain: selector = smgr.CreateTerrainTriangleSelector(n as TerrainSceneNode); break; case SceneNodeType.Octree: selector = smgr.CreateOctreeTriangleSelector((n as MeshSceneNode).Mesh, n); break; } if (selector != null) { // add it to the meta selector, which will take a reference to it meta.AddTriangleSelector(selector); // and drop my reference to it, so that the meta selector owns it selector.Drop(); } } SceneNodeAnimator anim = smgr.CreateCollisionResponseAnimator(meta, camera, new Vector3Df(5), new Vector3Df(0)); meta.Drop(); // i'm done with the meta selector now camera.AddAnimator(anim); anim.Drop(); // i'm done with the animator now // and set the camera position so that it doesn't start off stuck in the geometry camera.Position = new Vector3Df(0, 20, 0); // point the camera at the cube node, by finding the first node of type SceneNodeType.Cube SceneNode cube = smgr.GetSceneNodeFromType(SceneNodeType.Cube); if (cube != null) { camera.Target = cube.AbsolutePosition; } int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(true, true, new Color(200, 200, 200)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Load Irrlicht File example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main() { bool shadows = AskForRealtimeShadows(); DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480), 16, false, shadows); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; AnimatedMesh mesh = smgr.GetMesh("../../media/room.3ds"); smgr.MeshManipulator.MakePlanarTextureMapping(mesh.GetMesh(0), 0.004f); SceneNode node = smgr.AddAnimatedMeshSceneNode(mesh); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.jpg")); node.GetMaterial(0).SpecularColor = new Color(0); mesh = smgr.AddHillPlaneMesh("myHill", new Dimension2Df(20, 20), new Dimension2Di(40, 40), null, 0, new Dimension2Df(0), new Dimension2Df(10, 10)); node = smgr.AddWaterSurfaceSceneNode(mesh.GetMesh(0), 3.0f, 300.0f, 30.0f); node.Position = new Vector3Df(0, 7, 0); node.SetMaterialTexture(0, driver.GetTexture("../../media/stones.jpg")); node.SetMaterialTexture(1, driver.GetTexture("../../media/water.jpg")); node.SetMaterialType(MaterialType.Reflection2Layer); // create light node = smgr.AddLightSceneNode(null, new Vector3Df(0), new Colorf(1.0f, 0.6f, 0.7f, 1.0f), 800); SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 250); node.AddAnimator(anim); anim.Drop(); // attach billboard to light node = smgr.AddBillboardSceneNode(node, new Dimension2Df(50, 50)); node.SetMaterialFlag(MaterialFlag.Lighting, false); node.SetMaterialType(MaterialType.TransparentAddColor); node.SetMaterialTexture(0, driver.GetTexture("../../media/particlewhite.bmp")); // create a particle system ParticleSystemSceneNode ps = smgr.AddParticleSystemSceneNode(false); if (ps != null) { ParticleEmitter em = ps.CreateBoxEmitter( new AABBox(-7, 0, -7, 7, 1, 7), // emitter size new Vector3Df(0.0f, 0.06f, 0.0f), // initial direction 80, 100, // emit rate new Color(255, 255, 255, 0), // darkest color new Color(255, 255, 255, 0), // brightest color 800, 2000, 0, // min and max age, angle new Dimension2Df(10.0f), // min size new Dimension2Df(20.0f)); // max size ps.Emitter = em; // this grabs the emitter em.Drop(); // so we can drop it here without deleting it ParticleAffector paf = ps.CreateFadeOutParticleAffector(); ps.AddAffector(paf); // same goes for the affector paf.Drop(); ps.Position = new Vector3Df(-70, 60, 40); ps.Scale = new Vector3Df(2); ps.SetMaterialFlag(MaterialFlag.Lighting, false); ps.SetMaterialFlag(MaterialFlag.ZWrite, false); ps.SetMaterialTexture(0, driver.GetTexture("../../media/fire.bmp")); ps.SetMaterialType(MaterialType.TransparentAddColor); } VolumeLightSceneNode n = smgr.AddVolumeLightSceneNode(null, -1, 32, // Subdivisions on U axis 32, // Subdivisions on V axis new Color(255, 255, 255, 0), // foot color new Color(0, 0, 0, 0)); // tail color if (n != null) { n.Scale = new Vector3Df(56); n.Position = new Vector3Df(-120, 50, 40); // load textures for animation List <Texture> textures = new List <Texture>(); for (int i = 7; i > 0; i--) { string s = string.Format("../../media/portal{0}.bmp", i); textures.Add(driver.GetTexture(s)); } // create texture animator SceneNodeAnimator glow = smgr.CreateTextureAnimator(textures, 0.150f); // add the animator n.AddAnimator(glow); // drop the animator because it was created with a create() function glow.Drop(); } // add animated character mesh = smgr.GetMesh("../../media/dwarf.x"); AnimatedMeshSceneNode anode = smgr.AddAnimatedMeshSceneNode(mesh); anode.Position = new Vector3Df(-50, 20, -60); anode.AnimationSpeed = 15; // add shadow anode.AddShadowVolumeSceneNode(); smgr.ShadowColor = new Color(0, 0, 0, 150); // make the model a little bit bigger and normalize its normals // because of the scaling, for correct lighting anode.Scale = new Vector3Df(2); anode.SetMaterialFlag(MaterialFlag.NormalizeNormals, true); CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(); camera.Position = new Vector3Df(-50, 50, -150); // disable mouse cursor device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "SpecialFX example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main(string[] args) { DriverType driverType; Console.Write("Please select the driver you want for this example:\n" + " (a) OpenGL\n (b) Direct3D 9.0c\n (c) Direct3D 8.1\n" + " (d) Burning's Software Renderer\n (e) Software Renderer\n" + " (f) NullDevice\n (otherKey) exit\n\n"); ConsoleKeyInfo i = Console.ReadKey(); switch (i.Key) { case ConsoleKey.A: driverType = DriverType.OpenGL; break; case ConsoleKey.B: driverType = DriverType.Direct3D9; break; case ConsoleKey.C: driverType = DriverType.Direct3D8; break; case ConsoleKey.D: driverType = DriverType.BurningsVideo; break; case ConsoleKey.E: driverType = DriverType.Software; break; case ConsoleKey.F: driverType = DriverType.Null; break; default: return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh mesh = smgr.GetMesh("20kdm2.bsp"); SceneNode node = null; if (mesh != null) { node = smgr.AddOctreeSceneNode(mesh.GetMesh(0), null, -1, 1024); } if (node != null) { node.Position = new Vector3Df(-1300, -144, -1249); } smgr.AddCameraSceneNodeFPS(); device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(true, true, new Color(200, 200, 200)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Quake 3 Map Example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main(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(); }
private static float _playerVerticalSpeed = 0.0f; // used to calculate vertical speed for gravity and jump static void Main(string[] args) { IrrlichtDevice device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(ResolutionX, ResolutionY), 24, false, false, false); device.OnEvent += Device_OnEvent; 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 sydneyNode = smgr.AddAnimatedMeshSceneNode(mesh); var cubeSceneNode = smgr.AddCubeSceneNode(2.0f); cubeSceneNode.Scale = new Vector3Df(6.0f, 2.0f, 100.0f); cubeSceneNode.Position = new Vector3Df(cubeSceneNode.Position.X, GroundAltitude + 0.5f, cubeSceneNode.Position.Z); if (sydneyNode != null) { sydneyNode.SetMaterialFlag(MaterialFlag.Lighting, true); sydneyNode.SetMD2Animation(AnimationTypeMD2.Stand); sydneyNode.SetMaterialTexture(0, driver.GetTexture("../../media/sydney.bmp")); } var lightSceneNode = smgr.AddLightSceneNode(); var light = lightSceneNode.LightData; light.DiffuseColor = new Colorf(0.8f, 1.0f, 1.0f); light.Type = LightType.Directional; light.Position = new Vector3Df(0.0f, 5.0f, 5.0f); var cam = smgr.AddCameraSceneNode(null, new Vector3Df(20, 30, -40), new Vector3Df(20, 5, 0)); device.Timer.Start(); uint then = device.Timer.RealTime; while (device.Run()) { // As the game is simple we will handle our simple physics ourselves uint now = device.Timer.RealTime; uint elapsed = now - then; float elapsedTimeSec = (float)elapsed / 1000.0f; then = now; // we target 58.8 FPS if (elapsed < 17) { device.Sleep(17 - (int)elapsed); } else { // uh-oh, it took more than .125 sec to do render loop! // what do we do now? } _playerVerticalSpeed += elapsedTimeSec * -(VerticalGravity * 10.0f); var calculatedNewPos = sydneyNode.Position - new Vector3Df(0.0f, _playerVerticalSpeed * elapsedTimeSec, 0.0f); float offsetSydney = sydneyNode.BoundingBox.Extent.Y / 2.0f; _isGrounded = calculatedNewPos.Y <= (GroundAltitude + offsetSydney); if (_isGrounded) { _playerVerticalSpeed = 0.0f; calculatedNewPos.Y = GroundAltitude + offsetSydney; } else { calculatedNewPos.Y = calculatedNewPos.Y; } sydneyNode.Position = calculatedNewPos; driver.BeginScene(true, true, new Color(100, 101, 140)); smgr.DrawAll(); gui.DrawAll(); driver.EndScene(); } device.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment env = device.GUIEnvironment; driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true); // add irrlicht logo env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10)); // add camera CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(); camera.Position = new Vector3Df(-200, 200, -200); // disable mouse cursor device.CursorControl.Visible = false; driver.Fog = new Fog(new Color(138, 125, 81, 0), FogType.Linear, 250, 1000, 0.003f, true, false); AnimatedMesh roomMesh = smgr.GetMesh("../../media/room.3ds"); SceneNode room = null; SceneNode earth = null; if (roomMesh != null) { // the room mesh doesn't have proper texture mapping on the floor, // so we can recreate them on runtime smgr.MeshManipulator.MakePlanarTextureMapping(roomMesh.GetMesh(0), 0.003f); Texture normalMap = driver.GetTexture("../../media/rockwall_height.bmp"); if (normalMap != null) { driver.MakeNormalMapTexture(normalMap, 9.0f); } Mesh tangentMesh = smgr.MeshManipulator.CreateMeshWithTangents(roomMesh.GetMesh(0)); room = smgr.AddMeshSceneNode(tangentMesh); room.SetMaterialTexture(0, driver.GetTexture("../../media/rockwall.jpg")); room.SetMaterialTexture(1, normalMap); room.GetMaterial(0).SpecularColor = new Color(0); room.GetMaterial(0).Shininess = 0.0f; room.SetMaterialFlag(MaterialFlag.Fog, true); room.SetMaterialType(MaterialType.ParallaxMapSolid); room.GetMaterial(0).MaterialTypeParam = 1.0f / 64.0f; // adjust height for parallax effect tangentMesh.Drop(); // drop mesh because we created it with a "create" call } // add earth sphere AnimatedMesh earthMesh = smgr.GetMesh("../../media/earth.x"); if (earthMesh != null) { // perform various task with the mesh manipulator MeshManipulator manipulator = smgr.MeshManipulator; // create mesh copy with tangent informations from original earth.x mesh Mesh tangentSphereMesh = manipulator.CreateMeshWithTangents(earthMesh.GetMesh(0)); // set the alpha value of all vertices to 200 manipulator.SetVertexColorAlpha(tangentSphereMesh, 200); // scale the mesh by factor 50 Matrix m = new Matrix(); m.Scale = new Vector3Df(50); manipulator.Transform(tangentSphereMesh, m); earth = smgr.AddMeshSceneNode(tangentSphereMesh); earth.Position = new Vector3Df(-70, 130, 45); // load heightmap, create normal map from it and set it Texture earthNormalMap = driver.GetTexture("../../media/earthbump.jpg"); if (earthNormalMap != null) { driver.MakeNormalMapTexture(earthNormalMap, 20); earth.SetMaterialTexture(1, earthNormalMap); earth.SetMaterialType(MaterialType.NormalMapTransparentVertexAlpha); } // adjust material settings earth.SetMaterialFlag(MaterialFlag.Fog, true); // add rotation animator SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0, 0.1f, 0)); earth.AddAnimator(anim); anim.Drop(); // drop mesh because we created it with a "create" call. tangentSphereMesh.Drop(); } // add light 1 (more green) LightSceneNode light1 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(0.5f, 1.0f, 0.5f, 0.0f), 800); if (light1 != null) { light1.DebugDataVisible = DebugSceneType.BBox; // add fly circle animator to light SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(50, 300, 0), 190.0f, -0.003f); light1.AddAnimator(anim); anim.Drop(); // attach billboard to the light BillboardSceneNode bill = smgr.AddBillboardSceneNode(light1, new Dimension2Df(60, 60)); bill.SetMaterialFlag(MaterialFlag.Lighting, false); bill.SetMaterialFlag(MaterialFlag.ZWrite, false); bill.SetMaterialType(MaterialType.TransparentAddColor); bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlegreen.jpg")); } // add light 2 (red) SceneNode light2 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(1.0f, 0.2f, 0.2f, 0.0f), 800.0f); if (light2 != null) { // add fly circle animator to light SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 200.0f, 0.001f, new Vector3Df(0.2f, 0.9f, 0.0f)); light2.AddAnimator(anim); anim.Drop(); // attach billboard to light SceneNode bill = smgr.AddBillboardSceneNode(light2, new Dimension2Df(120, 120)); bill.SetMaterialFlag(MaterialFlag.Lighting, false); bill.SetMaterialFlag(MaterialFlag.ZWrite, false); bill.SetMaterialType(MaterialType.TransparentAddColor); bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlered.bmp")); // add particle system ParticleSystemSceneNode ps = smgr.AddParticleSystemSceneNode(false, light2); // create and set emitter ParticleEmitter em = ps.CreateBoxEmitter( new AABBox(-3, 0, -3, 3, 1, 3), new Vector3Df(0.0f, 0.03f, 0.0f), 80, 100, new Color(255, 255, 255, 10), new Color(255, 255, 255, 10), 400, 1100); em.MinStartSize = new Dimension2Df(30.0f, 40.0f); em.MaxStartSize = new Dimension2Df(30.0f, 40.0f); ps.Emitter = em; em.Drop(); // create and set affector ParticleAffector paf = ps.CreateFadeOutParticleAffector(); ps.AddAffector(paf); paf.Drop(); // adjust some material settings ps.SetMaterialFlag(MaterialFlag.Lighting, false); ps.SetMaterialFlag(MaterialFlag.ZWrite, false); ps.SetMaterialTexture(0, driver.GetTexture("../../media/fireball.bmp")); ps.SetMaterialType(MaterialType.TransparentAddColor); } MyEventReceiver receiver = new MyEventReceiver(device, room, earth); int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); smgr.DrawAll(); env.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Per pixel lighting example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
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(); }
private void backgroundRendering_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; //DeviceSettings settings = e.Argument as DeviceSettings; // create irrlicht device using provided settings if (panelRenderWindow.IsDisposed) { throw new Exception("Form closed!"); } DeviceSettings s = new DeviceSettings( IntPtr.Zero, DriverType.Direct3D9, 0, //antialias new Color(100, 101, 140), false); if (panelRenderWindow.InvokeRequired) { panelRenderWindow.Invoke(new MethodInvoker(delegate { s.WindowID = panelRenderWindow.Handle; })); } dev = IrrlichtDevice.CreateDevice(s); if (dev == null) { throw new NullReferenceException("Could not create device for engine!"); } dev.OnEvent += new IrrlichtDevice.EventHandler(this.device_OnEvent); dev.Logger.LogLevel = LogLevel.Warning; drv = dev.VideoDriver; smgr = dev.SceneManager; gui = dev.GUIEnvironment; _ = smgr.FileSystem.AddFileArchive(activeMod.FileDirectory); smgr.Attributes.AddValue("TW_TW3_LOAD_SKEL", true); smgr.Attributes.AddValue("TW_TW3_LOAD_BEST_LOD_ONLY", true); // added by vl if (meshFile != null && meshFile.Length > 0) { mesh = smgr.GetMesh(meshFile); } if (mesh == null) { throw new Exception("Failed to load mesh."); } mesh.Grab(); smgr.MeshManipulator.RecalculateNormals(mesh); meshLoaded = true; float scaleMul = 1.0f; node = smgr.AddAnimatedMeshSceneNode(mesh); helper = smgr.GetMeshLoader(smgr.MeshLoaderCount - 1).getMeshLoaderHelper(); // hacked to gat witcher3 loader if (node != null && meshLoaded) { node.Scale = new Vector3Df(3.0f); node.SetMaterialFlag(MaterialFlag.Lighting, false); scaleMul = node.BoundingBox.Radius / 4; if (!string.IsNullOrEmpty(rigFile)) { meshToAnimate = helper.loadRig(rigFile, mesh); if (meshToAnimate == null) { throw new Exception("Failed to load rig."); } else { meshToAnimate.Grab(); rigLoaded = true; Logger.LogString("Rig loaded!", Logtype.Success); node.Mesh = meshToAnimate; } } if (!string.IsNullOrEmpty(animFile) && rigLoaded) { animList = helper.loadAnimation(animFile, meshToAnimate); if (animList.Count > 0) { animLoaded = true; Logger.LogString($"{animList.Count} animations loaded! Select animation to play", Logtype.Success); } else { Logger.LogString("No animations loaded!", Logtype.Important); } } setMaterialsSettings(node); } var camera = smgr.AddCameraSceneNode(null, new Vector3Df(node.BoundingBox.Radius * 8, node.BoundingBox.Radius, 0), new Vector3Df(0, node.BoundingBox.Radius, 0)); camera.NearValue = 0.001f; camera.FOV = 45.0f * 3.14f / 180.0f; var animText = activeAnim; var mAnimText = gui.AddStaticText(animText, new Recti(0, this.ClientSize.Height - 80, 100, this.ClientSize.Height - 70)); var mPositionText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 70, 100, this.ClientSize.Height - 60)); var mRotationText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 60, 100, this.ClientSize.Height - 50)); var fpsText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 50, 100, this.ClientSize.Height - 40)); var infoText = gui.AddStaticText("[Space] - Reset\n[LMouse] - Rotate\n[MMouse] - Move\n[Wheel] - Zoom", new Recti(0, this.ClientSize.Height - 40, 100, this.ClientSize.Height)); mAnimText.OverrideColor = mPositionText.OverrideColor = mRotationText.OverrideColor = fpsText.OverrideColor = infoText.OverrideColor = new Color(255, 255, 255); mAnimText.BackgroundColor = mPositionText.BackgroundColor = mRotationText.BackgroundColor = fpsText.BackgroundColor = infoText.BackgroundColor = new Color(0, 0, 0); viewPort = drv.ViewPort; var lineMat = new Material { Lighting = false }; while (dev.Run()) { drv.ViewPort = viewPort; drv.BeginScene(ClearBufferFlag.Depth | ClearBufferFlag.Color, s.BackColor); node.Position = modelPosition; node.Rotation = modelAngle; //update info box mPositionText.Text = $"X: {modelPosition.X.ToString("F2")} Y: {modelPosition.Y.ToString("F2")} Z: {modelPosition.Z.ToString("F2")}"; mRotationText.Text = $"Yaw: {modelAngle.Y.ToString("F2")} Roll: {modelAngle.Z.ToString("F2")}"; fpsText.Text = $"FPS: {drv.FPS}"; smgr.DrawAll(); gui.DrawAll(); // draw xyz axis right bottom drv.ViewPort = new Recti(this.ClientSize.Width - 100, this.ClientSize.Height - 80, this.ClientSize.Width, this.ClientSize.Height); drv.SetMaterial(lineMat); var matrix = new Matrix(new Vector3Df(0, 0, 0), modelAngle); drv.SetTransform(TransformationState.World, matrix); matrix = matrix.BuildProjectionMatrixOrthoLH(100, 80, camera.NearValue, camera.FarValue); drv.SetTransform(TransformationState.Projection, matrix); matrix = matrix.BuildCameraLookAtMatrixLH(new Vector3Df(50, 0, 0), new Vector3Df(0, 0, 0), new Vector3Df(0, 1f, 0)); drv.SetTransform(TransformationState.View, matrix); drv.Draw3DLine(0, 0, 0, 30f, 0, 0, Color.SolidGreen); drv.Draw3DLine(0, 0, 0, 0, 30f, 0, Color.SolidBlue); drv.Draw3DLine(0, 0, 0, 0, 0, 30f, Color.SolidRed); drv.EndScene(); // if we requested to stop, we close the device if (worker.CancellationPending) { dev.Close(); } } // drop device dev.Drop(); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) return; useHighLevelShaders = AskUserForHighLevelShaders(driverType); if (useHighLevelShaders) useCgShaders = AskUserForCgShaders(driverType); device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) return; VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; string vsFileName = null; // filename for the vertex shader string psFileName = null; // filename for the pixel shader switch (driverType) { case DriverType.Direct3D8: psFileName = "../../media/d3d8.psh"; vsFileName = "../../media/d3d8.vsh"; break; case DriverType.Direct3D9: if (useHighLevelShaders) { // Cg can also handle this syntax 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) { if (useCgShaders) { // Use HLSL syntax for Cg psFileName = "../../media/d3d9.hlsl"; vsFileName = psFileName; // both shaders are in the same file } else { psFileName = "../../media/opengl.frag"; vsFileName = "../../media/opengl.vert"; } } else { psFileName = "../../media/opengl.psh"; vsFileName = "../../media/opengl.vsh"; } break; } if (!driver.QueryFeature(VideoDriverFeature.PixelShader_1_1) && !driver.QueryFeature(VideoDriverFeature.ARB_FragmentProgram_1)) device.Logger.Log("WARNING: Pixel shaders disabled because of missing driver/hardware support."); if (!driver.QueryFeature(VideoDriverFeature.VertexShader_1_1) && !driver.QueryFeature(VideoDriverFeature.ARB_VertexProgram_1)) device.Logger.Log("WARNING: Vertex shaders disabled because of missing driver/hardware support."); // create materials GPUProgrammingServices gpu = driver.GPUProgrammingServices; MaterialType newMaterialType1 = MaterialType.Solid; MaterialType newMaterialType2 = MaterialType.TransparentAddColor; if (gpu != null) { gpu.OnSetConstants += new GPUProgrammingServices.SetConstantsHandler(gpu_OnSetConstants); // create the shaders depending on if the user wanted high level or low level shaders if (useHighLevelShaders) { GPUShadingLanguage shadingLanguage = useCgShaders ? GPUShadingLanguage.Cg : GPUShadingLanguage.Default; newMaterialType1 = gpu.AddHighLevelShaderMaterialFromFiles( vsFileName, "vertexMain", VertexShaderType.VS_1_1, psFileName, "pixelMain", PixelShaderType.PS_1_1, MaterialType.Solid, 0, shadingLanguage); newMaterialType2 = gpu.AddHighLevelShaderMaterialFromFiles( vsFileName, "vertexMain", VertexShaderType.VS_1_1, psFileName, "pixelMain", PixelShaderType.PS_1_1, MaterialType.TransparentAddColor, 0, shadingLanguage); } else { // create material from low level shaders (asm or arb_asm) newMaterialType1 = gpu.AddShaderMaterialFromFiles(vsFileName, psFileName, MaterialType.Solid); newMaterialType2 = gpu.AddShaderMaterialFromFiles(vsFileName, psFileName, MaterialType.TransparentAddColor); } } if ((int)newMaterialType1 == -1) newMaterialType1 = MaterialType.Solid; if ((int)newMaterialType2 == -1) newMaterialType2 = MaterialType.TransparentAddColor; // create test scene node 1, with the new created material type 1 SceneNode node = smgr.AddCubeSceneNode(50); node.Position = new Vector3Df(0); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); node.SetMaterialFlag(MaterialFlag.Lighting, false); node.SetMaterialType(newMaterialType1); smgr.AddTextSceneNode(device.GUIEnvironment.BuiltInFont, "PS & VS & EMT_SOLID", new Color(255, 255, 255), node); SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0, 0.3f, 0)); node.AddAnimator(anim); anim.Drop(); // create test scene node 2, with the new created material type 2 node = smgr.AddCubeSceneNode(50); node.Position = new Vector3Df(0, -10, 50); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); node.SetMaterialFlag(MaterialFlag.Lighting, false); node.SetMaterialFlag(MaterialFlag.BlendOperation, true); node.SetMaterialType(newMaterialType2); smgr.AddTextSceneNode(device.GUIEnvironment.BuiltInFont, "PS & VS & EMT_TRANSPARENT", new Color(255, 255, 255), node); anim = smgr.CreateRotationAnimator(new Vector3Df(0, 0.3f, 0)); node.AddAnimator(anim); anim.Drop(); // create test scene node 3, with no shader node = smgr.AddCubeSceneNode(50); node.Position = new Vector3Df(0, 50, 25); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); node.SetMaterialFlag(MaterialFlag.Lighting, false); smgr.AddTextSceneNode(device.GUIEnvironment.BuiltInFont, "NO SHADER", new Color(255, 255, 255), node); // add a nice skybox driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, false); SceneNode skybox = smgr.AddSkyBoxSceneNode( "../../media/irrlicht2_up.jpg", "../../media/irrlicht2_dn.jpg", "../../media/irrlicht2_lf.jpg", "../../media/irrlicht2_rt.jpg", "../../media/irrlicht2_ft.jpg", "../../media/irrlicht2_bk.jpg"); driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, true); // add a camera and disable the mouse cursor CameraSceneNode cam = smgr.AddCameraSceneNodeFPS(); cam.Position = new Vector3Df(-100, 50, 100); cam.Target = new Vector3Df(0); device.CursorControl.Visible = false; // draw everything int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(true, true, new Color(0)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Vertex and pixel shader example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } 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(); }
static void Main() { device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 768), 32, false, true); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.SetWindowCaption("Minesweeper - Irrlicht Engine"); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; device.FileSystem.AddFileArchive("../../media/minesweeper.media.files"); game = new Game(device); // set up camera camera = scene.AddCameraSceneNode(); // Maya(null, -500, 50, 200); setupCameraPositionAndTarget(); // set up background Mesh m = scene.GetMesh("back.obj"); scene.MeshManipulator.Scale(m, new Vector3Df(80)); scene.MeshManipulator.FlipSurfaces(m); scene.MeshManipulator.RecalculateNormals(m); scene.MeshManipulator.SetVertexColors(m, new Color(80, 80, 80)); Material t = new Material(); t.Type = MaterialType.Reflection2Layer; t.Lighting = false; t.SetTexture(0, device.VideoDriver.GetTexture("TEXTURE-ref.jpg")); t.SetTexture(1, device.VideoDriver.GetTexture("TEXTURE-ref.jpg")); MeshSceneNode n = scene.AddMeshSceneNode(m, null, 7777); n.SetMaterial(0, t); n.Position = game.CenterOfTheBoard; SceneNodeAnimator a = scene.CreateRotationAnimator(new Vector3Df(0.07f, 0.01f, 0.05f)); n.AddAnimator(a); a.Drop(); // set up light light = scene.AddLightSceneNode(null, game.CenterOfTheBoard, new Colorf(1, 1, 1), 200); m = scene.AddVolumeLightMesh("lvol1", 32, 32, new Color(5, 5, 5)); scene.MeshManipulator.Scale(m, new Vector3Df(15, 30, 15)); n = scene.AddMeshSceneNode(m, light); n.Position = new Vector3Df(0, -10, 0); n.Rotation = new Vector3Df(180, 0, 0); n.SetMaterialType(MaterialType.TransparentAddColor); m = scene.AddVolumeLightMesh("lvol2", 32, 32, new Color(5, 5, 5)); scene.MeshManipulator.Scale(m, new Vector3Df(15, 30, 15)); n = scene.AddMeshSceneNode(m, light); n.Position = new Vector3Df(0, -10, 0); n.SetMaterialType(MaterialType.TransparentAddColor); // add gui hint text = gui.AddStaticText(TextStart, new Recti(10, 10, 200, 40)); text.OverrideColor = Color.SolidYellow; // main loop while (device.Run()) { driver.BeginScene(); scene.DrawAll(); gui.DrawAll(); if (optionFPS) { gui.BuiltInFont.Draw(driver.FPS + " FPS", driver.ScreenSize.Width - 50, 10, Color.SolidWhite); } driver.EndScene(); } device.Drop(); }
static void Main(string[] args) { checkBulletSharpDllPresence(); // setup Irrlicht device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1024, 768)); if (device == null) return; device.SetWindowCaption("BulletSharp Test - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); CameraSceneNode camera = scene.AddCameraSceneNodeFPS(); camera.Position = new Vector3Df(100, 800, -1000); camera.Target = new Vector3Df(0, 100, 0); camera.FarValue = 30000; camera.AutomaticCulling = CullingType.FrustumBox; device.CursorControl.Visible = false; // setup physics physics = new Physics(); physics.Setup(new Vector3Df(0, -worldGravity, 0)); // setup particles particles = new Particles(device); // load quake level device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); Mesh mesh = scene.GetMesh("20kdm2.bsp").GetMesh(0); SceneNode quakeLevel = scene.AddOctreeSceneNode(mesh, null, -1, 1024); quakeLevel.Position = new Vector3Df(-1300, -144, -1249); physics.AddShape(Physics.Shape.Mesh, quakeLevel); // generate dynamic objects for (int i = 0; i < 3; i++) { for (int j = 0; j < 30; j++) { for (int k = 0; k < 3; k++) { MeshSceneNode n = scene.AddCubeSceneNode(cubeSize); n.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); n.SetMaterialFlag(MaterialFlag.Lighting, false); n.Position = new Vector3Df(70 + i * cubeSize, 520 + j * cubeSize, -650 + k * cubeSize); physics.AddShape(Physics.Shape.Box, n, cubeMass); } } } // main loop uint curTime = 0; uint lastTime = 0; int simFps = 0; int simFrames = 0; uint simFramesTime = 0; while (device.Run()) { if (device.WindowActive) { // simulate physics lastTime = curTime; curTime = device.Timer.Time; if (!simPaused) { float deltaTime = (curTime - lastTime) / 1000.0f; bool b = physics.StepSimulation(deltaTime); if (b) simFrames++; } if (curTime - simFramesTime > 1000) { simFramesTime = curTime; simFps = simFrames; simFrames = 0; } // winnow particles particles.Winnow(curTime, simPaused); // render scene driver.BeginScene(true, true, new Color(40, 80, 160)); scene.DrawAll(); Material material = new Material(); material.Lighting = false; device.VideoDriver.SetMaterial(material); // display stats driver.Draw2DRectangle(new Recti(10, 10, 140, 180), new Color(0x7f000000)); Vector2Di v = new Vector2Di(20, 20); font.Draw("Rendering", v, Color.OpaqueYellow); v.Y += 16; font.Draw(scene.Attributes.GetValue("calls") + " nodes", v, Color.OpaqueWhite); v.Y += 16; font.Draw(driver.FPS + " fps", v, Color.OpaqueWhite); v.Y += 16; font.Draw("[T]rails " + (useTrails ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 32; font.Draw("Physics" + (simPaused ? " (paused)" : ""), v, Color.OpaqueYellow); v.Y += 16; font.Draw(physics.NumCollisionObjects + " shapes", v, Color.OpaqueWhite); v.Y += 16; font.Draw(simFps + " fps", v, Color.OpaqueWhite); v.Y += 16; font.Draw("[Space] to pause", v, Color.OpaqueGreen); driver.EndScene(); } device.Yield(); } // drop physics.Drop(); device.Drop(); }
static void Main(string[] args) { 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(); }
static void Main(string[] args) { // setup Irrlicht device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1024, 768), 32, false, true); if (device == null) return; device.SetWindowCaption("Stencil Shadows - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIFont statsFont = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); Material statsMaterial = Material.IdentityNoLighting; cameraNode = scene.AddCameraSceneNodeFPS(); cameraNode.FarValue = 20000; device.CursorControl.Visible = false; // setup shadows shadows = new Shadows(new Color(0xa0000000), 4000); // load quake level device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); Mesh m = scene.GetMesh("20kdm2.bsp").GetMesh(0); MeshSceneNode n = scene.AddOctreeSceneNode(m, null, -1, 1024); n.Position = new Vector3Df(-1300, -144, -1249); quakeLevelNode = n; // add faerie faerieNode = scene.AddAnimatedMeshSceneNode( scene.GetMesh("../../media/faerie.md2"), null, -1, new Vector3Df(100, -40, 80), new Vector3Df(0, 30, 0), new Vector3Df(1.6f)); faerieNode.SetMD2Animation(AnimationTypeMD2.Wave); faerieNode.AnimationSpeed = 20; faerieNode.GetMaterial(0).SetTexture(0, driver.GetTexture("../../media/faerie2.bmp")); faerieNode.GetMaterial(0).Lighting = false; faerieNode.GetMaterial(0).NormalizeNormals = true; shadows.AddObject(faerieNode); // add light lightMovementHelperNode = scene.AddEmptySceneNode(); n = scene.AddSphereSceneNode(2, 6, lightMovementHelperNode, -1, new Vector3Df(15, -10, 15)); n.SetMaterialFlag(MaterialFlag.Lighting, false); lightNode = n; shadows.AddLight(lightNode); // add flashlight m = scene.GetMesh("../../media/flashlight.obj"); n = scene.AddMeshSceneNode(m, lightNode, -1, new Vector3Df(0), new Vector3Df(0), new Vector3Df(5)); n.SetMaterialFlag(MaterialFlag.Lighting, false); flashlightNode = n; flashlightNode.Visible = false; // render uint shdFrameTime = 0; uint shdFrames = 0; uint shdFps = 0; while (device.Run()) { if (useShadowsRebuilding && shadows.BuildShadowVolume()) shdFrames++; uint t = device.Timer.Time; if (t - shdFrameTime > 1000) { shdFrameTime = t; shdFps = shdFrames; shdFrames = 0; } if (useLightBinding) { lightMovementHelperNode.Position = cameraNode.AbsolutePosition.GetInterpolated(lightMovementHelperNode.Position, 0.1); lightMovementHelperNode.Rotation = cameraNode.AbsoluteTransformation.Rotation; } driver.BeginScene(true, true, new Color(0xff112244)); scene.DrawAll(); if (useShadowsRendering) shadows.DrawShadowVolume(driver); // display stats device.VideoDriver.SetMaterial(statsMaterial); driver.Draw2DRectangle(new Recti(10, 10, 150, 220), new Color(0x7f000000)); Vector2Di v = new Vector2Di(20, 20); statsFont.Draw("Rendering", v, Color.OpaqueYellow); v.Y += 16; statsFont.Draw(driver.FPS + " fps", v, Color.OpaqueWhite); v.Y += 16; statsFont.Draw("[S]hadows " + (useShadowsRendering ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 16; statsFont.Draw("[L]ight binding " + (useLightBinding ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 16; statsFont.Draw("[F]lashlight " + (useFlashlight ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 32; statsFont.Draw("Shadows", v, Color.OpaqueYellow); v.Y += 16; statsFont.Draw(shdFps + " fps", v, Color.OpaqueWhite); v.Y += 16; statsFont.Draw(shadows.VerticesBuilt + " vertices", v, Color.OpaqueWhite); v.Y += 16; statsFont.Draw("[R]ebuilding " + (useShadowsRebuilding ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 16; statsFont.Draw("[Q]uake level " + (useShadowsQuakeLevel ? "ON" : "OFF"), v, Color.OpaqueGreen); driver.EndScene(); } shadows.Drop(); device.Drop(); }