private void setMaterialsSettings(AnimatedMeshSceneNode node)
        {
            if (node != null)
            {
                // materials with normal maps are not handled
                for (int i = 0; i < node.MaterialCount; ++i)
                {
                    Material material = node.GetMaterial(i);
                    if (material.Type == MaterialType.NormalMapSolid ||
                        material.Type == MaterialType.ParallaxMapSolid)
                    {
                        material.Type = MaterialType.Solid;
                    }
                    else if (material.Type == MaterialType.NormalMapTransparentAddColor ||
                             material.Type == MaterialType.ParallaxMapTransparentAddColor)
                    {
                        material.Type = MaterialType.TransparentAddColor;
                    }
                    else if (material.Type == MaterialType.NormalMapTransparentVertexAlpha ||
                             material.Type == MaterialType.ParallaxMapTransparentVertexAlpha)
                    {
                        material.Type = MaterialType.TransparentVertexAlpha;
                    }
                }

                node.SetMaterialFlag(MaterialFlag.Lighting, false);
                node.SetMaterialFlag(MaterialFlag.BackFaceCulling, false);

                for (int i = 1; i < 8; ++i)                 // 8 = _IRR_MATERIAL_MAX_TEXTURES_
                {
                    node.SetMaterialTexture(i, null);
                }
            }
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            //var light = Scene.AddLightSceneNode(Scene.RootNode,new Vector3Df(2, 6, 3), new Colorf(200, 200, 180), 20);
            var light = Scene.AddLightSceneNode(null, new Vector3Df(-30, 35, -25));

            light.Radius      = 25;
            light.CastShadows = true;
            light.LightType   = LightType.Point;

            var sun = Scene.AddLightSceneNode(null, new Vector3Df(40, 100, 40));

            sun.Radius      = 50;
            sun.CastShadows = true;
            sun.LightType   = LightType.Point;


            sphere       = Scene.AddAnimatedMeshSceneNode(Scene.AddSphereMesh("sphere", 10f));
            sphere.Scale = new Vector3Df(1);
            sphere.SetMaterialFlag(MaterialFlag.Lighting, true);
            sphere.Position = new Vector3Df(1, 11, 1);
            //sphere.SetMaterialTexture(0, Driver.GetTexture("Mars.jpg"));
            sphere.SetMaterialTexture(0, GeneratePlanetTexture(new Vector2Dd(300, 300)));
            Scene.MeshManipulator.SetVertexColors(sphere.Mesh, new Color(200, 200, 200));

            var terrain =
                Scene.AddAnimatedMeshSceneNode(Scene.AddHillPlaneMesh("terrain", new Dimension2Df(1, 1),
                                                                      new Dimension2Di(128, 128),
                                                                      new Material(), 0));

            terrain.Position = new Vector3Df(0, 0, 0);
            terrain.SetMaterialFlag(MaterialFlag.Lighting, true);
            Scene.MeshManipulator.SetVertexColors(terrain.Mesh, new Color(220, 220, 220));
            selector = Scene.CreateOctreeTriangleSelector(terrain.Mesh, terrain, 128);
            terrain.TriangleSelector = selector;
            Scene.CreateCollisionResponseAnimator(selector, terrain);

            _cam = new Camera(this);

            selectionCube = Scene.AddCubeSceneNode(10, null, -1);
            selectionCube.SetMaterialFlag(MaterialFlag.Wireframe, true);
        }
