Пример #1
0
 public void ApplyClampingOnTerrain(TerrainSceneNode terrain)
 {
     clampList.Add(terrain);
 }
Пример #2
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));

            // set gui font
            env.Skin.SetFont(env.GetFont("../../media/fontlucida.png"));

            // add some help text
            env.AddStaticText(
                "Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome",
                new Recti(10, 421, 250, 475), true, true, null, -1, true);

            // add camera
            CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(null, 100.0f, 1.2f);

            camera.Position = new Vector3Df(2700 * 2, 255 * 2, 2600 * 2);
            camera.Target   = new Vector3Df(2397 * 2, 343 * 2, 2700 * 2);
            camera.FarValue = 42000.0f;

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

            // add terrain scene node
            TerrainSceneNode terrain = smgr.AddTerrainSceneNode(
                "../../media/terrain-heightmap.bmp",                    // heightmap
                null,                                                   // parent node
                -1,                                                     // node id
                new Vector3Df(),                                        // position
                new Vector3Df(),                                        // rotation
                new Vector3Df(40, 4.4f, 40),                            // scale
                new Color(255, 255, 255),                               // vertex color
                5,                                                      // max LOD
                TerrainPatchSize._17,                                   // patch size
                4);                                                     // smooth factor

            terrain.SetMaterialFlag(MaterialFlag.Lighting, false);
            terrain.SetMaterialTexture(0, driver.GetTexture("../../media/terrain-texture.jpg"));
            terrain.SetMaterialTexture(1, driver.GetTexture("../../media/detailmap3.jpg"));
            terrain.SetMaterialType(MaterialType.DetailMap);

            terrain.ScaleTexture(1, 20);

            // create triangle selector for the terrain
            TriangleSelector selector = smgr.CreateTerrainTriangleSelector(terrain, 0);

            terrain.TriangleSelector = selector;

            // create collision response animator and attach it to the camera
            SceneNodeAnimator anim = smgr.CreateCollisionResponseAnimator(
                selector, camera,
                new Vector3Df(60, 100, 60),
                new Vector3Df(0, 0, 0),
                new Vector3Df(0, 50, 0));

            selector.Drop();
            camera.AddAnimator(anim);
            anim.Drop();

            // create skybox and skydome
            driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, false);

            SceneNode skybox = smgr.AddSkyBoxSceneNode(
                "../../media/irrlicht2_up.jpg",
                "../../media/irrlicht2_dn.jpg",
                "../../media/irrlicht2_lf.jpg",
                "../../media/irrlicht2_rt.jpg",
                "../../media/irrlicht2_ft.jpg",
                "../../media/irrlicht2_bk.jpg");

            SceneNode skydome = smgr.AddSkyDomeSceneNode(driver.GetTexture("../../media/skydome.jpg"), 16, 8, 0.95f, 2);

            driver.SetTextureCreationFlag(TextureCreationFlag.CreateMipMaps, true);

            // create event receiver
            new MyEventReceiver(device, terrain, skybox, skydome);

            int lastFPS = -1;

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

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

                    driver.EndScene();

                    // display frames per second in window title
                    int fps = driver.FPS;
                    if (lastFPS != fps)
                    {
                        // also print terrain height of current camera position
                        // we can use camera position because terrain is located at coordinate origin

                        device.SetWindowCaption(String.Format(
                                                    "Terrain rendering example - Irrlicht Engine [{0}] fps: {1} Height: {2}",
                                                    driver.Name, fps, terrain.GetHeight(camera.AbsolutePosition.X, camera.AbsolutePosition.Z)));

                        lastFPS = fps;
                    }
                }
            }

            device.Drop();
        }
