示例#1
0
        static bool device_OnEvent(Event evnt)
        {
            if (evnt.Type == EventType.Key &&
                evnt.Key.PressedDown)
            {
                switch (evnt.Key.Key)
                {
                case KeyCode.Space:
                    simPaused = !simPaused;
                    return(true);

                case KeyCode.KeyT:
                    useTrails = !useTrails;
                    return(true);
                }
            }

            if (evnt.Type == EventType.Mouse)
            {
                if (evnt.Mouse.IsLeftPressed())
                {
                    if (!mouseCanShoot)
                    {
                        return(true);
                    }

                    MeshSceneNode n = device.SceneManager.AddSphereSceneNode(sphereRadius);
                    n.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/wall.bmp"));
                    n.SetMaterialFlag(MaterialFlag.Lighting, false);

                    Vector3Df v = (device.SceneManager.ActiveCamera.Target - device.SceneManager.ActiveCamera.Position).Normalize();
                    n.Position = device.SceneManager.ActiveCamera.Position + v * 100;

                    if (useTrails)
                    {
                        particles.Add(n, device.Timer.Time);
                    }

                    physics.AddShape(Physics.Shape.Shpere, n, sphereMass, false, v * cubeMass * 10000);

                    mouseCanShoot = false;
                    return(true);
                }
                else
                {
                    mouseCanShoot = true;
                }
            }

            return(false);
        }
示例#2
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();
        }
示例#3
0
        static void openFolder(string newFolder)
        {
            textureManager.Stop();
            textureManager.Start(TextureManagerThreadCount);
            textureManager.EnqueueUnloadingOfAllLoadedTextures();
            animationManager.Clear();
            previewPlateInfo.Clear();

            irr.GUI.RootElement.GetElementFromID(CurrentFolderStaticTextId).Text = newFolder;

            SceneNode p = irr.Scene.GetSceneNodeFromID(PreviewRootNodeId);

            p.RemoveChildren();

            int   r = 10;
            float x = 0, z = 0;
            Mesh  m = irr.Scene.MeshCache.GetMesh(PreviewPlateMeshName);

            string[] f = Directory.GetFiles(newFolder, "*.*", SearchOption.TopDirectoryOnly);
            for (int i = 0; i < f.Length; i++)
            {
                x += PreviewPlateSize * 1.1f;
                if ((i % r) == 0)
                {
                    x  = 0;
                    z += PreviewPlateSize * 1.1f;
                }

                MeshSceneNode n = irr.Scene.AddMeshSceneNode(m, p, i | PreviewPlateNodeIdFlag);
                n.SetMaterialFlag(MaterialFlag.Lighting, false);
                n.Position = new Vector3Df(x, 1000, z);

                textureManager.LoadTexture(n, f[i], PreviewTextureSize);

                TriangleSelector s = irr.Scene.CreateTriangleSelector(n.Mesh, n);
                n.TriangleSelector = s;
                s.Drop();

                previewPlateInfo.Add(n.ID, Path.GetFileName(f[i]));
            }

            irr.Scene.ActiveCamera.Position = new Vector3Df(PreviewPlateSize * (r - 1) * 1.1f / 2, 6 * PreviewPlateSize, 0);
            irr.Scene.ActiveCamera.Target   = new Vector3Df(irr.Scene.ActiveCamera.Position.X, 0, PreviewPlateSize * 5);
            maxScrollPosition = (f.Length / r) * PreviewPlateSize * 1.1f;

            tasksAddedToTextureManager = textureManager.GetCommandQueueLength();
        }
示例#4
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);
        }
