예제 #1
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();
        }
예제 #2
0
        public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize,
                              Dimension2D tileCount, Dimension2D precision, int id) :
            base(parent, mgr, id)
        {
            _scene = mgr;
            _driver = mgr.VideoDriver;

            AnimatedMesh wmesh = _scene.AddHillPlaneMesh("watermesh" + _current,
                tileSize,
                tileCount, 0,
                new Dimension2Df(0, 0),
                new Dimension2Df(1, 1));
            _current++;

            int dmat;
            if (_driver.DriverType == DriverType.OpenGL)
                dmat = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 WATER_VERTEX_GLSL, "main", VertexShaderType._1_1, WATER_FRAGMENT_GLSL,
                 "main", PixelShaderType._1_1, OnShaderSet, MaterialType.TransparentAlphaChannel, 0);
            else
                dmat = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 WATER_HLSL, "vertexMain", VertexShaderType._2_0, WATER_HLSL,
                 "pixelMain", PixelShaderType._2_0, OnShaderSet, MaterialType.TransparentAlphaChannel, 2);

            if (_driver.DriverType == DriverType.OpenGL)
                ClampShader = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 CLAMP_VERTEX_GLSL, "main", VertexShaderType._1_1, CLAMP_FRAGMENT_GLSL,
                 "main", PixelShaderType._1_1, OnShaderSet, MaterialType.TransparentAlphaChannel, 1);
            else
                ClampShader = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 CLAMP_HLSL, "vertexMain", VertexShaderType._2_0, CLAMP_HLSL,
                 "pixelMain", PixelShaderType._2_0, OnShaderSet, MaterialType.TransparentAlphaChannel, 3);

            _waternode = _scene.AddMeshSceneNode(wmesh.GetMesh(0), this, -1);
            _waternode.SetMaterialType(dmat);
            _waternode.SetMaterialFlag(MaterialFlag.BackFaceCulling, false);
            _waternode.SetMaterialFlag(MaterialFlag.Lighting, false);
            _waternode.SetMaterialFlag(MaterialFlag.FogEnable, false);

            _rt = _driver.CreateRenderTargetTexture(precision);
            _waternode.SetMaterialTexture(0, _rt);

            CameraSceneNode oldcam = _scene.ActiveCamera;
            _fixedcam = _scene.AddCameraSceneNode(null);
            if (oldcam != null)
                _scene.ActiveCamera = oldcam;
        }
예제 #3
0
        static void Main()
        {
            device          = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 768), 32, false, true);
            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);
            device.SetWindowCaption("Minesweeper - Irrlicht Engine");

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

            device.FileSystem.AddFileArchive("../../media/minesweeper.media.files");
            game = new Game(device);

            // set up camera

            camera = scene.AddCameraSceneNode();             // Maya(null, -500, 50, 200);
            setupCameraPositionAndTarget();

            // set up background

            Mesh m = scene.GetMesh("back.obj");

            scene.MeshManipulator.Scale(m, new Vector3Df(80));
            scene.MeshManipulator.FlipSurfaces(m);
            scene.MeshManipulator.RecalculateNormals(m);
            scene.MeshManipulator.SetVertexColors(m, new Color(80, 80, 80));

            Material t = new Material();

            t.Type     = MaterialType.Reflection2Layer;
            t.Lighting = false;
            t.SetTexture(0, device.VideoDriver.GetTexture("TEXTURE-ref.jpg"));
            t.SetTexture(1, device.VideoDriver.GetTexture("TEXTURE-ref.jpg"));

            MeshSceneNode n = scene.AddMeshSceneNode(m, null, 7777);

            n.SetMaterial(0, t);
            n.Position = game.CenterOfTheBoard;

            SceneNodeAnimator a = scene.CreateRotationAnimator(new Vector3Df(0.07f, 0.01f, 0.05f));

            n.AddAnimator(a);
            a.Drop();

            // set up light

            light = scene.AddLightSceneNode(null, game.CenterOfTheBoard, new Colorf(1, 1, 1), 200);

            m = scene.AddVolumeLightMesh("lvol1", 32, 32, new Color(5, 5, 5));
            scene.MeshManipulator.Scale(m, new Vector3Df(15, 30, 15));
            n          = scene.AddMeshSceneNode(m, light);
            n.Position = new Vector3Df(0, -10, 0);
            n.Rotation = new Vector3Df(180, 0, 0);
            n.SetMaterialType(MaterialType.TransparentAddColor);

            m = scene.AddVolumeLightMesh("lvol2", 32, 32, new Color(5, 5, 5));
            scene.MeshManipulator.Scale(m, new Vector3Df(15, 30, 15));
            n          = scene.AddMeshSceneNode(m, light);
            n.Position = new Vector3Df(0, -10, 0);
            n.SetMaterialType(MaterialType.TransparentAddColor);

            // add gui hint

            text = gui.AddStaticText(TextStart, new Recti(10, 10, 200, 40));
            text.OverrideColor = Color.SolidYellow;

            // main loop

            while (device.Run())
            {
                driver.BeginScene();
                scene.DrawAll();
                gui.DrawAll();

                if (optionFPS)
                {
                    gui.BuiltInFont.Draw(driver.FPS + " FPS", driver.ScreenSize.Width - 50, 10, Color.SolidWhite);
                }

                driver.EndScene();
            }

            device.Drop();
        }