Пример #3
0
        public void Initialize3D()
        {
            device = new IrrlichtDevice(DriverType.Direct3D9, /* TODO: for Linux/OSX it should be OpenGL */
                                        new Dimension2D(800, 600), 32, false, true, true, true, GetHandle());
            device.FileSystem.WorkingDirectory = "3d";
            device.Resizeable = true;

            // setup a simple 3d scene
            SceneManager sceneManager = device.SceneManager;

            VideoDriver driver = device.VideoDriver;

            camera          = sceneManager.AddCameraSceneNodeFPS(null, 100.0f, 50000.0f, false);
            camera.Position = new Vector3D(1900 * 2, 255 * 2, 3700 * 2);
            camera.Target   = new Vector3D(2397 * 2, 343 * 2, 2700 * 2);
            camera.FarValue = 12000.0f;

            camera.InputReceiverEnabled = false;

            /*
             * Here comes the terrain renderer scene node: We add it just like any
             * other scene node to the scene using ISceneManager::addTerrainSceneNode().
             * The only parameter we use is a file name to the heightmap we use. A heightmap
             * is simply a gray scale texture. The terrain renderer loads it and creates
             * the 3D terrain from it.
             * To make the terrain look more big, we change the scale factor of it to (40, 4.4, 40).
             * Because we don't have any dynamic lights in the scene, we switch off the lighting,
             * and we set the file terrain-texture.jpg as texture for the terrain and
             * detailmap3.jpg as second texture, called detail map. At last, we set
             * the scale values for the texture: The first texture will be repeated only one time over
             * the whole terrain, and the second one (detail map) 20 times.
             */

            terrain = sceneManager.AddTerrainSceneNode("terrain-heightmap.bmp",
                                                       null,                          // parent node
                                                       -1,                            // node id
                                                       new Vector3D(0f, 0f, 0f),      // position
                                                       new Vector3D(0f, 0f, 0f),      // rotation
                                                       new Vector3D(40f, 4.4f, 40f),  // scale
                                                       new Color(255, 255, 255, 255), // vertexColor,
                                                       5,                             // maxLOD
                                                       TerrainPatchSize.TPS17         // patchSize
                                                       );

            terrain.SetMaterialFlag(MaterialFlag.Lighting, false);
            terrain.SetMaterialTexture(0, driver.GetTexture("terrain-texture.jpg"));
            terrain.SetMaterialTexture(1, driver.GetTexture("detailmap3.jpg"));
            terrain.SetMaterialType(MaterialType.DetailMap);
            terrain.ScaleTexture(1.0f, 20.0f);
            //terrain->setDebugDataVisible ( true );

            /*
             * To be able to do collision with the terrain, we create a triangle selector.
             * If you want to know what triangle selectors do, just take a look into the
             * collision tutorial. The terrain triangle selector works together with the
             * terrain. To demonstrate this, we create a collision response animator
             * and attach it to the camera, so that the camera will not be able to fly
             * through the terrain.
             */

            // create triangle selector for the terrain
            TriangleSelector selector = sceneManager.CreateTerrainTriangleSelector(terrain, 0);

            terrain.TriangleSelector = selector;

            // create collision response animator and attach it to the camera
            Animator animator = sceneManager.CreateCollisionResponseAnimator(selector, camera, new Vector3D(60, 100, 60), new Vector3D(0, 0, 0), new Vector3D(0, 50, 0), 0);

            selector.Dispose();
            camera.AddAnimator(animator);
            animator.Dispose();;

            /*
             * To make the user be able to switch between normal and wireframe mode, we create
             * an instance of the event reciever from above and let Irrlicht know about it. In
             * addition, we add the skybox which we already used in lots of Irrlicht examples.
             */

            // create skybox
            driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);

            sceneManager.AddSkyBoxSceneNode(null, new Texture[] {
                driver.GetTexture("irrlicht2_up.jpg"),
                driver.GetTexture("irrlicht2_dn.jpg"),
                driver.GetTexture("irrlicht2_lf.jpg"),
                driver.GetTexture("irrlicht2_rt.jpg"),
                driver.GetTexture("irrlicht2_ft.jpg"),
                driver.GetTexture("irrlicht2_bk.jpg")
            }, -1);

            while (device.Run())
            {
                driver.BeginScene(true, true, new Color());
                sceneManager.DrawAll();
                driver.EndScene();
            }

            device.Dispose();

            return;
        }