示例#5
0
        static bool Device_OnEvent(Event evnt)
        {
            if (evnt.Type == EventType.GUI &&
                evnt.GUI.Type == GUIEventType.ButtonClicked &&
                evnt.GUI.Caller.ID == ChooseFolderButtonId)
            {
                wantChangeFolder = true;
                return(true);
            }

            if (evnt.Type == EventType.Mouse &&
                evnt.Mouse.Type == MouseEventType.Wheel &&
                selectedNode == null)
            {
                Vector3Df p = irr.Scene.ActiveCamera.Position;
                Vector3Df t = irr.Scene.ActiveCamera.Target;
                float     s = irr.Scene.ActiveCamera.Position.Z + evnt.Mouse.Wheel * 16;

                if (s < 0)
                {
                    s = 0;
                }

                if (s > maxScrollPosition)
                {
                    s = maxScrollPosition;
                }

                t.Z = t.Z - p.Z + s;
                p.Z = s;

                irr.Scene.ActiveCamera.Position = p;
                irr.Scene.ActiveCamera.Target   = t;

                return(true);
            }

            if (evnt.Type == EventType.Mouse &&
                evnt.Mouse.Type == MouseEventType.Move &&
                selectedNode == null)
            {
                SceneNode n =
                    irr.Scene.SceneCollisionManager.GetSceneNodeFromScreenCoordinatesBB(
                        new Vector2Di(evnt.Mouse.X, evnt.Mouse.Y),
                        0,
                        irr.Scene.GetSceneNodeFromID(PreviewRootNodeId));

                if (hoveredNode != n)
                {
                    if (hoveredNode != null)
                    {
                        animationManager.Remove(hoveredNode);

                        animationManager.Add(
                            hoveredNode,
                            500,
                            new Vector3Df(hoveredNode.Position.X, hoveredNode.Position.Y - 15, hoveredNode.Position.Z),
                            new Vector3Df(0),
                            hoveredNode.Scale / 1.5f);
                    }

                    if (n != null)
                    {
                        animationManager.Remove(n);

                        animationManager.Add(
                            n,
                            40,
                            new Vector3Df(n.Position.X, n.Position.Y + 15, n.Position.Z),
                            new Vector3Df(-20, 0, 0),
                            n.Scale * 1.5f);
                    }

                    hoveredNode = n;
                }

                return(true);
            }

            if (evnt.Type == EventType.Mouse &&
                evnt.Mouse.Type == MouseEventType.LeftUp &&
                hoveredNode != null &&
                (hoveredNode.ID & SelectableNodeIdFlag) == SelectableNodeIdFlag &&
                selectedNode == null)
            {
                animationManager.Remove(hoveredNode);

                Mesh          m = irr.Scene.MeshCache.GetMesh(PreviewPlateMeshName);
                MeshSceneNode n = irr.Scene.AddMeshSceneNode(m);
                n.SetMaterialFlag(MaterialFlag.Lighting, false);
                n.Position = hoveredNode.Position;
                n.Rotation = hoveredNode.Rotation;
                n.Scale    = hoveredNode.Scale;

                string t = hoveredNode.GetMaterial(0).GetTexture(0).Name.Path.Split('|')[0];

                Dimension2Di d = new Dimension2Di(2048);
                if (d.Area > irr.Driver.MaxTextureSize.Area)
                {
                    d = irr.Driver.MaxTextureSize;
                }

                n.SetMaterialTexture(0, hoveredNode.GetMaterial(0).GetTexture(0));
                textureManager.LoadTexture(n, t, d, true);

                animationManager.Add(
                    n,
                    200,
                    irr.Scene.ActiveCamera.AbsolutePosition + new Vector3Df(0, -48, 40), // TODO: this magic numbers should be calculated somehow
                    new Vector3Df(-39.85f, 0, 0),                                        // using current active camera info (like view matrix or projection one)
                    n.Scale * ((irr.Scene.ActiveCamera.FOV - 0.125f) / n.Scale.Z));

                selectedNode        = n;
                hoveredNode.Visible = false;
                irr.GUI.RootElement.GetElementFromID(ChooseFolderButtonId).Enabled = false;

                return(true);
            }

            if (evnt.Type == EventType.Mouse &&
                evnt.Mouse.Type == MouseEventType.LeftUp &&
                selectedNode != null &&
                selectedNode.GetMaterial(0).GetTexture(0) != hoveredNode.GetMaterial(0).GetTexture(0))
            {
                if (animationManager.IsAnimated(selectedNode))
                {
                    return(true);
                }

                Texture t = selectedNode.GetMaterial(0).GetTexture(0);
                if (t != null)
                {
                    string s = t.Name.Path;
                    selectedNode.SetMaterialTexture(0, null);
                    textureManager.UnloadTexture(s);
                }

                selectedNode.Remove();
                selectedNode = null;

                hoveredNode.Visible = true;
                irr.GUI.RootElement.GetElementFromID(ChooseFolderButtonId).Enabled = true;

                return(true);
            }

            if (evnt.Type == EventType.Log &&
                evnt.Log.Text.StartsWith("Resizing window"))
            {
                wantUpdateActiveCameraAspectRatio = true;
            }

            return(false);
        }