Exemplo n.º 3
0
        static void Main()
        {
            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(ClearBufferFlag.All, new Color(100, 101, 140));

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

                driver.EndScene();
            }

            device.Drop();
        }
        private void backgroundRendering_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            //DeviceSettings settings = e.Argument as DeviceSettings;

            // create irrlicht device using provided settings
            if (panelRenderWindow.IsDisposed)
            {
                throw new Exception("Form closed!");
            }

            DeviceSettings s = new DeviceSettings(
                IntPtr.Zero,
                DriverType.Direct3D9,
                0,                  //antialias
                new Color(100, 101, 140),
                false);

            if (panelRenderWindow.InvokeRequired)
            {
                panelRenderWindow.Invoke(new MethodInvoker(delegate { s.WindowID = panelRenderWindow.Handle; }));
            }

            dev = IrrlichtDevice.CreateDevice(s);
            if (dev == null)
            {
                throw new NullReferenceException("Could not create device for engine!");
            }
            dev.OnEvent        += new IrrlichtDevice.EventHandler(this.device_OnEvent);
            dev.Logger.LogLevel = LogLevel.Warning;

            drv  = dev.VideoDriver;
            smgr = dev.SceneManager;
            gui  = dev.GUIEnvironment;

            _ = smgr.FileSystem.AddFileArchive(activeMod.FileDirectory);

            smgr.Attributes.AddValue("TW_TW3_LOAD_SKEL", true);
            smgr.Attributes.AddValue("TW_TW3_LOAD_BEST_LOD_ONLY", true);


            // added by vl
            if (meshFile != null && meshFile.Length > 0)
            {
                mesh = smgr.GetMesh(meshFile);
            }

            if (mesh == null)
            {
                throw new Exception("Failed to load mesh.");
            }

            mesh.Grab();
            smgr.MeshManipulator.RecalculateNormals(mesh);
            meshLoaded = true;

            float scaleMul = 1.0f;

            node   = smgr.AddAnimatedMeshSceneNode(mesh);
            helper = smgr.GetMeshLoader(smgr.MeshLoaderCount - 1).getMeshLoaderHelper();             // hacked to gat witcher3 loader
            if (node != null && meshLoaded)
            {
                node.Scale = new Vector3Df(3.0f);
                node.SetMaterialFlag(MaterialFlag.Lighting, false);

                scaleMul = node.BoundingBox.Radius / 4;

                if (!string.IsNullOrEmpty(rigFile))
                {
                    meshToAnimate = helper.loadRig(rigFile, mesh);
                    if (meshToAnimate == null)
                    {
                        throw new Exception("Failed to load rig.");
                    }
                    else
                    {
                        meshToAnimate.Grab();
                        rigLoaded = true;
                        Logger.LogString("Rig loaded!", Logtype.Success);
                        node.Mesh = meshToAnimate;
                    }
                }

                if (!string.IsNullOrEmpty(animFile) && rigLoaded)
                {
                    animList = helper.loadAnimation(animFile, meshToAnimate);
                    if (animList.Count > 0)
                    {
                        animLoaded = true;
                        Logger.LogString($"{animList.Count} animations loaded! Select animation to play", Logtype.Success);
                    }
                    else
                    {
                        Logger.LogString("No animations loaded!", Logtype.Important);
                    }
                }

                setMaterialsSettings(node);
            }

            var camera = smgr.AddCameraSceneNode(null,
                                                 new Vector3Df(node.BoundingBox.Radius * 8, node.BoundingBox.Radius, 0),
                                                 new Vector3Df(0, node.BoundingBox.Radius, 0));

            camera.NearValue = 0.001f;
            camera.FOV       = 45.0f * 3.14f / 180.0f;


            var animText = activeAnim;

            var mAnimText     = gui.AddStaticText(animText, new Recti(0, this.ClientSize.Height - 80, 100, this.ClientSize.Height - 70));
            var mPositionText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 70, 100, this.ClientSize.Height - 60));
            var mRotationText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 60, 100, this.ClientSize.Height - 50));
            var fpsText       = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 50, 100, this.ClientSize.Height - 40));
            var infoText      = gui.AddStaticText("[Space] - Reset\n[LMouse] - Rotate\n[MMouse] - Move\n[Wheel] - Zoom", new Recti(0, this.ClientSize.Height - 40, 100, this.ClientSize.Height));

            mAnimText.OverrideColor   = mPositionText.OverrideColor = mRotationText.OverrideColor = fpsText.OverrideColor = infoText.OverrideColor = new Color(255, 255, 255);
            mAnimText.BackgroundColor = mPositionText.BackgroundColor = mRotationText.BackgroundColor = fpsText.BackgroundColor = infoText.BackgroundColor = new Color(0, 0, 0);

            viewPort = drv.ViewPort;
            var lineMat = new Material
            {
                Lighting = false
            };

            while (dev.Run())
            {
                drv.ViewPort = viewPort;

                drv.BeginScene(ClearBufferFlag.Depth | ClearBufferFlag.Color, s.BackColor);

                node.Position = modelPosition;
                node.Rotation = modelAngle;

                //update info box
                mPositionText.Text = $"X: {modelPosition.X.ToString("F2")} Y: {modelPosition.Y.ToString("F2")} Z: {modelPosition.Z.ToString("F2")}";
                mRotationText.Text = $"Yaw: {modelAngle.Y.ToString("F2")} Roll: {modelAngle.Z.ToString("F2")}";
                fpsText.Text       = $"FPS: {drv.FPS}";

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

                // draw xyz axis right bottom

                drv.ViewPort = new Recti(this.ClientSize.Width - 100, this.ClientSize.Height - 80, this.ClientSize.Width, this.ClientSize.Height);

                drv.SetMaterial(lineMat);
                var matrix = new Matrix(new Vector3Df(0, 0, 0), modelAngle);
                drv.SetTransform(TransformationState.World, matrix);
                matrix = matrix.BuildProjectionMatrixOrthoLH(100, 80, camera.NearValue, camera.FarValue);
                drv.SetTransform(TransformationState.Projection, matrix);
                matrix = matrix.BuildCameraLookAtMatrixLH(new Vector3Df(50, 0, 0), new Vector3Df(0, 0, 0), new Vector3Df(0, 1f, 0));
                drv.SetTransform(TransformationState.View, matrix);
                drv.Draw3DLine(0, 0, 0, 30f, 0, 0, Color.SolidGreen);
                drv.Draw3DLine(0, 0, 0, 0, 30f, 0, Color.SolidBlue);
                drv.Draw3DLine(0, 0, 0, 0, 0, 30f, Color.SolidRed);

                drv.EndScene();

                // if we requested to stop, we close the device
                if (worker.CancellationPending)
                {
                    dev.Close();
                }
            }
            // drop device
            dev.Drop();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Létrehoz egy sizex*sizey méretű ablakot, windowCaption címmel és deviceType renderelési eszközzel.
        /// </summary>
        /// <param name="windowCaption">Ablak címe</param>
        /// <param name="sizex">Ablak szélessége</param>
        /// <param name="sizey">Ablak magassága</param>
        /// <param name="deviceType">A render eszköz típusa ("DriverType.OpenGL;" (OpenGL) vagy "DriverType.Direct3D8;"/"DriverType.Direct3D9;" (DirectX))</param>
        /// <param name="mapName">Betöltendő pálya neve a kiterjesztés nélkül (pl. "devmap")</param>
        /// <param name="pak0">A pak0 fájl neve (pl. "pak0" vagy "pack1")</param>
        /// <param name="pak1">A pak1 fájl neve (pl. "pak1" vagy "pack4")</param>
        /// <param name="pak2">A pak2 fájl neve (pl. "pak2" vagy "pack2")</param>
        public static void createScreen(string windowCaption, int sizex, int sizey, DriverType deviceType, string mapName, string pak0, string pak1, string pak2, bool isFullScreen)
        {
            //Ablakot megjeleníteni
            if (isFullScreen == true)
            {
                device = IrrlichtDevice.CreateDevice(deviceType, new Dimension2Di(sizex, sizey), 32, true, false, true);
            }
            else
            {
                device = IrrlichtDevice.CreateDevice(deviceType, new Dimension2Di(sizex, sizey), 32, false, false, true);
            }
            if (device == null)
                return;

            AnimatedMesh q3levelmesh = null;
            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);
            device.SetWindowCaption(Property.modName + " Build " + Property.modVersion);
            driver = device.VideoDriver;
            smgr = device.SceneManager;

            GUIEnvironment gui = device.GUIEnvironment;
            //fadein
            GUIInOutFader fader = device.GUIEnvironment.AddInOutFader();
            fader.SetColor(new Color(0, 0, 0, 255));
            fader.FadeIn(2000);
            //hurtOverlay = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/Overlays/hurt.png"), new Vector2Di(0, 0));
            //hurtOverlay.Visible = false;
            GUIImage copyrightScreen = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/exit.tga"), new Vector2Di(0, 0));
            float guiScalex = sizex / 800;
            float guiScaley = sizey / 600;
            copyrightScreen.Visible = false;
            copyrightScreen.ScaleImage = true;
            copyrightScreen.SetMaxSize(new Dimension2Di(sizex, sizey));
            copyrightScreen.SetMinSize(new Dimension2Di(sizex, sizey));
            //Betölteni a mapot
            try
            {
                device.FileSystem.AddFileArchive("./Content/PK3/" + pak0 + ".edsf");
            }
            catch (Exception ex)
            {
                Logger.Log("pak0 fajl betoltese sikertelen vagy nem talalhato, a jatek nem tud betoltodni");
                string error = ex.ToString();
                    Logger.Log(error);
                Environment.Exit(0);
            }
            try
            {
                device.FileSystem.AddFileArchive("./Content/PK3/" + pak1 + ".edsf");
            }
            catch (Exception ex)
            {
                Logger.Log("pak1 fajl betoltese sikertelen vagy nem talalhato, ignoralva");
                string error = ex.ToString();
                    Logger.Log(error);
            }
            try
            {
                device.FileSystem.AddFileArchive("./Content/PK3/" + pak2 + ".edsf");
            }
            catch (Exception ex)
            {
                Logger.Log("pak2 fajl betoltese sikertelen vagy nem talalhato, ignoralva");
                string error = ex.ToString();
                    Logger.Log(error);
            }
            try
            {
                q3levelmesh = smgr.GetMesh(mapName + ".bsp");
            }
            catch (Exception ex)
            {
                Logger.Log("Palya betoltese sikertelen vagy nem talalhato, a jatek nem tud betoltodni");
                string error = ex.ToString();
                Logger.Log(error);
                Environment.Exit(0);
            }
            MeshSceneNode q3node = null;
                q3node = smgr.AddOctreeSceneNode(q3levelmesh.GetMesh(0), null, IDFlag_IsPickable);
                q3node.Position = new Vector3Df(-1350, -130, -1400);
            SceneNode node = null;
            if (mapName == "rpg")
            {
                IsRPG = true;
            }
            //LightSceneNode light = smgr.AddLightSceneNode(q3node, new Vector3Df(-1319, -118, -1410), new Color(255, 255, 255), 600.0, 10);
            //Half-Life Headcrab
            AnimatedMeshSceneNode anode3 = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/headcrab.mdl"));
            if (IsRPG)
            {
                anode3.Position = new Vector3Df(-1212, -180, -1346);
                Audio.playWave("./Content/Music/rpg.mp3");
            }
            else
            {
                anode3.Position = new Vector3Df(-1372.951f, -145.9882f, -1319.71f);
            }
            anode3.Rotation = new Vector3Df(0, 0, 0);
            anode3.AnimationSpeed = 1;
            Scenes.changeAnimation(anode3, 1, 31);
            anode3.SetMaterialFlag(MaterialFlag.Lighting, true);
            anode3.GetMaterial(0).NormalizeNormals = true;
            anode3.GetMaterial(0).Lighting = false;
            //Yodan
            anode2 = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/yodan.mdl"));
            anode2.Position = new Vector3Df(-1355, -200, -1410);
            anode2.AnimationSpeed = 15;
            anode2.SetMaterialFlag(MaterialFlag.Lighting, true);
            anode2.GetMaterial(0).NormalizeNormals = true;
            anode2.GetMaterial(0).Lighting = false;
            anode2.SetTransitionTime(3);
               			Scenes.changeYodanAnimation(anode2, "idle");
            //SkyBox
            SceneNode skybox = smgr.AddSkyBoxSceneNode("./Contents/2D/Skybox/mountains_up.jpg", "./Contents/2D/Skybox/mountains_dn.jpg", "./Contents/2D/Skybox/mountains_lf.jpg", "./Contents/2D/Skybox/mountains_rt.jpg", "./Contents/2D/Skybox/mountains_ft.jpg", "./Contents/2D/Skybox/mountains_bk.jpg");
            skybox.Visible = true;
            //FPS kamera hozzáadása
            camera = smgr.AddCameraSceneNodeFPS();
            camera.Position = new Vector3Df(-1625.723f, -145.9937f, -1532.087f);
            camera.Target = new Vector3Df(-1491.555f, -1434.106f, -1368.737f);
            //fegyver
            AnimatedMesh weaponmesh = smgr.GetMesh("./Content/3D/blades.mdl");
            AnimatedMeshSceneNode weapon = smgr.AddAnimatedMeshSceneNode(weaponmesh, camera, 30);
            weapon.Scale = new Vector3Df(0.5f, 0.5f, 0.5f);
            weapon.Position = new Vector3Df(0, 0, 15);
            weapon.Rotation = new Vector3Df(0, -90, 0);
            Scenes.changeAnimation(weapon, 1, 1);
            weapon.Visible = true;
            //fizika
            TriangleSelector selector;
            selector = smgr.CreateOctreeTriangleSelector(q3levelmesh.GetMesh(0), q3node, 128);
            q3node.TriangleSelector = selector;
            anim = smgr.CreateCollisionResponseAnimator(selector, camera, new Vector3Df(30, 50, 30), new Vector3Df(0, -10, 0), new Vector3Df(0, 30, 0));
            //Overlay
            GUIImage overlay = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/Overlays/vignette.png"), new Vector2Di(0, 0));
            overlay.ScaleImage = true;
            overlay.SetMaxSize(new Dimension2Di(sizex, sizey));
            overlay.SetMinSize(new Dimension2Di(sizex, sizey));
            selector.Drop();
            camera.AddAnimator(anim);
            anim.Drop();
            // fény
            lightMovementHelperNode = smgr.AddEmptySceneNode();

            q3node = smgr.AddSphereSceneNode(2, 6, lightMovementHelperNode, -1, new Vector3Df(15, -10, 15));
            q3node.SetMaterialFlag(MaterialFlag.Lighting, false);

            lightNode = q3node;

            //A Portré
            anode = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/portrait.mdl"));
            anode.Position = new Vector3Df(-1177.601f, -137.975f, -1238.015f);
            anode.Rotation = new Vector3Df(0,0,0);
            anode.Scale = new Vector3Df(3);
            anode.AnimationSpeed = 1500;
            anode.SetMaterialFlag(MaterialFlag.Lighting, true);
            anode.GetMaterial(0).NormalizeNormals = true;
            anode.GetMaterial(0).Lighting = false;

            AnimatedMeshSceneNode anode4 = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/waiter.mdl"));
            anode4.Position = new Vector3Df(-1130, -375, -1724);
            anode4.Rotation = new Vector3Df(0, -90, 0);
            anode4.Scale = new Vector3Df(2, 2, 2);
            anode4.SetMaterialFlag(MaterialFlag.Lighting, false);
            Scenes.changeAnimation(anode4, 0, 1);

            //Egér elrejtése
            device.CursorControl.Visible = false;
            GUIFont font = device.GUIEnvironment.BuiltInFont;
            SceneCollisionManager collMan = smgr.SceneCollisionManager;
            TextSceneNode headcrabName = smgr.AddTextSceneNode(font, "Yodan Lebegö Headcrab-je <Level 10>", new Color(255, 255, 0), null, anode3.Position + new Vector3Df(0, 25, 0), 0);
            TextSceneNode waiterName = smgr.AddTextSceneNode(font, "John <Level 15>", new Color(0, 255, 0), null, anode4.Position + new Vector3Df(0, 125, 0), 0);
            uint then = device.Timer.Time;
            float MOVEMENT_SPEED = 100.0f;

            //Energiagömb
            /*AnimatedMeshSceneNode anode5 = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("./Content/3D/core.mdl"));
            anode5.Position = new Vector3Df(-1355, 0, -1410);
            Scenes.changeAnimation(anode5, 0, 90);
            anode5.Scale = new Vector3Df(2.0f);
            Line3Df coreray = new Line3Df(-1355, 0, -1410, -1355, -500, -1410);
            driver.SetMaterial(anode5.GetMaterial(1));
            driver.SetTransform(TransformationState.World, Matrix.Identity);
            driver.Draw3DLine(coreray, new Color(255,0,0));*/

            GUIImage bartenderForm = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/bartender.png"), new Vector2Di(10, 10));
            bartenderForm.ScaleImage = true;
            bartenderForm.Visible = false;
            bartenderForm.SetMinSize(new Dimension2Di(sizex - 10, sizey - 10));
            bartenderForm.SetMaxSize(new Dimension2Di(sizex - 10, sizey - 10));
            bool BartenderFormIsOpen = false;
            GUIImage ActionBar = device.GUIEnvironment.AddImage(driver.GetTexture("./Content/2D/Hud/Actionbar.tga"), new Vector2Di(0, 600 - 128));
            //330, 110  790, 120
            Recti expbarrect = new Recti();
            ExperienceBar expbar = new ExperienceBar(gui, expbarrect,0, ActionBar);
            expbar.SetProgress(0);
            expbar.SetColors(new Color(255, 255, 0), new Color(255, 255, 255));
            expbar.AddBorder(5, new Color(0, 0, 0));
            expbar.SetMinSize(new Dimension2Di(128, 64));
            expbar.SetMaxSize(new Dimension2Di(128, 64));
            //Mi minek a része
            q3node.AddChild(anode);
            q3node.AddChild(anode2);
            q3node.AddChild(anode3);
            q3node.AddChild(anode4);
            TextSceneNode yodanName = smgr.AddTextSceneNode(font, "Yodan a Bérgyilkos <Level 90>", new Color(255, 0, 0), null, anode2.Position + new Vector3Df(0, 50, 0), 0);
            while (device.Run())
            {
                driver.BeginScene(true, true, new Color(135, 206, 235));

                smgr.DrawAll();
                gui.DrawAll();
                string printDate = dateTime.ToShortTimeString();
                uint now = device.Timer.Time;
                float frameDeltaTime = (float)(now - then) / 1000.0f;
                then = now;
                Vector3Df nodePosition = camera.Position;
                if (font != null)
                {
                    /*font.Draw("Build " + Property.modVersion, 5, 5, new Color(0, 0, 255));
                    font.Draw("pos= " + camera.Position, 5, 578 - 16, new Color(0, 0, 255));
                    font.Draw("tar= " + camera.Target, 5, 594 - 16, new Color(0, 0, 255));*/
                    font.Draw(Player.Experience(), new Vector2Di(505, 582), new Color(0,0,0));
                }
                if (camera.Position.Z >= 10000)
                {
                    font.Draw("Kiestél a Világból!", new Vector2Di(400, 300), new Color (0, 0, 0));
                    camera.Position = anode.Position;
                }

                if (Quest1Done)
                {
                    yodanName.SetTextColor(new Color(255, 255, 0));
                }

                if (IsKeyDown(KeyCode.Space))
                {
                    nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
                }
                else if (IsKeyDown(KeyCode.LControl))
                {
                    nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;
                }
                if (IsKeyDown(KeyCode.LShift))
                {
                    MOVEMENT_SPEED = 200.0f;
                }
                else
                {
                    MOVEMENT_SPEED = 100.0f;
                }

                if (IsKeyDown(KeyCode.Esc))
                {
                    copyrightScreen.Visible = true;
                }
                if (IsKeyDown(KeyCode.KeyM))
                {
                    //Yodan.Run(new Vector3Df(-1642, -172, -1421), new Vector3Df(-1053, -167, -1416));
                }
                if (IsKeyDown(KeyCode.KeyB))
                {
                   // Yodan.Wave();

                   Scripting.RunScript(Scripting.LoadScript());
                }
                if (IsKeyDown(KeyCode.KeyV))
                {
                    //Yodan.Speak("./Content/Sound/vo/yodan/yo_20ft.mp3");
                }
                else if (IsKeyDown(KeyCode.KeyN))
                {
                    //Yodan.Stand();
                }
                else if (IsKeyDown(KeyCode.KeyC))
                {
                    //Yodan.WaveAndGreet();
                }
                //Actionbar START

                //Auto-Attack
                if (IsKeyDown(KeyCode.Key1))
                {
                    if (!AutoAttack)
                    {
                        Delay(100);
                        AutoAttack = true;
                        if (currentWeapon == 1)
                        {
                            Scenes.changeAnimation(weapon, 11 + 24 + 25, 11 + 24 + 25 + 31 + 30);
                        }
                        else if (currentWeapon == 2)
                        {
                            Scenes.changeAnimation(weapon, 91 + 31 + 81 + 31, 91 + 31 + 81 + 31+90);
                        }
                    }
                    else if (AutoAttack)
                    {
                        Delay(100);
                        AutoAttack = false;
                        if (currentWeapon == 1)
                        {
                            Scenes.changeAnimation(weapon, 1, 1);
                        }
                        else if (currentWeapon == 2)
                        {
                            Scenes.changeAnimation(weapon, 1, 90);
                        }

                    }
                }
                //Blades
                if (IsKeyDown(KeyCode.Key2))
                 {
                     AnimatedMesh bladesmesh = smgr.GetMesh("./Content/3D/blades.mdl");
                     weapon.Mesh = bladesmesh;
                     weapon.Scale = new Vector3Df(0.5f, 0.5f, 0.5f);
                     weapon.Position = new Vector3Df(0, 0, 15);
                     weapon.Rotation = new Vector3Df(0, -90, 0);
                     Scenes.changeAnimation(weapon, 1, 1);
                     currentWeapon = 1;
                 }
                 //Crossbow
                 if (IsKeyDown(KeyCode.Key3))
                 {
                     AnimatedMesh crossbowmesh = smgr.GetMesh("./Content/3D/crossbow.mdl");
                     weapon.Mesh = crossbowmesh;
                     Scenes.changeAnimation(weapon, 1, 90);
                     weapon.Scale = new Vector3Df(3.0f, 3.0f, 3.0f);
                     currentWeapon = 2;

                 }
                 if (IsKeyDown(KeyCode.Key4))
                 {
                     if (IsEtlapPickedUp)
                     {
                         bartenderForm.Visible = true;
                         BartenderFormIsOpen = true;
                         Audio.playWave("./Content/sound/paper_pickup.mp3");
                     }

                 }

                //Actionbar END

                //elteszi/előveszi a fegyvert
                if(IsKeyDown(KeyCode.Tab))
                {
                    if(weaponHolster)
                    {
                    weapon.Visible = false;
                    Audio.playWave("./Content/sound/weapon.mp3");
                    weaponHolster = false;
                    }
                    else
                    {
                    weapon.Visible = true;
                    Audio.playWave("./Content/sound/weapon.mp3");
                    weaponHolster = true;
                    }
                }
                if (IsKeyDown(KeyCode.MouseLButton))
                {
                    AutoAttack = true;
                    if (currentWeapon == 1)
                    {
                        Scenes.changeAnimation(weapon, 11 + 24 + 25, 11 + 24 + 25 + 31 + 30);
                    }
                    else if (currentWeapon == 2)
                    {
                        Scenes.changeAnimation(weapon, 91 + 31 + 81 + 31, 91 + 31 + 81 + 31 + 90);
                    }
                }
                else if (!IsKeyDown(KeyCode.MouseLButton))
                {
                    AutoAttack = false;
                    if (currentWeapon == 1)
                    {
                        Scenes.changeAnimation(weapon, 1, 1);
                    }
                    else if (currentWeapon == 2)
                    {
                        Scenes.changeAnimation(weapon, 1, 90);
                    }
                }

                if (IsKeyDown(KeyCode.KeyX))
                {
                    Texture yodanMissing = driver.GetTexture("./Content/2D/yodanmissing.tga");
                    Dimension2Di yodanMisSiz = yodanMissing.Size;
                    yodanMisSiz = anode.GetMaterial(0).GetTexture(0).Size;
                    anode.SetMaterialTexture(0, yodanMissing);
                }
                if (IsKeyDown(KeyCode.KeyE))
                {
                    //Bartender Johh On-Use
                    Vector3Df camtarget = camera.Target;
                    if (!BartenderFormIsOpen)
                    {
                        if (new Vector3Df(727, 221, -986) <= camtarget)
                        {
                            if (new Vector3Df(763, 276, -2329) >= camtarget)
                            {
                                if (camtarget > new Vector3Df(184, -1843, -1255))
                                {
                                    if (camtarget > new Vector3Df(138, -1837, -2318))
                                    {
                                        bartenderForm.Visible = true;
                                        BartenderFormIsOpen = true;
                                        if (!IsEtlapPickedUp)
                                        {
                                            ActionBar.Image = driver.GetTexture("./Content/2D/Hud/Actionbar_etlap.tga");
                                            Audio.playWave("./Content/sound/vo/waiter_john/teatime.mp3");
                                        }
                                        IsEtlapPickedUp = true;
                                        Audio.playWave("./Content/sound/paper_pickup.mp3");
                                    }
                                }
                            }
                        }
                    }
                    else if (BartenderFormIsOpen)
                    {
                        bartenderForm.Visible = false;
                        BartenderFormIsOpen = false;
                        Audio.playWave("./Content/sound/paper_pickup.mp3");
                    }
                }

                if (IsKeyDown(KeyCode.KeyK))
                {
                    //Yodan.GoGhost();
                }
                if (IsKeyDown(KeyCode.KeyJ))
                {
                    //Yodan.GoNormal();
                }
                if (IsKeyDown(KeyCode.KeyL))
                {

                }
                if (IsKeyDown(KeyCode.F7))
                {
                    Delay(500);
                    takeScreenshot(device);
                }
                if (IsKeyDown(KeyCode.F9))
                {
                    Delay(500);
                    string campos = camera.Position.ToString();
                    Logger.Log("position:" + campos);
                    string camtar = camera.Target.ToString();
                    Logger.Log("target: " + camtar);
                }
                if (IsKeyDown(KeyCode.LShift))
                {
                    if (IsKeyDown(KeyCode.KeyY))
                    {
                        Environment.Exit(0);
                    } else if (IsKeyDown(KeyCode.KeyN))
                    {
                        copyrightScreen.Visible = false;
                    }
                }

                camera.Position = nodePosition;
                driver.EndScene();
            }
            device.Drop();
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        static void Main()
        {
            bool shadows = AskForRealtimeShadows();

            DriverType?driverType = AskForDriver();

            if (!driverType.HasValue)
            {
                return;
            }

            IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480), 16, false, shadows);

            if (device == null)
            {
                return;
            }

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

            AnimatedMesh mesh = smgr.GetMesh("../../media/room.3ds");

            smgr.MeshManipulator.MakePlanarTextureMapping(mesh.GetMesh(0), 0.004f);

            SceneNode node = smgr.AddAnimatedMeshSceneNode(mesh);

            node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.jpg"));
            node.GetMaterial(0).SpecularColor = new Color(0);

            mesh = smgr.AddHillPlaneMesh("myHill",
                                         new Dimension2Df(20, 20),
                                         new Dimension2Di(40, 40), null, 0,
                                         new Dimension2Df(0),
                                         new Dimension2Df(10, 10));

            node          = smgr.AddWaterSurfaceSceneNode(mesh.GetMesh(0), 3.0f, 300.0f, 30.0f);
            node.Position = new Vector3Df(0, 7, 0);

            node.SetMaterialTexture(0, driver.GetTexture("../../media/stones.jpg"));
            node.SetMaterialTexture(1, driver.GetTexture("../../media/water.jpg"));

            node.SetMaterialType(MaterialType.Reflection2Layer);

            // create light

            node = smgr.AddLightSceneNode(null, new Vector3Df(0), new Colorf(1.0f, 0.6f, 0.7f, 1.0f), 800);
            SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 250);

            node.AddAnimator(anim);
            anim.Drop();

            // attach billboard to light

            node = smgr.AddBillboardSceneNode(node, new Dimension2Df(50, 50));
            node.SetMaterialFlag(MaterialFlag.Lighting, false);
            node.SetMaterialType(MaterialType.TransparentAddColor);
            node.SetMaterialTexture(0, driver.GetTexture("../../media/particlewhite.bmp"));

            // create a particle system

            ParticleSystemSceneNode ps = smgr.AddParticleSystemSceneNode(false);

            if (ps != null)
            {
                ParticleEmitter em = ps.CreateBoxEmitter(
                    new AABBox(-7, 0, -7, 7, 1, 7),   // emitter size
                    new Vector3Df(0.0f, 0.06f, 0.0f), // initial direction
                    80, 100,                          // emit rate
                    new Color(255, 255, 255, 0),      // darkest color
                    new Color(255, 255, 255, 0),      // brightest color
                    800, 2000, 0,                     // min and max age, angle
                    new Dimension2Df(10.0f),          // min size
                    new Dimension2Df(20.0f));         // max size

                ps.Emitter = em;                      // this grabs the emitter
                em.Drop();                            // so we can drop it here without deleting it

                ParticleAffector paf = ps.CreateFadeOutParticleAffector();

                ps.AddAffector(paf);                 // same goes for the affector
                paf.Drop();

                ps.Position = new Vector3Df(-70, 60, 40);
                ps.Scale    = new Vector3Df(2);
                ps.SetMaterialFlag(MaterialFlag.Lighting, false);
                ps.SetMaterialFlag(MaterialFlag.ZWrite, false);
                ps.SetMaterialTexture(0, driver.GetTexture("../../media/fire.bmp"));
                ps.SetMaterialType(MaterialType.TransparentAddColor);
            }

            VolumeLightSceneNode n = smgr.AddVolumeLightSceneNode(null, -1,
                                                                  32,                          // Subdivisions on U axis
                                                                  32,                          // Subdivisions on V axis
                                                                  new Color(255, 255, 255, 0), // foot color
                                                                  new Color(0, 0, 0, 0));      // tail color

            if (n != null)
            {
                n.Scale    = new Vector3Df(56);
                n.Position = new Vector3Df(-120, 50, 40);

                // load textures for animation
                List <Texture> textures = new List <Texture>();
                for (int i = 7; i > 0; i--)
                {
                    string s = string.Format("../../media/portal{0}.bmp", i);
                    textures.Add(driver.GetTexture(s));
                }

                // create texture animator
                SceneNodeAnimator glow = smgr.CreateTextureAnimator(textures, 0.150f);

                // add the animator
                n.AddAnimator(glow);

                // drop the animator because it was created with a create() function
                glow.Drop();
            }

            // add animated character

            mesh = smgr.GetMesh("../../media/dwarf.x");
            AnimatedMeshSceneNode anode = smgr.AddAnimatedMeshSceneNode(mesh);

            anode.Position       = new Vector3Df(-50, 20, -60);
            anode.AnimationSpeed = 15;

            // add shadow
            anode.AddShadowVolumeSceneNode();
            smgr.ShadowColor = new Color(0, 0, 0, 150);

            // make the model a little bit bigger and normalize its normals
            // because of the scaling, for correct lighting
            anode.Scale = new Vector3Df(2);
            anode.SetMaterialFlag(MaterialFlag.NormalizeNormals, true);

            CameraSceneNode camera = smgr.AddCameraSceneNodeFPS();

            camera.Position = new Vector3Df(-50, 50, -150);

            // disable mouse cursor
            device.CursorControl.Visible = false;

            int lastFPS = -1;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    driver.BeginScene(ClearBufferFlag.All, new Color(0));
                    smgr.DrawAll();
                    driver.EndScene();

                    int fps = driver.FPS;
                    if (lastFPS != fps)
                    {
                        device.SetWindowCaption(String.Format(
                                                    "SpecialFX example - Irrlicht Engine [{0}] fps: {1}",
                                                    driver.Name, fps));

                        lastFPS = fps;
                    }
                }
            }

            device.Drop();
        }