예제 #4
0
        static void Main(string[] args)
        {
            // Initialize device.

            DriverType driverType;

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

            IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480));

            if (device == null)
            {
                return;
            }

            // Add event handling.

            device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent);

            // Save important pointers.

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

            // Initialize joysticks and print info about them.

            List <JoystickInfo> joystickList = device.ActivateJoysticks();

            if (joystickList != null)
            {
                logger.Log("Joystick support is enabled and " + joystickList.Count.ToString() + " joystick(s) are present.");

                foreach (JoystickInfo j in joystickList)
                {
                    logger.Log("Joystick " + j.Joystick.ToString() + ":");
                    logger.Log("\tName: \"" + j.Name + "\"");
                    logger.Log("\tAxisCount: " + j.AxisCount.ToString());
                    logger.Log("\tButtonCount: " + j.ButtonCount.ToString());
                    logger.Log("\tPovHat: " + j.PovHat.ToString());
                }
            }
            else
            {
                logger.Log("Joystick support is not enabled.");
            }

            device.SetWindowCaption("Mouse and joystick - Irrlicht Lime - " + joystickList.Count.ToString() + " joystick(s)");

            // Create an arrow mesh and move it around either with the joystick axis/hat,
            // or make it follow the mouse pointer (when no joystick movement).

            SceneNode node = smgr.AddMeshSceneNode(
                smgr.AddArrowMesh(
                    "Arrow",
                    new Color(255, 0, 0),
                    new Color(0, 255, 0),
                    16, 16,
                    2.0f, 1.3f,
                    0.1f, 0.6f
                    )
                );

            node.SetMaterialFlag(MaterialFlag.Lighting, false);

            CameraSceneNode camera = smgr.AddCameraSceneNode();

            camera.Position = new Vector3Df(0, 0, -10);

            // As in example #4, we'll use framerate independent movement.
            uint        then          = device.Timer.Time;
            const float MovementSpeed = 5.0f;

            // Run main cycle.

            while (device.Run())
            {
                // Work out a frame delta time.
                uint  now            = device.Timer.Time;
                float frameDeltaTime = (float)(now - then) / 1000.0f;                 // in seconds
                then = now;

                bool      movedWithJoystick = false;
                Vector3Df nodePosition      = node.Position;

                if (joystickList.Count > 0)
                {
                    float moveHorizontal = 0.0f;                   // range is -1.0 for full left to +1.0 for full right
                    float moveVertical   = 0.0f;                   // range is -1.0 for full down to +1.0 for full up

                    // We receive the full analog range of the axes, and so have to implement our own dead zone.
                    // This is an empirical value, since some joysticks have more jitter or creep around the center
                    // point than others. We'll use 5% of the range as the dead zone, but generally you would want
                    // to give the user the option to change this.
                    float DeadZone = 0.05f;

                    moveHorizontal = joystickState.Axis[0] / 32767.0f;                     // "0" for X axis
                    if (Math.Abs(moveHorizontal) < DeadZone)
                    {
                        moveHorizontal = 0.0f;
                    }

                    moveVertical = joystickState.Axis[1] / -32767.0f;                     // "1" for Y axis
                    if (Math.Abs(moveVertical) < DeadZone)
                    {
                        moveVertical = 0.0f;
                    }

                    // POV will contain 65535 if POV hat info no0t supported, so we can check its range.
                    ushort povDegrees = (ushort)(joystickState.POV / 100);
                    if (povDegrees < 360)
                    {
                        if (povDegrees > 0 && povDegrees < 180)
                        {
                            moveHorizontal = +1.0f;
                        }
                        else if (povDegrees > 180)
                        {
                            moveHorizontal = -1.0f;
                        }

                        if (povDegrees > 90 && povDegrees < 270)
                        {
                            moveVertical = -1.0f;
                        }
                        else if (povDegrees > 270 || povDegrees < 90)
                        {
                            moveVertical = +1.0f;
                        }
                    }

                    // If we have any movement, apply it.
                    if (Math.Abs(moveHorizontal) > 0.0001f || Math.Abs(moveVertical) > 0.0001f)
                    {
                        float m = frameDeltaTime * MovementSpeed;
                        nodePosition      = new Vector3Df(moveHorizontal * m, moveVertical * m, nodePosition.Z);
                        movedWithJoystick = true;
                    }
                }

                // If the arrow node isn't being moved with the joystick, then have it follow the mouse cursor.
                if (!movedWithJoystick)
                {
                    // Create a ray through the mouse cursor.
                    Line3Df ray = smgr.SceneCollisionManager.GetRayFromScreenCoordinates(mouseState.Position, camera);

                    // And intersect the ray with a plane around the node facing towards the camera.
                    Plane3Df  plane = new Plane3Df(nodePosition, new Vector3Df(0, 0, -1));
                    Vector3Df mousePosition;
                    if (plane.GetIntersectionWithLine(ray.Start, ray.Vector, out mousePosition))
                    {
                        // We now have a mouse position in 3d space; move towards it.
                        Vector3Df toMousePosition   = mousePosition - nodePosition;
                        float     availableMovement = frameDeltaTime * MovementSpeed;

                        if (toMousePosition.Length <= availableMovement)
                        {
                            nodePosition = mousePosition;                             // jump to the final position
                        }
                        else
                        {
                            nodePosition += toMousePosition.Normalize() * availableMovement;                             // move towards it
                        }
                    }
                }

                node.Position = nodePosition;

                // Turn lighting on and off depending on whether the left mouse button is down.
                node.SetMaterialFlag(MaterialFlag.Lighting, mouseState.IsLeftButtonDown);

                // Draw all.
                driver.BeginScene(true, true, new Color(113, 113, 133));
                smgr.DrawAll();
                driver.EndScene();
            }

            // Drop the device.

            device.Drop();
        }
