Beispiel #1
0
        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();
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        static void Main()
        {
            DriverSettingsForm driverSettings = new DriverSettingsForm(
                "Texture paint example",
                "This example shows how to use TexturePainter and render-to-texture (RTT) technique.\n\n" +
                "Use mouse to draw on the 2D image (texture) and see changes on the mesh and on RTT target.");

            if (!driverSettings.ShowDialog())
            {
                return;
            }

            device = IrrlichtDevice.CreateDevice(
                driverSettings.DriverType,
                driverSettings.VideoMode.Resolution,
                driverSettings.VideoMode.Depth,
                driverSettings.Fullscreen);

            if (device == null)
            {
                Console.WriteLine("\nDevice creation failed!\n<Press any key to exit>");
                Console.ReadKey();
                return;
            }

            device.VideoDriver.SetTextureCreationFlag(TextureCreationFlag.AllowMemoryCopy, true);               //workaround: bug in irrlicht

            Application app = new Application(device);

            int lastFPS = -1;

            while (device.Run())
            {
                device.VideoDriver.BeginScene();

                app.Render();

                device.VideoDriver.EndScene();

                int fps = device.VideoDriver.FPS;
                if (fps != lastFPS)
                {
                    device.SetWindowCaption(string.Format(
                                                "Texture painting example - Irrlicht Lime [{0}] {1} fps",
                                                device.VideoDriver.Name, fps));

                    lastFPS = fps;
                }
            }

            device.Drop();
        }
Beispiel #4
0
        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();
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
        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();
        }
Beispiel #7
0
        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();
        }
Beispiel #8
0
        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();
        }
Beispiel #9
0
        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();
        }
Beispiel #10
0
        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();
        }
Beispiel #11
0
        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();
        }
Beispiel #12
0
        public FNGame()
        {
            var param = new IrrlichtCreationParameters()
            {
                AntiAliasing = 8,
                DeviceType   = DeviceType.Best,
                DriverType   = DriverType.OpenGL,
                VSync        = true,
                WindowSize   = new Dimension2Di(1200, 700)
            };

            device = IrrlichtDevice.CreateDevice(param);

            device.OnEvent += device_OnEvent;

            Driver = device.VideoDriver;
            Scene  = device.SceneManager;
            Gui    = device.GUIEnvironment;
        }
        public bool ShowDialog()
        {
            device = IrrlichtDevice.CreateDevice(DriverType.BurningsVideo, new Dimension2Di(320, 320));
            device.FileSystem.AddFileArchive("../../media/");
            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);
            device.SetWindowCaption(windowCaption);

            initGUI();

            while (device.Run())
            {
                device.VideoDriver.BeginScene(ClearBufferFlag.All, new Color(40, 180, 80));
                device.GUIEnvironment.DrawAll();
                device.VideoDriver.EndScene();
            }

            device.Drop();

            return(run);
        }
Beispiel #14
0
        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();
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            IrrlichtDevice device = IrrlichtDevice.CreateDevice(
                DriverType.Software, new Dimension2Di(640, 480), 16, false, false, false);

            device.SetWindowCaption("Hello World! - Irrlicht Engine Demo");

            VideoDriver    driver = device.VideoDriver;
            SceneManager   smgr   = device.SceneManager;
            GUIEnvironment gui    = device.GUIEnvironment;

            gui.AddStaticText("Hello World! This is the Irrlicht Software renderer!",
                              new Recti(10, 10, 260, 22), true);

            //          AnimatedMesh mesh = smgr.GetMesh("../../media/sydney.md2");
            //          AnimatedMeshSceneNode node = smgr.AddAnimatedMeshSceneNode(mesh);
            //
            //          if (node != null)
            //          {
            //              node.SetMaterialFlag(MaterialFlag.Lighting, false);
            //              node.SetMD2Animation(AnimationTypeMD2.Stand);
            //              node.SetMaterialTexture(0, driver.GetTexture("../../media/sydney.bmp"));
            //          }

            smgr.AddCameraSceneNode(null, new Vector3Df(0, 30, -40), new Vector3Df(0, 5, 0));

            while (device.Run())
            {
                driver.BeginScene(true, true, new Color(100, 101, 140));

                smgr.DrawAll();
                gui.DrawAll();

                driver.EndScene();
            }

            device.Drop();
        }
Beispiel #16
0
        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();
        }
Beispiel #17
0
        public Jeu()
        {
            Device = IrrlichtDevice.CreateDevice(
                DriverType.Direct3D9,
                new Dimension2Di(800, 600),
                32, false, false, true);

            Device.SetWindowCaption("Canardstein 3D");
            Device.OnEvent += Evenement;
            SceneNode cube = Device.SceneManager.AddCubeSceneNode(1, null, 0, new Vector3Df(2, 0, 0), new Vector3Df(0, 45, 0));

            cube.SetMaterialFlag(MaterialFlag.Lighting, false);
            CameraSceneNode camera = Device.SceneManager.AddCameraSceneNode(null, new Vector3Df(0, 0, 0), new Vector3Df(2, 0, 0));

            Device.CursorControl.Position = new Vector2Di(400, 300);
            Device.CursorControl.Visible  = false;

            while (Device.Run())
            {
                float tempsEcoule = (Device.Timer.Time - DerniereFrame) / 1000f;
                DerniereFrame = Device.Timer.Time;

                if (Device.CursorControl.Position.X != 400)
                {
                    Rotation += (Device.CursorControl.Position.X - 400) * 0.0025;
                    Device.CursorControl.Position = new Vector2Di(400, 300);
                    VecteurAvant = new Vector3Df(
                        x: (float)Math.Cos(Rotation),
                        y: 0,
                        z: -(float)Math.Sin(Rotation));
                    VecteurDroite = VecteurAvant;
                    VecteurDroite.RotateXZby(-90);
                }
                Vector3Df vitesse = new Vector3Df();
                if (K_Avant)
                {
                    vitesse += VecteurAvant;
                }
                else if (K_Arriere)
                {
                    vitesse -= VecteurAvant;
                }
                if (K_Gauche)
                {
                    vitesse -= VecteurDroite;
                }
                else if (K_Droite)
                {
                    vitesse += VecteurDroite;
                }

                vitesse = vitesse.Normalize() * tempsEcoule * 2;

                camera.Position += vitesse;
                camera.Target    = camera.Position + VecteurAvant;

                Device.VideoDriver.BeginScene(ClearBufferFlag.Color | ClearBufferFlag.Depth, Color.OpaqueMagenta);
                Device.SceneManager.DrawAll();
                Device.VideoDriver.EndScene();
            }
        }
        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();
        }
Beispiel #19
0
        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();
        }
Beispiel #20
0
        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();
        }
Beispiel #21
0
        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();
        }
Beispiel #22
0
        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();
        }
Beispiel #23
0
        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();
        }
        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();
        }
Beispiel #25
0
        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();
        }
Beispiel #26
0
        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();
        }
Beispiel #27
0
        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();
        }
Beispiel #28
0
        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();
        }
Beispiel #29
0
        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();
        }
        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();
        }