Exemplo n.º 9
0
        /// <summary>
        /// The irrlicht thread for rendering.
        /// </summary>
        private void StartIrr()
        {
            try
            {
                IrrlichtCreationParameters irrparam = new IrrlichtCreationParameters();
                if (irrlichtPanel.IsDisposed)
                {
                    throw new Exception("Form closed!");
                }
                if (irrlichtPanel.InvokeRequired)
                {
                    irrlichtPanel.Invoke(new MethodInvoker(delegate { irrparam.WindowID = irrlichtPanel.Handle; }));
                }
                irrparam.DriverType   = DriverType.Direct3D9;
                irrparam.BitsPerPixel = 16;

                device = IrrlichtDevice.CreateDevice(irrparam);

                if (device == null)
                {
                    throw new NullReferenceException("Could not create device for engine!");
                }

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

                var animText = "";
                if (Animations.AnimationNames.Count > 0)
                {
                    animText = "Animation: " + Animations.AnimationNames[selectedAnimIdx].Key;
                }
                var mAnimText     = gui.AddStaticText(animText, new Recti(0, this.ClientSize.Height - 80, 100, this.ClientSize.Height - 70));
                var mPositionText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 70, 100, this.ClientSize.Height - 60));
                var mRotationText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 60, 100, this.ClientSize.Height - 50));
                var fpsText       = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 50, 100, this.ClientSize.Height - 40));
                var infoText      = gui.AddStaticText("[Space] - Reset\n[LMouse] - Rotate\n[MMouse] - Move\n[Wheel] - Zoom", new Recti(0, this.ClientSize.Height - 40, 100, this.ClientSize.Height));
                mAnimText.OverrideColor   = mPositionText.OverrideColor = mRotationText.OverrideColor = fpsText.OverrideColor = infoText.OverrideColor = new Color(255, 255, 255);
                mAnimText.BackgroundColor = mPositionText.BackgroundColor = mRotationText.BackgroundColor = fpsText.BackgroundColor = infoText.BackgroundColor = new Color(0, 0, 0);

                SkinnedMesh skinnedMesh = smgr.CreateSkinnedMesh();
                foreach (var meshBuffer in cdata.staticMesh.MeshBuffers)
                {
                    skinnedMesh.AddMeshBuffer(meshBuffer);
                }
                smgr.MeshManipulator.RecalculateNormals(skinnedMesh);
                if (RigFile != null)
                {
                    rig.Apply(skinnedMesh);
                    if (AnimFile != null)
                    {
                        anims.Apply(skinnedMesh);
                    }
                }
                skinnedMesh.SetDirty(HardwareBufferType.VertexAndIndex);
                skinnedMesh.FinalizeMeshPopulation();
                AnimatedMeshSceneNode node = smgr.AddAnimatedMeshSceneNode(skinnedMesh);

                if (node == null)
                {
                    throw new Exception("Could not load file!");
                }

                node.Scale = new Vector3Df(3.0f);
                node.SetMaterialFlag(MaterialFlag.Lighting, false);
                SetMaterials(driver, node);

                CameraSceneNode camera = smgr.AddCameraSceneNode(null, new Vector3Df(node.BoundingBox.Radius * 8, node.BoundingBox.Radius, 0), new Vector3Df(0, node.BoundingBox.Radius, 0));
                camera.NearValue = 0.001f;
                camera.FOV       = 45 * CommonData.PI_OVER_180;
                scaleMul         = node.BoundingBox.Radius / 4;

                var viewPort = driver.ViewPort;
                var lineMat  = new Material();
                lineMat.Lighting = false;

                while (device.Run())
                {
                    driver.ViewPort = viewPort;
                    driver.BeginScene(ClearBufferFlag.All, new Color(100, 101, 140));

                    node.Position         = modelPosition;
                    node.Rotation         = modelAngle;
                    node.DebugDataVisible = DebugSceneType.Skeleton | DebugSceneType.BBox;
                    mPositionText.Text    = $"X: {modelPosition.X.ToString("F2")} Y: {modelPosition.Y.ToString("F2")} Z: {modelPosition.Z.ToString("F2")}";
                    mRotationText.Text    = $"Yaw: {modelAngle.Y.ToString("F2")} Roll: {modelAngle.Z.ToString("F2")}";
                    fpsText.Text          = $"FPS: {driver.FPS}";

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

                    driver.ViewPort = new Recti(this.ClientSize.Width - 100, this.ClientSize.Height - 80, this.ClientSize.Width, this.ClientSize.Height);
                    //driver.ClearBuffers(ClearBufferFlag.None);

                    driver.SetMaterial(lineMat);
                    var matrix = new Matrix(new Vector3Df(0, 0, 0), modelAngle);
                    driver.SetTransform(TransformationState.World, matrix);
                    matrix = matrix.BuildProjectionMatrixOrthoLH(100, 80, camera.NearValue, camera.FarValue);
                    driver.SetTransform(TransformationState.Projection, matrix);
                    matrix = matrix.BuildCameraLookAtMatrixLH(new Vector3Df(50, 0, 0), new Vector3Df(0, 0, 0), new Vector3Df(0, 1f, 0));
                    driver.SetTransform(TransformationState.View, matrix);
                    driver.Draw3DLine(0, 0, 0, 30f, 0, 0, Color.OpaqueGreen);
                    driver.Draw3DLine(0, 0, 0, 0, 30f, 0, Color.OpaqueBlue);
                    driver.Draw3DLine(0, 0, 0, 0, 0, 30f, Color.OpaqueRed);

                    driver.EndScene();
                }

                device.Drop();
            }
            catch (ThreadAbortException) { }
            catch (NullReferenceException) { }
            catch (Exception ex)
            {
                if (!this.IsDisposed)
                {
                    MessageBox.Show(ex.Message);
                    //this.Invoke(new MethodInvoker(delegate { this.Close(); }));
                }
            }
        }