예제 #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;
            }

            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();
        }
예제 #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;
            }

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

            driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true);

            // add irrlicht logo
            env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10));

            // add camera
            CameraSceneNode camera = smgr.AddCameraSceneNodeFPS();

            camera.Position = new Vector3Df(-200, 200, -200);

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

            driver.Fog = new Fog(new Color(138, 125, 81, 0), FogType.Linear, 250, 1000, 0.003f, true, false);

            AnimatedMesh roomMesh = smgr.GetMesh("../../media/room.3ds");
            SceneNode    room     = null;
            SceneNode    earth    = null;

            if (roomMesh != null)
            {
                // the room mesh doesn't have proper texture mapping on the floor,
                // so we can recreate them on runtime
                smgr.MeshManipulator.MakePlanarTextureMapping(roomMesh.GetMesh(0), 0.003f);

                Texture normalMap = driver.GetTexture("../../media/rockwall_height.bmp");
                if (normalMap != null)
                {
                    driver.MakeNormalMapTexture(normalMap, 9.0f);
                }

                Mesh tangentMesh = smgr.MeshManipulator.CreateMeshWithTangents(roomMesh.GetMesh(0));
                room = smgr.AddMeshSceneNode(tangentMesh);
                room.SetMaterialTexture(0, driver.GetTexture("../../media/rockwall.jpg"));
                room.SetMaterialTexture(1, normalMap);
                room.GetMaterial(0).SpecularColor = new Color(0);
                room.GetMaterial(0).Shininess     = 0.0f;
                room.SetMaterialFlag(MaterialFlag.Fog, true);
                room.SetMaterialType(MaterialType.ParallaxMapSolid);
                room.GetMaterial(0).MaterialTypeParam = 1.0f / 64.0f; // adjust height for parallax effect

                tangentMesh.Drop();                                   // drop mesh because we created it with a "create" call
            }

            // add earth sphere
            AnimatedMesh earthMesh = smgr.GetMesh("../../media/earth.x");

            if (earthMesh != null)
            {
                // perform various task with the mesh manipulator
                MeshManipulator manipulator = smgr.MeshManipulator;

                // create mesh copy with tangent informations from original earth.x mesh
                Mesh tangentSphereMesh = manipulator.CreateMeshWithTangents(earthMesh.GetMesh(0));

                // set the alpha value of all vertices to 200
                manipulator.SetVertexColorAlpha(tangentSphereMesh, 200);

                // scale the mesh by factor 50
                Matrix m = new Matrix();
                m.Scale = new Vector3Df(50);
                manipulator.Transform(tangentSphereMesh, m);

                earth          = smgr.AddMeshSceneNode(tangentSphereMesh);
                earth.Position = new Vector3Df(-70, 130, 45);

                // load heightmap, create normal map from it and set it
                Texture earthNormalMap = driver.GetTexture("../../media/earthbump.jpg");
                if (earthNormalMap != null)
                {
                    driver.MakeNormalMapTexture(earthNormalMap, 20);
                    earth.SetMaterialTexture(1, earthNormalMap);
                    earth.SetMaterialType(MaterialType.NormalMapTransparentVertexAlpha);
                }

                // adjust material settings
                earth.SetMaterialFlag(MaterialFlag.Fog, true);

                // add rotation animator
                SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0, 0.1f, 0));
                earth.AddAnimator(anim);
                anim.Drop();

                // drop mesh because we created it with a "create" call.
                tangentSphereMesh.Drop();
            }

            // add light 1 (more green)
            LightSceneNode light1 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(0.5f, 1.0f, 0.5f, 0.0f), 800);

            if (light1 != null)
            {
                light1.DebugDataVisible = DebugSceneType.BBox;

                // add fly circle animator to light
                SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(50, 300, 0), 190.0f, -0.003f);
                light1.AddAnimator(anim);
                anim.Drop();

                // attach billboard to the light
                BillboardSceneNode bill = smgr.AddBillboardSceneNode(light1, new Dimension2Df(60, 60));
                bill.SetMaterialFlag(MaterialFlag.Lighting, false);
                bill.SetMaterialFlag(MaterialFlag.ZWrite, false);
                bill.SetMaterialType(MaterialType.TransparentAddColor);
                bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlegreen.jpg"));
            }

            // add light 2 (red)
            SceneNode light2 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(1.0f, 0.2f, 0.2f, 0.0f), 800.0f);

            if (light2 != null)
            {
                // add fly circle animator to light
                SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 200.0f, 0.001f, new Vector3Df(0.2f, 0.9f, 0.0f));
                light2.AddAnimator(anim);
                anim.Drop();

                // attach billboard to light
                SceneNode bill = smgr.AddBillboardSceneNode(light2, new Dimension2Df(120, 120));
                bill.SetMaterialFlag(MaterialFlag.Lighting, false);
                bill.SetMaterialFlag(MaterialFlag.ZWrite, false);
                bill.SetMaterialType(MaterialType.TransparentAddColor);
                bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlered.bmp"));

                // add particle system
                ParticleSystemSceneNode ps = smgr.AddParticleSystemSceneNode(false, light2);

                // create and set emitter
                ParticleEmitter em = ps.CreateBoxEmitter(
                    new AABBox(-3, 0, -3, 3, 1, 3),
                    new Vector3Df(0.0f, 0.03f, 0.0f),
                    80, 100,
                    new Color(255, 255, 255, 10), new Color(255, 255, 255, 10),
                    400, 1100);

                em.MinStartSize = new Dimension2Df(30.0f, 40.0f);
                em.MaxStartSize = new Dimension2Df(30.0f, 40.0f);

                ps.Emitter = em;
                em.Drop();

                // create and set affector
                ParticleAffector paf = ps.CreateFadeOutParticleAffector();
                ps.AddAffector(paf);
                paf.Drop();

                // adjust some material settings
                ps.SetMaterialFlag(MaterialFlag.Lighting, false);
                ps.SetMaterialFlag(MaterialFlag.ZWrite, false);
                ps.SetMaterialTexture(0, driver.GetTexture("../../media/fireball.bmp"));
                ps.SetMaterialType(MaterialType.TransparentAddColor);
            }

            MyEventReceiver receiver = new MyEventReceiver(device, room, earth);

            int lastFPS = -1;

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

                    smgr.DrawAll();
                    env.DrawAll();

                    driver.EndScene();

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

                        lastFPS = fps;
                    }
                }
            }

            device.Drop();
        }
