Пример #1
0
        public static void Keyboard_KeyDown(ref ICubeMap cubeMap, ICamera camera, ILight light, ITerrain terrain, ref Vector3 initCameraPosition, ref float cameraAngle, float farDist, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Up:
                initCameraPosition = CameraFoward(camera, initCameraPosition, cameraAngle, farDist);
                break;

            case Key.Down:
                initCameraPosition = CameraBackward(camera, initCameraPosition, cameraAngle, farDist);
                break;

            case Key.Right:
                cameraAngle = CameraRight(camera, cameraAngle, farDist);
                break;

            case Key.Left:
                cameraAngle = CameraLeft(camera, cameraAngle, farDist);
                break;

            case Key.A:
                initCameraPosition = CameraUp(camera, initCameraPosition, cameraAngle, farDist);
                break;

            case Key.Z:
                initCameraPosition = CameraDown(camera, initCameraPosition, cameraAngle, farDist);
                break;

            case Key.W:
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                break;

            case Key.S:
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                break;

            case Key.M:
                UIInputData.IsMapOn = true;
                break;

            case Key.Escape:
                UIInputData.IsMapOn = false;
                break;

            case Key.T:
                UIInputData.IsTerrainOn = true;
                UIInputData.IsOceanOn   = false;
                break;

            case Key.O:
                UIInputData.IsTerrainOn = false;
                UIInputData.IsOceanOn   = true;
                break;

            case Key.R:
                UIInputData.FresnelParameter += 0.1f;
                break;

            case Key.F:
                UIInputData.FresnelParameter -= 0.1f;
                break;

            case Key.C:
                if (UIInputData.IsWoodenChestOn)
                {
                    UIInputData.IsWoodenChestOn = false;
                }
                else
                {
                    UIInputData.IsWoodenChestOn = true;
                }
                break;

            case Key.F1:
                UIInputData.IsWaterCalm = false;
                break;

            case Key.F2:
                UIInputData.IsWaterCalm = true;
                break;

            case Key.F12:
                UIInputData.StormParameter = new float[] { 2, 1.5f, 1.5f, 4, 2 };
                break;

            case Key.F11:
                UIInputData.StormParameter = new float[] { 1, 1, 1, 1, 1 };
                break;

            case Key.D:
                if (UIInputData.isDiffuseOn)
                {
                    UIInputData.isDiffuseOn = false;
                }
                else
                {
                    UIInputData.isDiffuseOn = true;
                }
                break;

            case Key.F3:
                Vector3 pos = light.LightPosition;
                light.LightPosition = new Vector3(pos.X + 1.0f, light.LightPosition.Y, light.LightPosition.Z);
                break;

            case Key.F4:
                pos = light.LightPosition;
                light.LightPosition = new Vector3(pos.X - 1.0f, light.LightPosition.Y, light.LightPosition.Z);
                break;

            case Key.F5:
                pos = light.LightPosition;
                light.LightPosition = new Vector3(pos.X, light.LightPosition.Y + 1.0f, light.LightPosition.Z);
                break;

            case Key.F6:
                pos = light.LightPosition;
                light.LightPosition = new Vector3(pos.X, light.LightPosition.Y - 1.0f, light.LightPosition.Z);
                break;

            case Key.F7:
                pos = light.LightPosition;
                light.LightPosition = new Vector3(pos.X, light.LightPosition.Y, light.LightPosition.Z + 1.0f);
                break;

            case Key.F8:
                pos = light.LightPosition;
                light.LightPosition = new Vector3(pos.X, light.LightPosition.Y, light.LightPosition.Z - 1.0f);
                break;

            case Key.Number1:
                ChangeCubeMap(ref cubeMap, "Mountain");
                break;

            case Key.Number2:
                ChangeCubeMap(ref cubeMap, "Desert");
                break;

            case Key.Number3:
                ChangeCubeMap(ref cubeMap, "Frozen");
                break;

            case Key.Number4:
                ChangeCubeMap(ref cubeMap, "Spooky");
                break;

            case Key.Number5:
                terrain.Load(true);
                break;

            case Key.Number6:
                terrain.Load(true, true);
                break;
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var gameWindow = new GameWindow(WindowWidth, WindowHeight, new GraphicsMode(32, 24, 0, 8), "Ocean sim (Grestner waves) and terrain", GameWindowFlags.Default, DisplayDevice.AvailableDisplays.Last());

            gameWindow.MakeCurrent();
            gameWindow.Context.LoadAll();

            Utils.Utils.GLRenderProperties(WindowWidth, WindowHeight);

            _camera = Factory <Camera.Camera> .Create(_cameraPosition0, LookAt0, new Vector3(0, 1, 0));


            _light = LightFactory.Create(new Vector3(-350.0f, 300.0f, 0.0f), new Color4(255, 255, 255, 1), new Color4(255, 255, 255, 1), new Color4(252, 252, 252, 1), LightName.Light0);
            _light.Load();



            _terrain = Terrainfactory.Create(Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.TOPOMAP1.GIF"),
                                             Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.Dirt.jpg"),
                                             Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.sand.jpg"),
                                             Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.Grass.png"),
                                             Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.Rock.png"));
            _terrain.Load();


            _cubeMap = CubeMapFactory.Create(2500, false, new Vector3(256, 0, 256),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_front.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_back.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_front.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_top.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_left.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_right.jpg")
                                             );
            _cubeMap.Load();

            _woodenChest = CubeMapFactory.Create(100, true, new Vector3(256, 150, 256), Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.plank.jpg"));
            _woodenChest.Load();

            _water = new Water(WaterWidth, WaterHeight);
            _water.Load();

            _seaBed = PlaneFactory.Create(true, new Vbo()
            {
                Position = new Vector3(0, -70, 0), Normal = new Vector3(0, 1, 0), TexCoord = new Vector2(0, 0)
            },
                                          new Vbo()
            {
                Position = new Vector3(0, -70, WaterHeight), Normal = new Vector3(0, 1, 0), TexCoord = new Vector2(0, 1)
            },
                                          new Vbo()
            {
                Position = new Vector3(WaterWidth, -70, WaterHeight), Normal = new Vector3(0, 1, 0), TexCoord = new Vector2(1, 1)
            },
                                          new Vbo()
            {
                Position = new Vector3(WaterWidth, -70, 0), Normal = new Vector3(0, 1, 0), TexCoord = new Vector2(1, 0)
            },
                                          Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.seabed.jpg"), TextureWrapMode.ClampToEdge);
            _seaBed.Load();

            _birdTexture = FramBufferOBjectFactory.Create(512, 512);
            _birdTexture.Load();

            gameWindow.RenderFrame += gameWindow_RenderFrame;
            gameWindow.UpdateFrame += gameWindow_UpdateFrame;

            gameWindow.Keyboard.KeyDown += Keyboard_KeyDown;
            gameWindow.Run(60.0, 30.0);
        }