Exemplo n.º 10
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 smgr   = device.SceneManager;

            SceneNode node = smgr.AddSphereSceneNode();

            if (node != null)
            {
                node.Position = new Vector3Df(0, 0, 30);
                node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp"));
                node.SetMaterialFlag(MaterialFlag.Lighting, false);
            }

            SceneNode n = smgr.AddCubeSceneNode();

            if (n != null)
            {
                n.SetMaterialTexture(0, driver.GetTexture("../../media/t351sml.jpg"));
                n.SetMaterialFlag(MaterialFlag.Lighting, false);

                SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 0, 30), 20.0f);
                if (anim != null)
                {
                    n.AddAnimator(anim);
                    anim.Drop();
                }
            }

            AnimatedMeshSceneNode anms = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/ninja.b3d"));

            if (anms != null)
            {
                SceneNodeAnimator anim = smgr.CreateFlyStraightAnimator(
                    new Vector3Df(100, 0, 60), new Vector3Df(-100, 0, 60), 3.5f, true);
                if (anim != null)
                {
                    anms.AddAnimator(anim);
                    anim.Drop();
                }

                anms.SetMaterialFlag(MaterialFlag.Lighting, false);

                anms.SetFrameLoop(0, 13);
                anms.AnimationSpeed = 15;

                anms.Scale    = new Vector3Df(2);
                anms.Rotation = new Vector3Df(0, -90, 0);
            }

            smgr.AddCameraSceneNodeFPS();
            device.CursorControl.Visible = false;

            device.GUIEnvironment.AddImage(
                driver.GetTexture("../../media/irrlichtlogoalpha2.tga"),
                new Vector2Di(10, 20));

            int lastFPS = -1;

            uint then = device.Timer.Time;

            const float MOVEMENT_SPEED = 5.0f;

            while (device.Run())
            {
                uint  now            = device.Timer.Time;
                float frameDeltaTime = (float)(now - then) / 1000.0f;
                then = now;

                Vector3Df nodePosition = node.Position;

                if (IsKeyDown(KeyCode.KeyW))
                {
                    nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
                }
                else if (IsKeyDown(KeyCode.KeyS))
                {
                    nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;
                }

                if (IsKeyDown(KeyCode.KeyA))
                {
                    nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
                }
                else if (IsKeyDown(KeyCode.KeyD))
                {
                    nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;
                }

                node.Position = nodePosition;

                driver.BeginScene(ClearBufferFlag.All, new Color(113, 113, 113));
                smgr.DrawAll();
                device.GUIEnvironment.DrawAll();
                driver.EndScene();

                int fps = driver.FPS;
                if (lastFPS != fps)
                {
                    device.SetWindowCaption(String.Format(
                                                "Movement example - Irrlicht Engine [{0}] fps: {1}",
                                                driver.Name, fps));

                    lastFPS = fps;
                }
            }

            device.Drop();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            DriverType driverType;

            if (!AskUserForDriver(out driverType))
            {
                return;
            }

            IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(ResX, ResY), 32, fullScreen);

            if (device == null)
            {
                return;
            }

            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);
            VideoDriver  driver = device.VideoDriver;
            SceneManager smgr   = device.SceneManager;

            // load model
            AnimatedMesh model = smgr.GetMesh("../../media/sydney.md2");

            if (model == null)
            {
                return;
            }

            AnimatedMeshSceneNode model_node = smgr.AddAnimatedMeshSceneNode(model);

            // load texture
            if (model_node != null)
            {
                Texture texture = driver.GetTexture("../../media/sydney.bmp");
                model_node.SetMaterialTexture(0, texture);
                model_node.SetMD2Animation(AnimationTypeMD2.Run);
                model_node.SetMaterialFlag(MaterialFlag.Lighting, false);
            }

            // load map
            device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3");
            AnimatedMesh map = smgr.GetMesh("20kdm2.bsp");

            if (map != null)
            {
                SceneNode map_node = smgr.AddOctreeSceneNode(map.GetMesh(0));
                map_node.Position = new Vector3Df(-850, -220, -850);
            }

            // create 3 fixed and one user-controlled cameras
            camera[0]          = smgr.AddCameraSceneNode(null, new Vector3Df(50, 0, 0), new Vector3Df(0)); // font
            camera[1]          = smgr.AddCameraSceneNode(null, new Vector3Df(0, 50, 0), new Vector3Df(0)); // top
            camera[2]          = smgr.AddCameraSceneNode(null, new Vector3Df(0, 0, 50), new Vector3Df(0)); // left
            camera[3]          = smgr.AddCameraSceneNodeFPS();                                             // user-controlled
            camera[3].Position = new Vector3Df(-50, 0, -50);

            device.CursorControl.Visible = false;

            int lastFPS = -1;

            while (device.Run())
            {
                // set the viewpoint to the whole screen and begin scene
                driver.ViewPort = new Recti(0, 0, ResX, ResY);
                driver.BeginScene(true, true, new Color(100, 100, 100));

                if (splitScreen)
                {
                    smgr.ActiveCamera = camera[0];
                    driver.ViewPort   = new Recti(0, 0, ResX / 2, ResY / 2);                   // top left
                    smgr.DrawAll();

                    smgr.ActiveCamera = camera[1];
                    driver.ViewPort   = new Recti(ResX / 2, 0, ResX, ResY / 2);                   // top right
                    smgr.DrawAll();

                    smgr.ActiveCamera = camera[2];
                    driver.ViewPort   = new Recti(0, ResY / 2, ResX / 2, ResY);                   // bottom left
                    smgr.DrawAll();

                    driver.ViewPort = new Recti(ResX / 2, ResY / 2, ResX, ResY);                     // bottom right
                }

                smgr.ActiveCamera = camera[3];
                smgr.DrawAll();

                driver.EndScene();

                int fps = driver.FPS;
                if (lastFPS != fps)
                {
                    device.SetWindowCaption(String.Format(
                                                "Split Screen example - Irrlicht Engine [{0}] fps: {1}",
                                                driver.Name, fps));

                    lastFPS = fps;
                }
            }

            device.Drop();
        }