示例#6
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();
        }
示例#7
0
        static void Main(string[] args)
        {
            checkBulletSharpDllPresence();

            // setup Irrlicht

            device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1024, 768));
            if (device == null)
            {
                return;
            }

            device.SetWindowCaption("BulletSharp Test - Irrlicht Engine");
            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);

            VideoDriver  driver = device.VideoDriver;
            SceneManager scene  = device.SceneManager;
            GUIFont      font   = device.GUIEnvironment.GetFont("../../media/fontlucida.png");

            CameraSceneNode camera = scene.AddCameraSceneNodeFPS();

            camera.Position         = new Vector3Df(100, 800, -1000);
            camera.Target           = new Vector3Df(0, 100, 0);
            camera.FarValue         = 30000;
            camera.AutomaticCulling = CullingType.FrustumBox;

            device.CursorControl.Visible = false;

            // setup physics

            physics = new Physics();
            physics.Setup(new Vector3Df(0, -worldGravity, 0));

            // setup particles

            particles = new Particles(device);

            // load quake level

            device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3");

            Mesh      mesh       = scene.GetMesh("20kdm2.bsp").GetMesh(0);
            SceneNode quakeLevel = scene.AddOctreeSceneNode(mesh, null, -1, 1024);

            quakeLevel.Position = new Vector3Df(-1300, -144, -1249);

            physics.AddShape(Physics.Shape.Mesh, quakeLevel);

            // generate dynamic objects

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 30; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        MeshSceneNode n = scene.AddCubeSceneNode(cubeSize);
                        n.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp"));
                        n.SetMaterialFlag(MaterialFlag.Lighting, false);
                        n.Position = new Vector3Df(70 + i * cubeSize, 520 + j * cubeSize, -650 + k * cubeSize);

                        physics.AddShape(Physics.Shape.Box, n, cubeMass);
                    }
                }
            }

            // main loop

            uint curTime       = 0;
            uint lastTime      = 0;
            int  simFps        = 0;
            int  simFrames     = 0;
            uint simFramesTime = 0;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    // simulate physics

                    lastTime = curTime;
                    curTime  = device.Timer.Time;
                    if (!simPaused)
                    {
                        float deltaTime = (curTime - lastTime) / 1000.0f;
                        bool  b         = physics.StepSimulation(deltaTime);
                        if (b)
                        {
                            simFrames++;
                        }
                    }

                    if (curTime - simFramesTime > 1000)
                    {
                        simFramesTime = curTime;
                        simFps        = simFrames;
                        simFrames     = 0;
                    }

                    // winnow particles

                    particles.Winnow(curTime, simPaused);

                    // render scene

                    driver.BeginScene(true, true, new Color(40, 80, 160));
                    scene.DrawAll();

                    Material material = new Material();
                    material.Lighting = false;
                    device.VideoDriver.SetMaterial(material);

                    // display stats

                    driver.Draw2DRectangle(new Recti(10, 10, 140, 180), new Color(0x7f000000));

                    Vector2Di v = new Vector2Di(20, 20);
                    font.Draw("Rendering", v, Color.OpaqueYellow);
                    v.Y += 16;
                    font.Draw(scene.Attributes.GetValue("calls") + " nodes", v, Color.OpaqueWhite);
                    v.Y += 16;
                    font.Draw(driver.FPS + " fps", v, Color.OpaqueWhite);
                    v.Y += 16;
                    font.Draw("[T]rails " + (useTrails ? "ON" : "OFF"), v, Color.OpaqueGreen);
                    v.Y += 32;
                    font.Draw("Physics" + (simPaused ? " (paused)" : ""), v, Color.OpaqueYellow);
                    v.Y += 16;
                    font.Draw(physics.NumCollisionObjects + " shapes", v, Color.OpaqueWhite);
                    v.Y += 16;
                    font.Draw(simFps + " fps", v, Color.OpaqueWhite);
                    v.Y += 16;
                    font.Draw("[Space] to pause", v, Color.OpaqueGreen);

                    driver.EndScene();
                }

                device.Yield();
            }

            // drop

            physics.Drop();
            device.Drop();
        }
