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(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() { 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(); }
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() { 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(); }
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(); }
/// <summary> /// The irrlicht thread for rendering. /// </summary> private void StartIrr() { try { IrrlichtCreationParameters irrparam = new IrrlichtCreationParameters(); if (irrlichtPanel.IsDisposed) { throw new Exception("Form closed!"); } if (irrlichtPanel.InvokeRequired) { irrlichtPanel.Invoke(new MethodInvoker(delegate { irrparam.WindowID = irrlichtPanel.Handle; })); } irrparam.DriverType = DriverType.Direct3D9; irrparam.BitsPerPixel = 16; device = IrrlichtDevice.CreateDevice(irrparam); if (device == null) { throw new NullReferenceException("Could not create device for engine!"); } driver = device.VideoDriver; smgr = device.SceneManager; gui = device.GUIEnvironment; var animText = ""; if (Animations.AnimationNames.Count > 0) { animText = "Animation: " + Animations.AnimationNames[selectedAnimIdx].Key; } var mAnimText = gui.AddStaticText(animText, new Recti(0, this.ClientSize.Height - 80, 100, this.ClientSize.Height - 70)); var mPositionText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 70, 100, this.ClientSize.Height - 60)); var mRotationText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 60, 100, this.ClientSize.Height - 50)); var fpsText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 50, 100, this.ClientSize.Height - 40)); var infoText = gui.AddStaticText("[Space] - Reset\n[LMouse] - Rotate\n[MMouse] - Move\n[Wheel] - Zoom", new Recti(0, this.ClientSize.Height - 40, 100, this.ClientSize.Height)); mAnimText.OverrideColor = mPositionText.OverrideColor = mRotationText.OverrideColor = fpsText.OverrideColor = infoText.OverrideColor = new Color(255, 255, 255); mAnimText.BackgroundColor = mPositionText.BackgroundColor = mRotationText.BackgroundColor = fpsText.BackgroundColor = infoText.BackgroundColor = new Color(0, 0, 0); SkinnedMesh skinnedMesh = smgr.CreateSkinnedMesh(); foreach (var meshBuffer in cdata.staticMesh.MeshBuffers) { skinnedMesh.AddMeshBuffer(meshBuffer); } smgr.MeshManipulator.RecalculateNormals(skinnedMesh); if (RigFile != null) { rig.Apply(skinnedMesh); if (AnimFile != null) { anims.Apply(skinnedMesh); } } skinnedMesh.SetDirty(HardwareBufferType.VertexAndIndex); skinnedMesh.FinalizeMeshPopulation(); AnimatedMeshSceneNode node = smgr.AddAnimatedMeshSceneNode(skinnedMesh); if (node == null) { throw new Exception("Could not load file!"); } node.Scale = new Vector3Df(3.0f); node.SetMaterialFlag(MaterialFlag.Lighting, false); SetMaterials(driver, node); CameraSceneNode camera = smgr.AddCameraSceneNode(null, new Vector3Df(node.BoundingBox.Radius * 8, node.BoundingBox.Radius, 0), new Vector3Df(0, node.BoundingBox.Radius, 0)); camera.NearValue = 0.001f; camera.FOV = 45 * CommonData.PI_OVER_180; scaleMul = node.BoundingBox.Radius / 4; var viewPort = driver.ViewPort; var lineMat = new Material(); lineMat.Lighting = false; while (device.Run()) { driver.ViewPort = viewPort; driver.BeginScene(ClearBufferFlag.All, new Color(100, 101, 140)); node.Position = modelPosition; node.Rotation = modelAngle; node.DebugDataVisible = DebugSceneType.Skeleton | DebugSceneType.BBox; mPositionText.Text = $"X: {modelPosition.X.ToString("F2")} Y: {modelPosition.Y.ToString("F2")} Z: {modelPosition.Z.ToString("F2")}"; mRotationText.Text = $"Yaw: {modelAngle.Y.ToString("F2")} Roll: {modelAngle.Z.ToString("F2")}"; fpsText.Text = $"FPS: {driver.FPS}"; smgr.DrawAll(); gui.DrawAll(); driver.ViewPort = new Recti(this.ClientSize.Width - 100, this.ClientSize.Height - 80, this.ClientSize.Width, this.ClientSize.Height); //driver.ClearBuffers(ClearBufferFlag.None); driver.SetMaterial(lineMat); var matrix = new Matrix(new Vector3Df(0, 0, 0), modelAngle); driver.SetTransform(TransformationState.World, matrix); matrix = matrix.BuildProjectionMatrixOrthoLH(100, 80, camera.NearValue, camera.FarValue); driver.SetTransform(TransformationState.Projection, matrix); matrix = matrix.BuildCameraLookAtMatrixLH(new Vector3Df(50, 0, 0), new Vector3Df(0, 0, 0), new Vector3Df(0, 1f, 0)); driver.SetTransform(TransformationState.View, matrix); driver.Draw3DLine(0, 0, 0, 30f, 0, 0, Color.OpaqueGreen); driver.Draw3DLine(0, 0, 0, 0, 30f, 0, Color.OpaqueBlue); driver.Draw3DLine(0, 0, 0, 0, 0, 30f, Color.OpaqueRed); driver.EndScene(); } device.Drop(); } catch (ThreadAbortException) { } catch (NullReferenceException) { } catch (Exception ex) { if (!this.IsDisposed) { MessageBox.Show(ex.Message); //this.Invoke(new MethodInvoker(delegate { this.Close(); })); } } }
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)); // set gui font env.Skin.SetFont(env.GetFont("../../media/fontlucida.png")); // add some help text env.AddStaticText( "Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome", new Recti(10, 421, 250, 475), true, true, null, -1, true); // add camera CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(null, 100.0f, 1.2f); camera.Position = new Vector3Df(2700 * 2, 255 * 2, 2600 * 2); camera.Target = new Vector3Df(2397 * 2, 343 * 2, 2700 * 2); camera.FarValue = 42000.0f; // disable mouse cursor device.CursorControl.Visible = false; // add terrain scene node TerrainSceneNode terrain = smgr.AddTerrainSceneNode( "../../media/terrain-heightmap.bmp", // heightmap null, // parent node -1, // node id new Vector3Df(), // position new Vector3Df(), // rotation new Vector3Df(40, 4.4f, 40), // scale new Color(255, 255, 255), // vertex color 5, // max LOD TerrainPatchSize._17, // patch size 4); // smooth factor terrain.SetMaterialFlag(MaterialFlag.Lighting, false); terrain.SetMaterialTexture(0, driver.GetTexture("../../media/terrain-texture.jpg")); terrain.SetMaterialTexture(1, driver.GetTexture("../../media/detailmap3.jpg")); terrain.SetMaterialType(MaterialType.DetailMap); terrain.ScaleTexture(1, 20); // create triangle selector for the terrain TriangleSelector selector = smgr.CreateTerrainTriangleSelector(terrain, 0); terrain.TriangleSelector = selector; // create collision response animator and attach it to the camera SceneNodeAnimator anim = smgr.CreateCollisionResponseAnimator( selector, camera, new Vector3Df(60, 100, 60), new Vector3Df(0, 0, 0), new Vector3Df(0, 50, 0)); selector.Drop(); camera.AddAnimator(anim); anim.Drop(); // create skybox and skydome 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"); SceneNode skydome = smgr.AddSkyDomeSceneNode(driver.GetTexture("../../media/skydome.jpg"), 16, 8, 0.95f, 2); driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, true); // create event receiver new MyEventReceiver(device, terrain, skybox, skydome); int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); smgr.DrawAll(); env.DrawAll(); driver.EndScene(); // display frames per second in window title int fps = driver.FPS; if (lastFPS != fps) { // also print terrain height of current camera position // we can use camera position because terrain is located at coordinate origin device.SetWindowCaption(String.Format( "Terrain rendering example - Irrlicht Engine [{0}] fps: {1} Height: {2}", driver.Name, fps, terrain.GetHeight(camera.AbsolutePosition.X, camera.AbsolutePosition.Z))); lastFPS = fps; } } } device.Drop(); }
/// <summary> /// The irrlicht thread for rendering. /// </summary> private void StartIrr() { #if DEBUG try #endif { float DEGREES_TO_RADIANS = (float)(Math.PI / 180.0); //Setup IrrlichtCreationParameters irrparam = new IrrlichtCreationParameters(); if (irrlichtPanel.IsDisposed) { throw new Exception("Form closed!"); } if (irrlichtPanel.InvokeRequired) { irrlichtPanel.Invoke(new MethodInvoker(delegate { irrparam.WindowID = irrlichtPanel.Handle; })); } irrparam.DriverType = DriverType.Direct3D9; irrparam.BitsPerPixel = 32; irrparam.AntiAliasing = 1; device = IrrlichtDevice.CreateDevice(irrparam); if (device == null) { throw new NullReferenceException("Could not create device for engine!"); } driver = device.VideoDriver; smgr = SceneManagerWolvenKit.Create(device); gui = device.GUIEnvironment; smgr.Attributes.SetValue("TW_TW3_TEX_PATH", depot); driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true); lightNode = smgr.AddLightSceneNode(null, new Vector3Df(0, 0, 0), new Colorf(1.0f, 1.0f, 1.0f), 200000.0f); smgr.AmbientLight = new Colorf(1.0f, 1.0f, 1.0f); worldNode = smgr.AddEmptySceneNode(); //NOTE: Witcher assets use Z up but Irrlicht uses Y up so rotate the model worldNode.Rotation = new Vector3Df(-90, 0, 0); //NOTE: We also need to flip the x-coordinate with this rotation worldNode.Scale = new Vector3Df(-1.0f, 1.0f, 1.0f); worldNode.Visible = true; var dome = smgr.AddSkyDomeSceneNode(driver.GetTexture("Terrain\\skydome.jpg"), 16, 8, 0.95f, 2.0f); dome.Visible = true; fpsText = gui.AddStaticText("FPS: 0", new Recti(2, 10, 200, 30), false, false, null, 1, false); fpsText.OverrideColor = IrrlichtLime.Video.Color.SolidRed; fpsText.OverrideFont = gui.GetFont("#DefaultWKFont"); vertexCountText = gui.AddStaticText("Vertices: " + totalVertexCount.ToString(), new Recti(2, 32, 300, 52), false, false, null, 1, false); vertexCountText.OverrideColor = IrrlichtLime.Video.Color.SolidRed; vertexCountText.OverrideFont = gui.GetFont("#DefaultWKFont"); meshCountText = gui.AddStaticText("Meshes: " + totalMeshCount.ToString(), new Recti(2, 54, 300, 74), false, false, null, 1, false); meshCountText.OverrideColor = IrrlichtLime.Video.Color.SolidRed; meshCountText.OverrideFont = gui.GetFont("#DefaultWKFont"); var camera = smgr.AddCameraSceneNodeWolvenKit(); camera.FarValue = 10000.0f; //distanceBar.Invoke((MethodInvoker)delegate //{ // camera.FarValue = (float)Math.Pow(10.0, (double)distanceBar.Value); //}); viewPort = driver.ViewPort; var lineMat = new IrrlichtLime.Video.Material { Lighting = false }; var WMatrix = new Matrix(new Vector3Df(0, 0, 0), smgr.ActiveCamera.ModelRotation); var PMatrix = new Matrix(); PMatrix = PMatrix.BuildProjectionMatrixOrthoLH(100, 80, 0.001f, 10000.0f); var VMatrix = new Matrix(); VMatrix = VMatrix.BuildCameraLookAtMatrixLH(new Vector3Df(50, 0, 0), new Vector3Df(0, 0, 0), new Vector3Df(0, 1f, 0)); int gizmoX = (int)(irrlichtPanel.Width * 0.92f); int gizmoY = (int)(irrlichtPanel.Height * 0.92f); var gizmoViewPort = new Recti(gizmoX, gizmoY, irrlichtPanel.Width, irrlichtPanel.Height); while (device.Run()) { if (this.Visible) { ProcessCommand(); driver.BeginScene(ClearBufferFlag.All); int val = driver.FPS; fpsText.Text = "FPS: " + val.ToString(); smgr.DrawAll(); gui.DrawAll(); // draw xyz axis right bottom driver.ViewPort = gizmoViewPort; driver.SetMaterial(lineMat); WMatrix.SetRotationRadians(smgr.ActiveCamera.ModelRotation * DEGREES_TO_RADIANS); driver.SetTransform(TransformationState.World, WMatrix); driver.SetTransform(TransformationState.Projection, PMatrix); driver.SetTransform(TransformationState.View, VMatrix); driver.Draw3DLine(0, 0, 0, 30f, 0, 0, IrrlichtLime.Video.Color.SolidGreen); driver.Draw3DLine(0, 0, 0, 0, 30f, 0, IrrlichtLime.Video.Color.SolidBlue); driver.Draw3DLine(0, 0, 0, 0, 0, 30f, IrrlichtLime.Video.Color.SolidRed); driver.ViewPort = viewPort; driver.EndScene(); } else { device.Yield(); } } } #if DEBUG catch (ThreadAbortException) { } catch (NullReferenceException) { } catch (Exception ex) { if (!this.IsDisposed) { MessageBox.Show(ex.Message); //this.Invoke(new MethodInvoker(delegate { this.Close(); })); } } #endif }
public Application() { _01.HelloWorld.Kinect kinect = new _01.HelloWorld.Kinect(); mfX = mouseX = 840; mfY = mouseY = 525; mouseL = false; mouseR = false; //device = IrrlichtDevice.CreateDevice( // DriverType.Direct3D9, new Dimension2Di(800, 600), 16, false, true, false); // | device = IrrlichtDevice.CreateDevice( // \|/ Fullscreen DriverType.Direct3D9, new Dimension2Di(1680, 1050), 32, false, true, false); device.SetWindowCaption("BENder3D"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); smgr.AmbientLight = new Colorf(128, 128, 128, 128); //smgr.AddLightSceneNode(null, new Vector3Df(0, 70, 0), new Colorf(122,0,122,0), (float)10); MeshSceneNode box = smgr.AddCubeSceneNode(100, null, 9001, new Vector3Df(0.0f, -ballRadius * 3 / 2, 0.0f)); box.Scale = new Vector3Df(100.0f, 0.1f, 100.0f); //Mesh cyl = smgr.GeometryCreator.CreateCylinderMesh(ballRadius, 50, 256); //Mesh sphere = smgr.GeometryCreator.CreateSphereMesh(ballRadius, 16,16); //MeshSceneNode t = smgr.AddSphereSceneNode(ballRadius, 32); //MeshSceneNode t = smgr.AddOctreeSceneNode(sphere); MeshSceneNode t = smgr.AddMeshSceneNode(smgr.GetMesh("pill.obj")); //MeshSceneNode t = smgr.AddMeshSceneNode(cyl); TriangleSelector triselect = smgr.CreateTriangleSelector(t.Mesh, t); t.TriangleSelector = triselect; triselect.Drop(); //t = smgr.AddMeshSceneNode(smgr.GetMesh("../../media/sphere.x")); //smgr t.SetMaterialTexture(0, driver.GetTexture("rockwall.jpg")); //t.SetMaterialFlag(MaterialFlag.Lighting, true); t.GetMaterial(0).SpecularColor.Set(0, 0, 0); //t.GetMaterial(0).Lighting = true; t.GetMaterial(0).NormalizeNormals = false; /*Texture citrus = driver.AddTexture(new Dimension2Di(200, 200), "citrus.png"); * gui.AddImage(citrus, new Vector2Di(824, 0), true);*/ gui.AddStaticText("Hey, Listen! Press C to switch the mesh to a cylinder!\n Press S to change to a sphere, and enter to send yourself the obj file!", new Recti(0, 0, 400, 60)); //t.AddShadowVolumeSceneNode(); // driver.GPUProgrammingServices.OnSetConstants += new GPUProgrammingServices.SetConstantsHandler(gpu_OnSetConstants); /* * MaterialType shaderMat = MaterialType.Solid; * shaderMat = driver.GPUProgrammingServices.AddHighLevelShaderMaterialFromFiles("C:/IrrlichtLime-1.4/examples/01.HelloWorld/bumpmap.hlsl", "VertexShaderFunction", VertexShaderType.VS_3_0, * "C:/IrrlichtLime-1.4/examples/01.HelloWorld/bumpmap.hlsl", "PixelShaderFunction", PixelShaderType.PS_3_0, MaterialType.Solid); * * t.SetMaterialType(shaderMat); * t.SetMaterialTexture(1, driver.GetTexture("../../media/rockwall_height.bmp"));*/ GPUProgrammingServices gpu = driver.GPUProgrammingServices; MaterialType newMaterialType1 = MaterialType.Solid; MaterialType newMaterialType2 = MaterialType.TransparentAddColor; gpu.OnSetConstants += new GPUProgrammingServices.SetConstantsHandler(gpu_OnSetConstants); // create the shaders depending on if the user wanted high level or low level shaders newMaterialType1 = gpu.AddHighLevelShaderMaterialFromFiles( "d3d9.hlsl", "vertexMain", VertexShaderType.VS_1_1, "d3d9.hlsl", "pixelMain", PixelShaderType.PS_1_1, MaterialType.Solid, 0, GPUShadingLanguage.Default); t.SetMaterialType(newMaterialType1); //t.GetMaterial(0).Wireframe = true; //t.DebugDataVisible = DebugSceneType.Full; //t.AddShadowVolumeSceneNode(null, -1, false, 1000.0f); smgr.AddLightSceneNode(null, new Vector3Df(40, 150, -50), new Colorf(255, 255, 255, 255), 250.0f); //CSampleSceneNode sceneNode = new CSampleSceneNode(smgr.RootNode, smgr, 667); camera = smgr.AddCameraSceneNode(null, new Vector3Df(0, 50, -140), new Vector3Df(0, 5, 0)); //camera.Target = new Vector3Df(-70, 30, -60); //smgr.AddCameraSceneNodeFPS(null, (float)50.0); Material m = new Material(); m.Lighting = false; double PI = 3.1415926f; float distance = 200.0f; double angle = 180.0f; double angleY = 20.0f; int oldMouseX = mouseX; int oldMouseY = mouseY; uint then = device.Timer.Time; uint currentAutism = device.Timer.Time; bool autism = false; while (device.Run()) { uint now = device.Timer.Time; float frameDeltaTime = (float)(now - then) / 1000.0f; then = now; if (kinect.isTranslating && (kinect.translation.X < 30 && kinect.translation.X > -30)) { mfX -= (int)(kinect.translation.X); mfY -= (int)(kinect.translation.Y); Console.WriteLine(mouseX + ", " + mouseY + " ----------------- " + (int)(kinect.translation.X) + ", " + (int)(kinect.translation.Y)); } kinect.resetTranslation(); /* * if (getDistance((int)mfX, (int)mfY, 512, 384) > 150) * { * mfX = 512; mfY= 384; * }*/ mouseX = Math.Abs((int)mfX) % 1024; mouseY = Math.Abs((int)mfY) % 768; //mouseX = kinect.position.X; device.CursorControl.Position = new Vector2Di(mouseX, mouseY); if (!potterWheelDown && IsKeyDown(KeyCode.Up)) { potterWheelDown = true; deltaAngle = 1.0d; potterWheelActivate = !potterWheelActivate; } else if (!IsKeyDown(KeyCode.Up)) { potterWheelDown = false; } if (!leftKeyPressed && IsKeyDown(KeyCode.Left)) { leftKeyPressed = true; deltaAngle /= 2; } else if (!IsKeyDown(KeyCode.Left)) { leftKeyPressed = false; } if (!rightKeyPressed && IsKeyDown(KeyCode.Right)) { rightKeyPressed = true; deltaAngle *= 2; } else if (!IsKeyDown(KeyCode.Right)) { rightKeyPressed = false; } if (potterWheelActivate) { angle -= 700.0f * deltaAngle * frameDeltaTime; } if (angle > 360) { angle -= 360; } else if (angle < 0) { angle += 360; } if (angleY > 360) { angle -= 360; } else if (angleY < 0) { angleY += 360; } driver.BeginScene(true, true, new Color(100, 101, 140)); camera.Target = new Vector3Df(0, 0, 0); double temp = Math.Cos(angleY * PI / 180.0) * distance; double X = Math.Sin(angle * PI / 180.0) * temp; double Y = Math.Sin(angleY * PI / 180.0) * distance; double Z = Math.Cos(angle * PI / 180.0) * temp; camera.Position = new Vector3Df((float)X, (float)Y, (float)Z); smgr.DrawAll(); gui.DrawAll(); driver.SetMaterial(m); Triangle3Df triangle = interpolateFrom2D(new Vector2Di(mouseX, mouseY)); if (kinect.isMorphing && kinect.morphDist > 0) //if (IsKeyDown(KeyCode.KeyW)) { //Console.WriteLine("PRESSED KEY"); triangle.A *= new Vector3Df(0.5f); triangle.B *= new Vector3Df(0.5f); triangle.C *= new Vector3Df(0.5f); if (isCyl) { deformCyl(t, triangle.A, new Vector3Df(.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle); } else { deformMesh(t, triangle.A, new Vector3Df(.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle); } } else if (kinect.isMorphing && kinect.morphDist < 0) { //Console.WriteLine("PRESSED KEY"); triangle.A *= new Vector3Df(1.5f); triangle.B *= new Vector3Df(1.5f); triangle.C *= new Vector3Df(1.5f); if (isCyl) { deformCyl(t, triangle.A, new Vector3Df(-.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle); } else { deformMesh(t, triangle.A, new Vector3Df(-.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle); } } if (kinect.isZoom && kinect.zoomDist < 0) { if (distance < 300.0f) { distance += .0625f; } } if (kinect.isZoom && kinect.zoomDist > 0) { if (distance > 150) { distance -= .0625f; } } if (kinect.isRotating && kinect.rotation > 0) { angle += 200 * frameDeltaTime; } if (kinect.isRotating && kinect.rotation < 0) { angle -= 200 * frameDeltaTime; } //Change shape if (IsKeyDown(KeyCode.KeyA)) { IrrlichtLime.IO.WriteFile file = device.FileSystem.CreateWriteFile("./Saved.obj"); writeMesh(file, t.Mesh, 1); mail(); } if (IsKeyDown(KeyCode.KeyC)) { isCyl = true; t.Remove(); t = smgr.AddMeshSceneNode(smgr.GetMesh("pill.obj")); //MeshSceneNode t = smgr.AddMeshSceneNode(cyl); triselect = smgr.CreateTriangleSelector(t.Mesh, t); t.TriangleSelector = triselect; triselect.Drop(); //t = smgr.AddMeshSceneNode(smgr.GetMesh("../../media/sphere.x")); //smgr t.SetMaterialTexture(0, driver.GetTexture("rockwall.jpg")); //t.SetMaterialFlag(MaterialFlag.Lighting, true); t.GetMaterial(0).SpecularColor.Set(0, 0, 0); //t.GetMaterial(0).Lighting = true; t.GetMaterial(0).NormalizeNormals = false; t.SetMaterialType(newMaterialType1); } else if (IsKeyDown(KeyCode.KeyS)) { isCyl = false; t.Remove(); t = smgr.AddSphereSceneNode(ballRadius, 32); triselect = smgr.CreateTriangleSelector(t.Mesh, t); t.TriangleSelector = triselect; triselect.Drop(); //t = smgr.AddMeshSceneNode(smgr.GetMesh("../../media/sphere.x")); //smgr t.SetMaterialTexture(0, driver.GetTexture("rockwall.jpg")); //t.SetMaterialFlag(MaterialFlag.Lighting, true); t.GetMaterial(0).SpecularColor.Set(0, 0, 0); //t.GetMaterial(0).Lighting = true; t.GetMaterial(0).NormalizeNormals = false; t.SetMaterialType(newMaterialType1); } driver.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(); }
/// <summary> /// The irrlicht thread for rendering. /// </summary> private void StartIrr() { try { //Setup IrrlichtCreationParameters irrparam = new IrrlichtCreationParameters(); if (irrlichtPanel.IsDisposed) { throw new Exception("Form closed!"); } if (irrlichtPanel.InvokeRequired) { irrlichtPanel.Invoke(new MethodInvoker(delegate { irrparam.WindowID = irrlichtPanel.Handle; })); } irrparam.DriverType = DriverType.Direct3D9; irrparam.DriverType = DriverType.OpenGL; irrparam.BitsPerPixel = 16; device = IrrlichtDevice.CreateDevice(irrparam); if (device == null) { throw new NullReferenceException("Could not create device for engine!"); } driver = device.VideoDriver; smgr = device.SceneManager; gui = device.GUIEnvironment; var cam = smgr.AddCameraSceneNode(null); cam.TargetAndRotationBinding = true; cam.Position = new Vector3Df(-100.0f, 500.0f, 100.0f); cam.Target = new Vector3Df(0.0f); cam.FarValue = 42000.0f; device.CursorControl.Visible = false; //Terrain heightmap = driver.CreateImage("Terrain\\basemap.bmp"); terrain = smgr.AddTerrainSceneNode( "Terrain\\basemap.bmp", null, -1, new Vector3Df(0.0f) ); terrain.Scale = new Vector3Df(32, 5, 32); terrain.SetMaterialFlag(MaterialFlag.Lighting, false); terrain.SetMaterialTexture(0, driver.GetTexture("Terrain\\rockwall.jpg")); selector = smgr.CreateTerrainTriangleSelector(terrain, 0); var arrow = smgr.AddAnimatedMeshSceneNode(smgr.AddArrowMesh("arrow", new IrrlichtLime.Video.Color(255, 255, 0, 0), new IrrlichtLime.Video.Color(255, 0, 255, 0)), null); arrow.SetMaterialFlag(MaterialFlag.Lighting, false); arrow.Scale = new Vector3Df(100.0f); arrow.Rotation = new Vector3Df(0.0f, 0.0f, 180.0f); //Skybox and skydome driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, false); /*var box = smgr.AddSkyBoxSceneNode( * ("Terrain\\irrlicht2_up.jpg"), * ("Terrain\\irrlicht2_dn.jpg"), * ("Terrain\\irrlicht2_lf.jpg"), * ("Terrain\\irrlicht2_rt.jpg"), * ("Terrain\\irrlicht2_ft.jpg"), * ("Terrain\\irrlicht2_bk.jpg")); * box.Visible = true;*/ var dome = smgr.AddSkyDomeSceneNode(driver.GetTexture("Terrain\\skydome.jpg"), 16, 8, 0.95f, 2.0f); dome.Visible = true; driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, true); var helpq = gui.AddStaticText("Press Q to disable focus!", new Recti(0, this.ClientSize.Height - 40, 100, this.ClientSize.Height), true, true, null, 1, true); var helpesc = gui.AddStaticText("Press ESC to quit", new Recti(0, this.ClientSize.Height - 20, 100, this.ClientSize.Height), true, true, null, 1, true); middletext = gui.AddStaticText("Click to enable mouselook and move with WASD", new Recti(ClientSize.Width / 2 - 100, this.ClientSize.Height / 2, ClientSize.Width / 2 + 100, this.ClientSize.Height / 2 + 30), true, true, null, 1, true); middletext.OverrideColor = IrrlichtLime.Video.Color.SolidWhite; middletext.BackgroundColor = IrrlichtLime.Video.Color.SolidBlack; var irrTimer = device.Timer; var then = 0; var then30 = 0; device.CursorControl.Visible = false; Vector2Df lastcurr = new Vector2Df(0f); uint dt = 0; while (device.Run()) { driver.BeginScene(ClearBufferFlag.All); if (catchmouse) { // move the arrow to the nearest vertex ... IrrlichtLime.Core.Vector2Di center = new IrrlichtLime.Core.Vector2Di(irrlichtPanel.Width / 2, irrlichtPanel.Height / 2); Line3Df ray = smgr.SceneCollisionManager.GetRayFromScreenCoordinates(center, cam); Vector3Df pos; Triangle3Df Tri; var curr = device.CursorControl.RelativePosition; // Threshold and periodical check so we don't spin around due to float conversions if (device.Timer.Time > dt && curr.GetDistanceFrom(lastcurr) > 0.01f) { Line3Df cursor_ray = smgr.SceneCollisionManager .GetRayFromScreenCoordinates(new Vector2Di((int)(curr.X * irrlichtPanel.Width), (int)(curr.Y * irrlichtPanel.Height)), cam); smgr.ActiveCamera.Target = cursor_ray.Middle; dt = device.Timer.Time + 30; lastcurr = curr; device.CursorControl.Position = center; } if (smgr.SceneCollisionManager.GetCollisionPoint(ray, selector, out pos, out Tri, out outnode)) { var scale = 32; // terrain is scaled 32X var size = 512; // heightmap is 512x512 pixels var x = (pos.X / scale); var z = (pos.Z / scale); var index = x * size + z; x *= scale; z *= scale; arrow.Position = new Vector3Df(x, terrain.GetHeight(x, z) + 100, z); } } smgr.DrawAll(); gui.DrawAll(); driver.EndScene(); //device.CursorControl.Position = new Vector2Di(irrlichtPanel. } device.Drop(); } catch (ThreadAbortException) { } catch (NullReferenceException) { } catch (Exception ex) { if (!this.IsDisposed) { MessageBox.Show(ex.Message); //this.Invoke(new MethodInvoker(delegate { this.Close(); })); } } }