Exemplo n.º 12
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.");
            }

            dev.Logger.LogLevel = LogLevel.Warning;
            VideoDriver  drv  = dev.VideoDriver;
            SceneManager smgr = dev.SceneManager;

            smgr.FileSystem.AddFileArchive("E:/WitcherMods/modTest/Test/files/Mod/Bundle");
            smgr.FileSystem.AddFileArchive("E:/WitcherMods/modTest/Test/files/Raw/Mod/TextureCache");

            smgr.Attributes.AddValue("TW_TW3_LOAD_SKEL", true);
            smgr.Attributes.AddValue("TW_TW3_LOAD_BEST_LOD_ONLY", true);

            // setup a simple 3d scene

            //CameraSceneNode cam = smgr.AddCameraSceneNode();
            //cam.Target = new Vector3Df(0);

            // added by vl
            AnimatedMesh mesh = smgr.GetMesh("E:/WitcherMods/modTest/Test/files/Mod/Bundle/characters/models/animals/cat/model/t_01__cat.w2mesh");

            if (mesh == null)
            {
                throw new Exception("Failed to load mesh.");
            }

            smgr.MeshManipulator.RecalculateNormals(mesh);

            List <String> animList = null;

            float scaleMul               = 1.0f;
            AnimatedMeshSceneNode node   = smgr.AddAnimatedMeshSceneNode(mesh);
            MeshLoaderHelper      helper = smgr.GetMeshLoader(smgr.MeshLoaderCount - 1).getMeshLoaderHelper();

            if (node != null)
            {
                scaleMul   = node.BoundingBox.Radius / 4;
                node.Scale = new Vector3Df(3.0f);
                node.SetMaterialFlag(MaterialFlag.Lighting, false);

                SkinnedMesh sm = helper.loadRig("E:/WitcherMods/modTest/Test/files/Mod/Bundle/characters/base_entities/cat_base/cat_base.w2rig", mesh);
                if (sm == null)
                {
                    throw new Exception("Failed to load rig.");
                }

                animList = helper.loadAnimation("E:/WitcherMods/modTest/Test/files/Mod/Bundle/animations/animals/cat/cat_animation.w2anims", sm);
                if (animList.Count > 0)
                {
                    AnimatedMesh am = helper.applyAnimation(animList[0], sm);
                    node.Mesh = am;
                }
                //scaleSkeleton(sm, 3.0f);
                //sm.SkinMesh();

                mesh.Drop();
                sm.Drop();
                setMaterialsSettings(node);

                /*
                 * animList = helper.loadAnimation("E:/WitcherMods/modTest/Test/files/Mod/Bundle/animations/animals/cat/cat_animation.w2anims", node);
                 * if (animList.Count > 0)
                 * {
                 *      helper.applyAnimation(animList[0]);
                 * }
                 */
            }

            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;

            node.DebugDataVisible ^= DebugSceneType.BBox | DebugSceneType.Skeleton;

            node.Position = new Vector3Df(0.0f);

            /*
             * 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(ClearBufferFlag.Depth);
                }
                else
                {
                    drv.BeginScene(ClearBufferFlag.Depth | ClearBufferFlag.Color, 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();
        }