示例#8
0
        public Jeu()
        {
            Device = IrrlichtDevice.CreateDevice(
                DriverType.Direct3D9,
                new Dimension2Di(800, 600),
                32, false, false, true);

            Device.SetWindowCaption("Canardstein 3D");
            Device.OnEvent += Evenement;

            Audio = new ISoundEngine();

            for (int i = 0; i < 3; i++)
            {
                TexturePistolet[i] = Device.VideoDriver.GetTexture(@"Textures\pistolet" + i.ToString() + ".png");
            }

            for (int i = 0; i < 7; i++)
            {
                TextureGarde[i] = Device.VideoDriver.GetTexture(@"Textures\nazi" + i.ToString("00") + ".png");
            }

            TextureMur     = Device.VideoDriver.GetTexture(@"Textures\mur.png");
            TextureMurDeco = Device.VideoDriver.GetTexture(@"Textures\mur_deco.png");
            TextureSol     = Device.VideoDriver.GetTexture(@"Textures\sol.png");
            TexturePlafond = Device.VideoDriver.GetTexture(@"Textures\plafond.png");
            TexturePolice  = Device.VideoDriver.GetTexture(@"Textures\police.png");

            using (Bitmap carte = (Bitmap)System.Drawing.Image.FromFile(@"Textures\carte.png"))
            {
                for (int x = 0; x < 32; x++)
                {
                    for (int y = 0; y < 32; y++)
                    {
                        System.Drawing.Color col = carte.GetPixel(x, y);
                        Murs[x, y] = false;

                        if ((col.R == 255) && (col.G == 255) && (col.B == 255))
                        {
                            SceneNode cube = Device.SceneManager.AddCubeSceneNode(1, null, 0, new Vector3Df(x, 0, y));
                            cube.SetMaterialFlag(MaterialFlag.Lighting, false);
                            cube.SetMaterialFlag(MaterialFlag.Fog, true);
                            cube.SetMaterialTexture(0, TextureMur);
                            Murs[x, y] = true;
                        }
                        else if ((col.R == 0) && (col.G == 0) && (col.B == 255))
                        {
                            SceneNode cube = Device.SceneManager.AddCubeSceneNode(1, null, 0, new Vector3Df(x, 0, y));
                            cube.SetMaterialFlag(MaterialFlag.Lighting, false);
                            cube.SetMaterialFlag(MaterialFlag.Fog, true);
                            cube.SetMaterialTexture(0, TextureMurDeco);
                            Murs[x, y] = true;
                        }
                    }
                }
            }



            //On va maintenant créer un plancher et un plafond, histoire de mettre un peu d'ordre. On commence par générer meshSol,
            //le modèle 3D d'un plan que nous allons nommer « plan » (parce qu'il est obligatoire de fournir un nom), divisé en 32 × 32 cases de taille 1 × 1.
            //On ne va pas lui assigner de texture pour le moment (null). Ce plan sera parfaitement horizontal, avec 0 × 0 variation de hauteur 0.
            //Enfin, la texture sera répétée 32 fois horizontalement et verticalement.
            Mesh meshSol = Device.SceneManager.AddHillPlaneMesh("plan", new Dimension2Df(1, 1), new Dimension2Di(32, 32), null, 0, new Dimension2Df(0, 0), new Dimension2Df(32, 32));

            //On désactive l'éclairage dynamique sur notre nouvel objet, comme on l'avait déjà fait pour le cube, et on lui assigne TextureSol.
            //Puis on le positionne à une distance d'une demi-unité sous le zéro (ou, plus précisément, sous les pieds de notre héros, la position Y de la caméra étant de 0),
            //et à −15.5 sur les axes X et Z (notre plan mesurant 32 par 32 cases de largeur 1, le déplacer de 15,5 unités permet de s'assurer que l'un de ses coins sera à la coordonnée 0,0,
            //ce sera utile dans la prochaine leçon).
            MeshSceneNode sol = Device.SceneManager.AddMeshSceneNode(meshSol);

            sol.SetMaterialFlag(MaterialFlag.Lighting, false);
            sol.SetMaterialFlag(MaterialFlag.Fog, true);
            sol.SetMaterialTexture(0, TextureSol);
            sol.Position = new Vector3Df(15.5f, -0.5f, 15.5f);

            //Pareil pour le plafond, sauf qu'on le place à une hauteur de 0,5 (et non de −0,5), et qu'on le pivote de 180 sur l'axe X pour le tourner vers le bas.
            MeshSceneNode plafond = Device.SceneManager.AddMeshSceneNode(meshSol);

            plafond.SetMaterialFlag(MaterialFlag.Lighting, false);
            plafond.SetMaterialFlag(MaterialFlag.Fog, true);
            plafond.SetMaterialTexture(0, TexturePlafond);
            plafond.Position = new Vector3Df(15.5f, 0.5f, 15.5f);
            plafond.Rotation = new Vector3Df(180, 0, 0);

            CameraSceneNode camera = Device.SceneManager.AddCameraSceneNode(null, new Vector3Df(1, 0, 1), new Vector3Df(2, 0, 1));

            //Abaisse la distance minimum d'affichage de la caméra. La valeur par défaut est de 1, ce qui ne nous convient pas :
            //plafond et sol se trouvant à 0,5 unité de la caméra, ils seraient trop près pour être dessinés.
            camera.NearValue = 0.1f;

            AjouterChose <Ennemi>(3, 3);
            AjouterChose <Ennemi>(6, 12);
            AjouterChose <Ennemi>(12, 12);
            AjouterChose <Ennemi>(20, 6);
            AjouterChose <Ennemi>(28, 16);
            AjouterChose <Ennemi>(11, 27);

            Device.VideoDriver.Fog = new Fog(new IrrlichtLime.Video.Color(138, 125, 81, 0), FogType.Linear, 0, 10);

            ParticleSystemSceneNode part = Device.SceneManager.AddParticleSystemSceneNode(false, null, 0, new Vector3Df(29, -.5f, 30));

            part.SetMaterialFlag(MaterialFlag.Lighting, false);
            ParticleEmitter em = part.CreateBoxEmitter(
                new AABBox(-.5f, 0, -.5f, .5f, 0, .5f),
                new Vector3Df(0.0f, 0.0015f, 0.0f),
                20, 24,
                new IrrlichtLime.Video.Color(0, 128, 255, 0), new IrrlichtLime.Video.Color(0, 255, 255, 0),
                800, 800, 0,
                new Dimension2Df(0.005f, 0.04f), new Dimension2Df(0.01f, 0.08f));

            part.Emitter = em;

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

                if ((AlphaSang > 0) && (Vies > 0))
                {
                    AlphaSang = Math.Max(0, AlphaSang - tempsEcoule * 500);
                }


                if (((int)camera.Position.X == 29) && ((int)camera.Position.Z == 30))
                {
                    Device.Close();
                }

                if (Device.CursorControl.Position.X != 400)
                {
                    Rotation += (Device.CursorControl.Position.X - 400) * 0.0025;
                    Device.CursorControl.Position = new Vector2Di(400, 300);
                    VecteurAvant  = new Vector3Df((float)Math.Cos(Rotation), 0, -(float)Math.Sin(Rotation));
                    VecteurDroite = VecteurAvant;
                    VecteurDroite.RotateXZby(-90);
                }


                for (int i = 0; i < Choses.Count; i++)
                {
                    Choses[i].MiseAJour(tempsEcoule, camera);
                }


                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;


                if (TenterMouvement(camera, vitesse) || TenterMouvement(camera, new Vector3Df(vitesse.X, 0, 0)) || TenterMouvement(camera, new Vector3Df(0, 0, vitesse.Z)))
                {
                    camera.Target = camera.Position + VecteurAvant;
                }

                Device.VideoDriver.BeginScene(ClearBufferFlag.Color | ClearBufferFlag.Depth, IrrlichtLime.Video.Color.OpaqueMagenta);
                Device.SceneManager.DrawAll();

                Device.VideoDriver.Draw2DImage(TexturePistolet[FramePistolet], new Recti(new Vector2Di(250, 300), new Dimension2Di(300, 300)), new Recti(0, 0, 512, 512), null, COULEUR_BLANC, true);
                DessinerHUD();
                Device.VideoDriver.EndScene();

                if (FramePistolet > 0)
                {
                    ProchaineFramePistolet -= tempsEcoule;

                    if (ProchaineFramePistolet <= 0f)
                    {
                        FramePistolet++;
                        if (FramePistolet > 2)
                        {
                            FramePistolet = 0;
                        }
                        ProchaineFramePistolet = 0.1f;
                    }
                }
            }
        }
