Exemplo n.º 1
0
        public override Result Update(float dt)
        {
            if (_heightmap == null)
            {
            }
            else
            {
                _angle += dt * 0.5f;
                var center = _heightmap.Center;
                var eye    = new Vector3(center.X + MathF.Cos(_angle) * center.X * 2.0f, _heightmap.MaxHeight * 8.0f, -center.Y + MathF.Sin(_angle) * center.Y * 2.0f);
                var lookAt = new Vector3(center.X, 0.0f, -center.Y);

                var world = Matrix.Identity;
                var view  = Matrix.LookAtLH(eye, lookAt, new Vector3(0, 1, 0));
                var proj  = Matrix.PerspectiveFovLH(MathF.Pi / 4, 1.3333f, 1.0f, 1000.0f);

                Device.SetTransform(TransformState.World, world);
                Device.SetTransform(TransformState.View, view);
                Device.SetTransform(TransformState.Projection, proj);

                if (Input.IsKeyDown(Key.Space))
                {
                    _image++;
                    if (_image > 2)
                    {
                        _image = 0;
                    }
                    switch (_image)
                    {
                    case 0:
                        _heightmap.LoadFromFile("images/abe.jpg");
                        break;

                    case 1:
                        _heightmap.LoadFromFile("images/smiley.bmp");
                        break;

                    case 2:
                        _heightmap.LoadFromFile("images/heightmap.jpg");
                        break;
                    }
                    _hmRenderer.Release();
                    _hmRenderer = new HeightMapRenderer(_heightmap, Device);
                    _hmRenderer.CreateParticles();
                    Thread.Sleep(300);
                }
            }
            if (Input.IsKeyDown(Key.Escape))
            {
                Quit();
            }
            return(ResultCode.Success);
        }
Exemplo n.º 2
0
        public override Result Update(float dt)
        {
            if (_heightmap == null)
            {
            }
            else
            {
                _angle += dt * 0.5f;
                var center = _heightmap.Center;
                var eye    = new Vector3(center.X + MathF.Cos(_angle) * center.X * 2.0f, _heightmap.MaxHeight * 8.0f, -center.Y + MathF.Sin(_angle) * center.Y * 2.0f);
                var lookAt = new Vector3(center.X, 0.0f, -center.Y);

                var world = Matrix.Identity;
                var view  = Matrix.LookAtLH(eye, lookAt, new Vector3(0, 1, 0));
                var proj  = Matrix.PerspectiveFovLH(MathF.Pi / 4, 1.3333f, 1.0f, 1000.0f);

                Device.SetTransform(TransformState.World, world);
                Device.SetTransform(TransformState.View, view);
                Device.SetTransform(TransformState.Projection, proj);

                if (Input.IsKeyDown(Key.Space))
                {
                    _heightmap.CreateRandomHeightMap(MathF.Rand(2000), _size / 10.0f, _amplitude / 10.0f, 9);
                    _hmRenderer.Release();
                    _hmRenderer = new HeightMapRenderer(_heightmap, Device);
                    _hmRenderer.CreateParticles();
                    Thread.Sleep(100);
                }
            }
            if (Input.IsKeyDown(Key.Escape))
            {
                Quit();
                return(ResultCode.Success);
            }
            if (Input.IsKeyDown(Key.DownArrow) && _size > 1)
            {
                _size--; Thread.Sleep(100);
            }
            if (Input.IsKeyDown(Key.UpArrow) && _size < 20)
            {
                _size++; Thread.Sleep(100);
            }
            if (Input.IsKeyDown(Key.LeftArrow) && _amplitude > 1)
            {
                _amplitude--; Thread.Sleep(100);
            }
            if (Input.IsKeyDown(Key.RightArrow) && _amplitude < 15)
            {
                _amplitude++; Thread.Sleep(100);
            }
            return(ResultCode.Success);
        }
Exemplo n.º 3
0
 public override Result Cleanup()
 {
     ReleaseCom(Font);
     ReleaseCom(Device);
     _heightmap.Release();
     _hmRenderer.Release();
     Debug.Print("Application terminated");
     return(ResultCode.Success);
 }