예제 #7
0
        ClockNode(SceneNode parent, SceneManager smgr)
            : base(parent, smgr)
        {
            OnGetBoundingBox    += new GetBoundingBoxEventHandler(ClockNode_OnGetBoundingBox);
            OnGetMaterialCount  += new GetMaterialCountEventHandler(ClockNode_OnGetMaterialCount);
            OnGetMaterial       += new GetMaterialEventHandler(ClockNode_OnGetMaterial);
            OnRegisterSceneNode += new RegisterSceneNodeEventHandler(ClockNode_OnRegisterSceneNode);
            OnRender            += new RenderEventHandler(ClockNode_OnRender);
            OnAnimate           += new AnimateEventHandler(ClockNode_OnAnimate);

            // add clock face

            Mesh          mesh      = SceneManager.GeometryCreator.CreateCylinderMesh(100, 32, 6, new Color(180, 180, 180));
            MeshSceneNode clockFace = SceneManager.AddMeshSceneNode(mesh, this);

            clockFace.Rotation = new Vector3Df(90, 0, 0);
            clockFace.Position = new Vector3Df(0, 0, 10);
            mesh.Drop();

            clockFace.UpdateAbsolutePosition();
            boundingBox = clockFace.BoundingBoxTransformed;
            for (int i = 0; i < clockFace.MaterialCount; i++)
            {
                materialList.Add(clockFace.GetMaterial(i));
            }

            // add clock center

            mesh = SceneManager.GeometryCreator.CreateCylinderMesh(10, 24, 16, new Color(255, 255, 255), false);
            MeshSceneNode clockCenter = SceneManager.AddMeshSceneNode(mesh, this);

            clockCenter.Rotation = new Vector3Df(90, 0, 0);
            clockCenter.Position = new Vector3Df(0, 0, -14);
            mesh.Drop();

            clockCenter.UpdateAbsolutePosition();
            boundingBox.AddInternalBox(clockCenter.BoundingBoxTransformed);
            for (int i = 0; i < clockCenter.MaterialCount; i++)
            {
                materialList.Add(clockCenter.GetMaterial(i));
            }

            // add clock ticks

            for (int j = 0; j < 12; j++)
            {
                mesh = SceneManager.GeometryCreator.CreateCylinderMesh(5, 10, 16, new Color(255, 255, 255), false);
                MeshSceneNode clockTick = SceneManager.AddMeshSceneNode(mesh, this);
                clockTick.Rotation = new Vector3Df(90, 0, 0);

                float s = (float)Math.Sin((j * (360 / 12)) / (180 / Math.PI));
                float c = (float)Math.Cos((j * (360 / 12)) / (180 / Math.PI));
                clockTick.Position = new Vector3Df(s * 80, c * 80, 0);

                if ((j % 3) == 0)
                {
                    clockTick.Scale = new Vector3Df(2, 1, 2);
                }

                mesh.Drop();

                clockTick.UpdateAbsolutePosition();
                boundingBox.AddInternalBox(clockTick.BoundingBoxTransformed);
                for (int i = 0; i < clockTick.MaterialCount; i++)
                {
                    materialList.Add(clockTick.GetMaterial(i));
                }
            }

            // add hour arrow

            mesh       = SceneManager.GeometryCreator.CreateArrowMesh(12, 12, 40, 35, 4, 4, new Color(40, 40, 255), new Color(40, 40, 255));
            arrowHours = SceneManager.AddMeshSceneNode(mesh, this);
            arrowHours.GetMaterial(0).EmissiveColor = new Color(0, 0, 255);
            arrowHours.GetMaterial(1).EmissiveColor = new Color(0, 0, 255);
            arrowHours.Position = new Vector3Df(0, 0, 3);
            mesh.Drop();

            arrowHours.UpdateAbsolutePosition();
            boundingBox.AddInternalBox(arrowHours.BoundingBoxTransformed);
            for (int i = 0; i < arrowHours.MaterialCount; i++)
            {
                materialList.Add(arrowHours.GetMaterial(i));
            }

            // add minute arrow

            mesh         = SceneManager.GeometryCreator.CreateArrowMesh(12, 12, 60, 50, 4, 4, new Color(40, 255, 40), new Color(40, 255, 40));
            arrowMinutes = SceneManager.AddMeshSceneNode(mesh, this);
            arrowMinutes.GetMaterial(0).EmissiveColor = new Color(0, 255, 0);
            arrowMinutes.GetMaterial(1).EmissiveColor = new Color(0, 255, 0);
            arrowMinutes.Position = new Vector3Df(0, 0, -5);
            mesh.Drop();

            arrowMinutes.UpdateAbsolutePosition();
            boundingBox.AddInternalBox(arrowMinutes.BoundingBoxTransformed);
            for (int i = 0; i < arrowMinutes.MaterialCount; i++)
            {
                materialList.Add(arrowMinutes.GetMaterial(i));
            }

            // add second arrow

            mesh         = SceneManager.GeometryCreator.CreateArrowMesh(12, 12, 70, 60, 2, 2, new Color(255, 40, 40), new Color(255, 40, 40));
            arrowSeconds = SceneManager.AddMeshSceneNode(mesh, this);
            arrowSeconds.GetMaterial(0).EmissiveColor = new Color(255, 0, 0);
            arrowSeconds.GetMaterial(1).EmissiveColor = new Color(255, 0, 0);
            arrowSeconds.Position = new Vector3Df(0, 0, -11);
            mesh.Drop();

            arrowSeconds.UpdateAbsolutePosition();
            boundingBox.AddInternalBox(arrowSeconds.BoundingBoxTransformed);
            for (int i = 0; i < arrowSeconds.MaterialCount; i++)
            {
                materialList.Add(arrowSeconds.GetMaterial(i));
            }

            SceneManager.AddLightSceneNode(arrowSeconds, new Vector3Df(0, 70, 0), new Colorf(arrowSeconds.GetMaterial(0).EmissiveColor), 80);
            SceneManager.AddLightSceneNode(arrowMinutes, new Vector3Df(0, 60, 0), new Colorf(arrowMinutes.GetMaterial(0).EmissiveColor), 60);
            SceneManager.AddLightSceneNode(arrowHours, new Vector3Df(0, 40, 0), new Colorf(arrowHours.GetMaterial(0).EmissiveColor), 40);
        }