示例#9
0
        static void Main()
        {
            DriverType?driverType = AskForDriver();

            if (!driverType.HasValue)
            {
                return;
            }

            IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(800, 600));

            if (device == null)
            {
                return;
            }

            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);
            device.SetWindowCaption("Mesh handling - Irrlicht Engine - press [1], [2], [3] to regenerate mesh");
            VideoDriver  driver = device.VideoDriver;
            SceneManager scene  = device.SceneManager;

            // Generate starting height map and mesh

            HeightMap map = new HeightMap(255, 255);

            map.Generate(HeightMap.HeightFunc.EggBox);

            HeightMesh mesh = new HeightMesh();

            mesh.Init(driver, map, 50.0f, HeightMesh.ColorFunc.GreyscaleBasedOnTheHeight);

            // Add the mesh to the scene graph

            MeshSceneNode meshnode = scene.AddMeshSceneNode(mesh.Mesh);

            meshnode.SetMaterialFlag(MaterialFlag.BackFaceCulling, false);

            // Add light (just for nice effects)

            LightSceneNode    lightnode = scene.AddLightSceneNode(null, new Vector3Df(0, 100, 0), new Colorf(1, 1, 1), 500.0f);
            SceneNodeAnimator anim      = scene.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 250.0f);

            lightnode.AddAnimator(anim);
            anim.Drop();

            // Add camera

            CameraSceneNode camera = scene.AddCameraSceneNodeFPS();

            camera.Position = new Vector3Df(-20.0f, 100.0f, -20.0f);
            camera.Target   = new Vector3Df(200.0f, -100.0f, 200.0f);
            camera.FarValue = 20000.0f;

            // Main loop

            while (device.Run())
            {
                if (!device.WindowActive)
                {
                    device.Sleep(100);
                    continue;
                }

                if (IsKeyDown(KeyCode.KeyW))
                {
                    meshnode.SetMaterialFlag(MaterialFlag.Wireframe, !meshnode.GetMaterial(0).Wireframe);
                }
                else if (IsKeyDown(KeyCode.Key1))
                {
                    map.Generate(HeightMap.HeightFunc.EggBox);
                    mesh.Init(driver, map, 50.0f, HeightMesh.ColorFunc.GreyscaleBasedOnTheHeight);
                }
                else if (IsKeyDown(KeyCode.Key2))
                {
                    map.Generate(HeightMap.HeightFunc.MoreSine);
                    mesh.Init(driver, map, 50.0f, HeightMesh.ColorFunc.CoordinateInterpolation);
                }
                else if (IsKeyDown(KeyCode.Key3))
                {
                    map.Generate(HeightMap.HeightFunc.JustExp);
                    mesh.Init(driver, map, 50.0f, HeightMesh.ColorFunc.CoordinateInterpolation);
                }

                driver.BeginScene();
                scene.DrawAll();
                driver.EndScene();
            }

            // Clean up

            mesh.Drop();
            device.Drop();
        }
