Beispiel #1
0
        public static void Main()
        {
            IrrlichtDevice device = new IrrlichtDevice(DriverType.OpenGL,
                                                    new Dimension2D(640, 480),
                                                    32, false, true, true, true);

            device.FileSystem.WorkingDirectory = "../../medias";
            device.OnEvent += new OnEventDelegate(device_OnEvent);

            string caption = "Irrlicht .NET CP ATMOSpere test";

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

            terrain = scene.AddTerrainSceneNode(
                "terrain-heightmap.bmp", null, -1,
                new Vector3D(0,0,0), new Vector3D(1,1,1), new Vector3D(40, 4.4f, 40), new Color(255, 255, 255, 255),5,TerrainPatchSize.TPS17);

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

            terrain.ScaleTexture(1.0f, 20.0f);

               	atmo = new ATMOSphere(device.Timer, null, scene, -1);
               	atmo.SkyTexture = driver.GetTexture("sky2.tga");
               	atmo.SunTexture = driver.GetTexture("sun.tga");
               	atmo.StarsTexture = driver.GetTexture("stars.bmp");
               	atmo.CreateSkyPalette();
            atmo.Speed = 600.0f;

                                KeyMap keyMap = new KeyMap();
                    keyMap.AssignAction(KeyAction.MoveForward,KeyCode.Key_W);
                    keyMap.AssignAction(KeyAction.MoveBackward,KeyCode.Key_S);
                    keyMap.AssignAction(KeyAction.StrafeLeft,KeyCode.Key_A);
                    keyMap.AssignAction(KeyAction.StrafeRight,KeyCode.Key_D);

            CameraSceneNode fpsCam = scene.AddCameraSceneNodeFPS(null, 50, 200, false, keyMap);
            fpsCam.Position = Vector3D.From(2200,440,2000);

            device.CursorControl.Visible = false;
            driver.SetTextureFlag(TextureCreationFlag.Always32Bit, true);
            Timer timer = device.Timer;

            new ATMOSkytest();

            while (device.Run() && !Exit)
            {
                driver.BeginScene(true, true, Color.Gray);
               			atmo.Update(device.Timer.RealTime);
                scene.DrawAll();
                driver.EndScene();

            }
        }
Beispiel #2
0
 public void ApplyClampingOnTerrain(TerrainSceneNode terrain)
 {
     clampList.Add(terrain);
 }
 /// <summary>
 /// Creates an optimized-for-terrain triangle selector
 /// </summary>
 /// <returns>A TriangleSelector</returns>
 /// <param name="terrain">Terrain whose the mesh is used</param>
 /// <param name="LOD">Level of Detail, 0 is for the maximal</param>
 public TriangleSelector CreateTerrainTriangleSelector(TerrainSceneNode terrain, int LOD)
 {
     return (TriangleSelector)
         NativeElement.GetObject(SceneManager_CreateTerrainTriangleSelector(_raw, terrain.Raw, LOD),
                                 typeof(TriangleSelector));
 }
Beispiel #4
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;
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            // ask user for driver
            DriverType driverType = DriverType.OpenGL;

            // Ask user to select driver:
            // Create device and exit if creation fails:
            device = new IrrlichtDevice(driverType, new Dimension2D(640, 480), 32, false, true, true, true);
            device.FileSystem.WorkingDirectory = "../../medias"; //We set Irrlicht's current directory to %application directory%/media
            //MyEventReceiver receiver(room, env, driver);
            device.OnEvent += new OnEventDelegate(device_OnEvent); //We had a simple delegate that will handle every event

            /*************************************************/
            /* First, we add standard stuff to the scene: A nice irrlicht engine logo,
               a small help text, a user controlled camera, and we disable the mouse
               cursor.*/
            SceneManager smgr = device.SceneManager;
            VideoDriver driver = device.VideoDriver;
            GUIEnvironment env = device.GUIEnvironment;

            driver.SetTextureFlag(TextureCreationFlag.Always32Bit, true);

            // add irrlicht logo
            env.AddImage(driver.GetTexture("NETCPlogo.png"),
                new Position2D(10, 10), true, null, 0, "");

            // add some help text
            GUIStaticText text = env.AddStaticText(
                "Press 'W' to change wireframe mode\nPress 'D' to toggle detail map",
                new Rect(new Position2D(10, 453), new Position2D(200, 475)), true, true, null, -1,true);

            // add camera
            CameraSceneNode camera =
                smgr.AddCameraSceneNodeFPS(null, 100.0f, 1200.0f, false);
            camera.Position = new Vector3D(1900 * 2, 255 * 2, 3700 * 2);
            camera.Target = new Vector3D(2397 * 2, 343 * 2, 2700 * 2);
            camera.FarValue = 120000.0f;

            // disable mouse cursor
            device.CursorControl.Visible = 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.
             */
            // add terrain scene node
            terrain = smgr.AddTerrainSceneNode(
                "terrain-heightmap.bmp", null, -1,
                new Vector3D(0,0,0), new Vector3D(1,1,1), new Vector3D(40, 4.4f, 40), new Color(255, 255, 255, 255),3,TerrainPatchSize.TPS9);

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

            terrain.ScaleTexture(1.0f, 20.0f);

            /*WaterSceneNode water = new WaterSceneNode(null, smgr, new Dimension2Df(64,64), new Dimension2D(100,100));
            water.Position = new Vector3D(1900 * 2, 255 * 2, 3700 * 2);*/

            /* 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 =
                smgr.CreateTerrainTriangleSelector(terrain, 0);

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

            //we add the skybox which we already used in lots of Irrlicht examples.
            driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);

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

            driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, true);

            /* That's it, draw everything. Now you know how to use terrain
               in Irrlicht.
            */
            int lastFPS = -1;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    driver.BeginScene(true, true, new Color(0, 200, 200, 200));
                    smgr.DrawAll();
                    env.DrawAll();
                    driver.EndScene();

                    int fps = device.VideoDriver.FPS;
                    if (lastFPS != fps)
                    {
                        device.WindowCaption = "Terrain Renderer - Irrlicht Engine " +
                            "FPS:" + fps.ToString();
                        lastFPS = fps;
                    }
                }
            }

            /*
            In the end, delete the Irrlicht device.
            */
            device.Close();
        }