예제 #8
0
        public Application()
        {
            _01.HelloWorld.Kinect kinect = new _01.HelloWorld.Kinect();
            mfX = mouseX = 840; mfY = mouseY = 525; mouseL = false; mouseR = false;
            //device = IrrlichtDevice.CreateDevice(
            //    DriverType.Direct3D9, new Dimension2Di(800, 600), 16, false, true, false);
            //                                                           |
            device = IrrlichtDevice.CreateDevice(                    // \|/ Fullscreen
                DriverType.Direct3D9, new Dimension2Di(1680, 1050), 32, false, true, false);

            device.SetWindowCaption("BENder3D");

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

            device.OnEvent   += new IrrlichtDevice.EventHandler(device_OnEvent);
            smgr.AmbientLight = new Colorf(128, 128, 128, 128);
            //smgr.AddLightSceneNode(null, new Vector3Df(0, 70, 0), new Colorf(122,0,122,0), (float)10);
            MeshSceneNode box = smgr.AddCubeSceneNode(100, null, 9001, new Vector3Df(0.0f, -ballRadius * 3 / 2, 0.0f));

            box.Scale = new Vector3Df(100.0f, 0.1f, 100.0f);
            //Mesh cyl = smgr.GeometryCreator.CreateCylinderMesh(ballRadius, 50, 256);
            //Mesh sphere = smgr.GeometryCreator.CreateSphereMesh(ballRadius, 16,16);
            //MeshSceneNode t = smgr.AddSphereSceneNode(ballRadius, 32);
            //MeshSceneNode t = smgr.AddOctreeSceneNode(sphere);
            MeshSceneNode t = smgr.AddMeshSceneNode(smgr.GetMesh("pill.obj"));
            //MeshSceneNode t = smgr.AddMeshSceneNode(cyl);
            TriangleSelector triselect = smgr.CreateTriangleSelector(t.Mesh, t);

            t.TriangleSelector = triselect;
            triselect.Drop();
            //t = smgr.AddMeshSceneNode(smgr.GetMesh("../../media/sphere.x"));
            //smgr
            t.SetMaterialTexture(0, driver.GetTexture("rockwall.jpg"));
            //t.SetMaterialFlag(MaterialFlag.Lighting, true);
            t.GetMaterial(0).SpecularColor.Set(0, 0, 0);
            //t.GetMaterial(0).Lighting = true;
            t.GetMaterial(0).NormalizeNormals = false;

            /*Texture citrus = driver.AddTexture(new Dimension2Di(200, 200), "citrus.png");
             * gui.AddImage(citrus, new Vector2Di(824, 0), true);*/
            gui.AddStaticText("Hey, Listen! Press C to switch the mesh to a cylinder!\n Press S to change to a sphere, and enter to send yourself the obj file!", new Recti(0, 0, 400, 60));
            //t.AddShadowVolumeSceneNode();
            //           driver.GPUProgrammingServices.OnSetConstants += new GPUProgrammingServices.SetConstantsHandler(gpu_OnSetConstants);

            /*
             * MaterialType shaderMat = MaterialType.Solid;
             * shaderMat = driver.GPUProgrammingServices.AddHighLevelShaderMaterialFromFiles("C:/IrrlichtLime-1.4/examples/01.HelloWorld/bumpmap.hlsl", "VertexShaderFunction", VertexShaderType.VS_3_0,
             * "C:/IrrlichtLime-1.4/examples/01.HelloWorld/bumpmap.hlsl", "PixelShaderFunction", PixelShaderType.PS_3_0, MaterialType.Solid);
             *
             * t.SetMaterialType(shaderMat);
             * t.SetMaterialTexture(1, driver.GetTexture("../../media/rockwall_height.bmp"));*/

            GPUProgrammingServices gpu = driver.GPUProgrammingServices;
            MaterialType           newMaterialType1 = MaterialType.Solid;
            MaterialType           newMaterialType2 = MaterialType.TransparentAddColor;

            gpu.OnSetConstants += new GPUProgrammingServices.SetConstantsHandler(gpu_OnSetConstants);

            // create the shaders depending on if the user wanted high level or low level shaders

            newMaterialType1 = gpu.AddHighLevelShaderMaterialFromFiles(
                "d3d9.hlsl", "vertexMain", VertexShaderType.VS_1_1,
                "d3d9.hlsl", "pixelMain", PixelShaderType.PS_1_1,
                MaterialType.Solid, 0, GPUShadingLanguage.Default);
            t.SetMaterialType(newMaterialType1);
            //t.GetMaterial(0).Wireframe = true;
            //t.DebugDataVisible = DebugSceneType.Full;
            //t.AddShadowVolumeSceneNode(null, -1, false, 1000.0f);
            smgr.AddLightSceneNode(null, new Vector3Df(40, 150, -50), new Colorf(255, 255, 255, 255), 250.0f);
            //CSampleSceneNode sceneNode = new CSampleSceneNode(smgr.RootNode, smgr, 667);
            camera = smgr.AddCameraSceneNode(null, new Vector3Df(0, 50, -140), new Vector3Df(0, 5, 0));

            //camera.Target = new Vector3Df(-70, 30, -60);
            //smgr.AddCameraSceneNodeFPS(null, (float)50.0);
            Material m = new Material();

            m.Lighting = false;
            double PI        = 3.1415926f;
            float  distance  = 200.0f;
            double angle     = 180.0f;
            double angleY    = 20.0f;
            int    oldMouseX = mouseX;
            int    oldMouseY = mouseY;



            uint then          = device.Timer.Time;
            uint currentAutism = device.Timer.Time;
            bool autism        = false;

            while (device.Run())
            {
                uint  now            = device.Timer.Time;
                float frameDeltaTime = (float)(now - then) / 1000.0f;
                then = now;
                if (kinect.isTranslating && (kinect.translation.X < 30 && kinect.translation.X > -30))
                {
                    mfX -= (int)(kinect.translation.X);
                    mfY -= (int)(kinect.translation.Y);

                    Console.WriteLine(mouseX + ", " + mouseY + " ----------------- " + (int)(kinect.translation.X) + ", " + (int)(kinect.translation.Y));
                }

                kinect.resetTranslation();

                /*
                 * if (getDistance((int)mfX, (int)mfY, 512, 384) > 150)
                 * {
                 *  mfX = 512; mfY= 384;
                 * }*/


                mouseX = Math.Abs((int)mfX) % 1024;
                mouseY = Math.Abs((int)mfY) % 768;
                //mouseX = kinect.position.X;

                device.CursorControl.Position = new Vector2Di(mouseX, mouseY);

                if (!potterWheelDown && IsKeyDown(KeyCode.Up))
                {
                    potterWheelDown     = true;
                    deltaAngle          = 1.0d;
                    potterWheelActivate = !potterWheelActivate;
                }
                else if (!IsKeyDown(KeyCode.Up))
                {
                    potterWheelDown = false;
                }
                if (!leftKeyPressed && IsKeyDown(KeyCode.Left))
                {
                    leftKeyPressed = true;
                    deltaAngle    /= 2;
                }
                else if (!IsKeyDown(KeyCode.Left))
                {
                    leftKeyPressed = false;
                }
                if (!rightKeyPressed && IsKeyDown(KeyCode.Right))
                {
                    rightKeyPressed = true;
                    deltaAngle     *= 2;
                }
                else if (!IsKeyDown(KeyCode.Right))
                {
                    rightKeyPressed = false;
                }
                if (potterWheelActivate)
                {
                    angle -= 700.0f * deltaAngle * frameDeltaTime;
                }

                if (angle > 360)
                {
                    angle -= 360;
                }
                else if (angle < 0)
                {
                    angle += 360;
                }

                if (angleY > 360)
                {
                    angle -= 360;
                }
                else if (angleY < 0)
                {
                    angleY += 360;
                }
                driver.BeginScene(true, true, new Color(100, 101, 140));
                camera.Target = new Vector3Df(0, 0, 0);
                double temp = Math.Cos(angleY * PI / 180.0) * distance;
                double X    = Math.Sin(angle * PI / 180.0) * temp;
                double Y    = Math.Sin(angleY * PI / 180.0) * distance;
                double Z    = Math.Cos(angle * PI / 180.0) * temp;
                camera.Position = new Vector3Df((float)X, (float)Y, (float)Z);
                smgr.DrawAll();

                gui.DrawAll();
                driver.SetMaterial(m);
                Triangle3Df triangle = interpolateFrom2D(new Vector2Di(mouseX, mouseY));
                if (kinect.isMorphing && kinect.morphDist > 0)
                //if (IsKeyDown(KeyCode.KeyW))
                {
                    //Console.WriteLine("PRESSED KEY");
                    triangle.A *= new Vector3Df(0.5f);
                    triangle.B *= new Vector3Df(0.5f);
                    triangle.C *= new Vector3Df(0.5f);
                    if (isCyl)
                    {
                        deformCyl(t, triangle.A, new Vector3Df(.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle);
                    }
                    else
                    {
                        deformMesh(t, triangle.A, new Vector3Df(.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle);
                    }
                }
                else if (kinect.isMorphing && kinect.morphDist < 0)
                {
                    //Console.WriteLine("PRESSED KEY");
                    triangle.A *= new Vector3Df(1.5f);
                    triangle.B *= new Vector3Df(1.5f);
                    triangle.C *= new Vector3Df(1.5f);
                    if (isCyl)
                    {
                        deformCyl(t, triangle.A, new Vector3Df(-.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle);
                    }
                    else
                    {
                        deformMesh(t, triangle.A, new Vector3Df(-.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle);
                    }
                }
                if (kinect.isZoom && kinect.zoomDist < 0)
                {
                    if (distance < 300.0f)
                    {
                        distance += .0625f;
                    }
                }
                if (kinect.isZoom && kinect.zoomDist > 0)
                {
                    if (distance > 150)
                    {
                        distance -= .0625f;
                    }
                }
                if (kinect.isRotating && kinect.rotation > 0)
                {
                    angle += 200 * frameDeltaTime;
                }
                if (kinect.isRotating && kinect.rotation < 0)
                {
                    angle -= 200 * frameDeltaTime;
                }

                //Change shape

                if (IsKeyDown(KeyCode.KeyA))
                {
                    IrrlichtLime.IO.WriteFile file = device.FileSystem.CreateWriteFile("./Saved.obj");
                    writeMesh(file, t.Mesh, 1);

                    mail();
                }
                if (IsKeyDown(KeyCode.KeyC))
                {
                    isCyl = true;
                    t.Remove();
                    t = smgr.AddMeshSceneNode(smgr.GetMesh("pill.obj"));
                    //MeshSceneNode t = smgr.AddMeshSceneNode(cyl);
                    triselect          = smgr.CreateTriangleSelector(t.Mesh, t);
                    t.TriangleSelector = triselect;
                    triselect.Drop();
                    //t = smgr.AddMeshSceneNode(smgr.GetMesh("../../media/sphere.x"));
                    //smgr
                    t.SetMaterialTexture(0, driver.GetTexture("rockwall.jpg"));
                    //t.SetMaterialFlag(MaterialFlag.Lighting, true);
                    t.GetMaterial(0).SpecularColor.Set(0, 0, 0);
                    //t.GetMaterial(0).Lighting = true;
                    t.GetMaterial(0).NormalizeNormals = false;
                    t.SetMaterialType(newMaterialType1);
                }
                else if (IsKeyDown(KeyCode.KeyS))
                {
                    isCyl = false;
                    t.Remove();
                    t                  = smgr.AddSphereSceneNode(ballRadius, 32);
                    triselect          = smgr.CreateTriangleSelector(t.Mesh, t);
                    t.TriangleSelector = triselect;
                    triselect.Drop();
                    //t = smgr.AddMeshSceneNode(smgr.GetMesh("../../media/sphere.x"));
                    //smgr
                    t.SetMaterialTexture(0, driver.GetTexture("rockwall.jpg"));
                    //t.SetMaterialFlag(MaterialFlag.Lighting, true);
                    t.GetMaterial(0).SpecularColor.Set(0, 0, 0);
                    //t.GetMaterial(0).Lighting = true;
                    t.GetMaterial(0).NormalizeNormals = false;
                    t.SetMaterialType(newMaterialType1);
                }
                driver.EndScene();
            }

            device.Drop();
        }
예제 #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();
        }