示例#10
0
        static void Main()
        {
            // setup Irrlicht

            device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 768), 32, false, true);
            if (device == null)
            {
                return;
            }

            device.SetWindowCaption("Stencil Shadows - Irrlicht Engine");
            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);

            VideoDriver  driver = device.VideoDriver;
            SceneManager scene  = device.SceneManager;

            GUIFont statsFont = device.GUIEnvironment.GetFont("../../media/fontlucida.png");

            cameraNode          = scene.AddCameraSceneNodeFPS();
            cameraNode.FarValue = 20000;

            device.CursorControl.Visible = false;

            // setup shadows

            shadows = new Shadows(new Color(0xa0000000), 4000);

            // load quake level

            device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3");

            Mesh          m = scene.GetMesh("20kdm2.bsp").GetMesh(0);
            MeshSceneNode n = scene.AddOctreeSceneNode(m, null, -1, 1024);

            n.Position     = new Vector3Df(-1300, -144, -1249);
            quakeLevelNode = n;

            // add faerie

            faerieNode = scene.AddAnimatedMeshSceneNode(
                scene.GetMesh("../../media/faerie.md2"),
                null, -1,
                new Vector3Df(100, -40, 80),
                new Vector3Df(0, 30, 0),
                new Vector3Df(1.6f));

            faerieNode.SetMD2Animation(AnimationTypeMD2.Wave);
            faerieNode.AnimationSpeed = 20;
            faerieNode.GetMaterial(0).SetTexture(0, driver.GetTexture("../../media/faerie2.bmp"));
            faerieNode.GetMaterial(0).Lighting         = false;
            faerieNode.GetMaterial(0).NormalizeNormals = true;

            shadows.AddObject(faerieNode);

            // add light

            lightMovementHelperNode = scene.AddEmptySceneNode();

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

            lightNode = n;
            shadows.AddLight(lightNode);

            // add flashlight

            m = scene.GetMesh("../../media/flashlight.obj");
            n = scene.AddMeshSceneNode(m, lightNode, -1, new Vector3Df(0), new Vector3Df(0), new Vector3Df(5));
            n.SetMaterialFlag(MaterialFlag.Lighting, false);

            flashlightNode         = n;
            flashlightNode.Visible = false;

            // render

            uint shdFrameTime = 0;
            uint shdFrames    = 0;
            uint shdFps       = 0;

            while (device.Run())
            {
                if (useShadowsRebuilding &&
                    shadows.BuildShadowVolume())
                {
                    shdFrames++;
                }

                uint t = device.Timer.Time;
                if (t - shdFrameTime > 1000)
                {
                    shdFrameTime = t;
                    shdFps       = shdFrames;
                    shdFrames    = 0;
                }

                if (useLightBinding)
                {
                    lightMovementHelperNode.Position = cameraNode.AbsolutePosition.GetInterpolated(lightMovementHelperNode.Position, 0.1);
                    lightMovementHelperNode.Rotation = cameraNode.AbsoluteTransformation.Rotation;
                }

                driver.BeginScene(ClearBufferFlag.All, new Color(0xff112244));

                scene.DrawAll();

                if (useShadowsRendering)
                {
                    shadows.DrawShadowVolume(driver);
                }

                // display stats

                driver.Draw2DRectangle(new Recti(10, 10, 150, 220), new Color(0x7f000000));

                Vector2Di v = new Vector2Di(20, 20);
                statsFont.Draw("Rendering", v, Color.SolidYellow);
                v.Y += 16;
                statsFont.Draw(driver.FPS + " fps", v, Color.SolidWhite);
                v.Y += 16;
                statsFont.Draw("[S]hadows " + (useShadowsRendering ? "ON" : "OFF"), v, Color.SolidGreen);
                v.Y += 16;
                statsFont.Draw("[L]ight binding " + (useLightBinding ? "ON" : "OFF"), v, Color.SolidGreen);
                v.Y += 16;
                statsFont.Draw("[F]lashlight " + (useFlashlight ? "ON" : "OFF"), v, Color.SolidGreen);
                v.Y += 32;
                statsFont.Draw("Shadows", v, Color.SolidYellow);
                v.Y += 16;
                statsFont.Draw(shdFps + " fps", v, Color.SolidWhite);
                v.Y += 16;
                statsFont.Draw(shadows.VerticesBuilt + " vertices", v, Color.SolidWhite);
                v.Y += 16;
                statsFont.Draw("[R]ebuilding " + (useShadowsRebuilding ? "ON" : "OFF"), v, Color.SolidGreen);
                v.Y += 16;
                statsFont.Draw("[Q]uake level " + (useShadowsQuakeLevel ? "ON" : "OFF"), v, Color.SolidGreen);

                driver.EndScene();
            }

            shadows.Drop();
            device.Drop();
        }