Exemple #1
0
        public override Result Init(int width, int height, bool windowed)
        {
            CreateWindow(width, height);
            Device = CreateDevice(width, height, windowed);
            if (Device == null)
            {
                return(ResultCode.Failure);
            }

            Font = new Font(Device, 18, 0, FontWeight.Bold, 1, false, CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.Default | PitchAndFamily.DontCare, "Arial");

            _heightmap = new HeightMap(Device, new Point(100, 100), 15.0f);
            if (_heightmap.CreateRandomHeightMap(MathF.Rand(2000), _size / 10.0f, _amplitude / 10.0f, 9).IsFailure)
            {
                Debug.Print("Failed to create random heightmap");
                Quit();
            }
            _hmRenderer = new HeightMapRenderer(_heightmap, Device);

            if (_hmRenderer.CreateParticles().IsFailure)
            {
                Debug.Print("Failed to create particles");
                Quit();
            }

            IsRunning = true;


            return(ResultCode.Success);
        }
        public override Result Init(int width, int height, bool windowed)
        {
            CreateWindow(width, height);
            Device = CreateDevice(width, height, windowed);
            if (Device == null)
            {
                return(ResultCode.Failure);
            }

            Font = new Font(Device, 18, 0, FontWeight.Bold, 1, false, CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.Default | PitchAndFamily.DontCare, "Arial");

            _heightmap = new HeightMap(Device, new Point(100, 100), 15.0f);
            if (_heightmap.LoadFromFile("images/abe.jpg").IsFailure)
            {
                Debug.Print("failed to load from file");
                Quit();
            }

            _hmRenderer = new HeightMapRenderer(_heightmap, Device);

            if (_hmRenderer.CreateParticles().IsFailure)
            {
                Debug.Print("Failed to create particles");
                Quit();
            }

            IsRunning = true;

            return(ResultCode.Success);
        }
        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);
        }
Exemple #4
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);
        }
        public override Result Init(int width, int height, bool windowed)
        {
            CreateWindow(width, height);
            Device = CreateDevice(width, height, windowed);
            if (Device == null)
            {
                return(ResultCode.Failure);
            }

            Font = new Font(Device, 18, 0, FontWeight.Bold, 1, false, CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.Default | PitchAndFamily.DontCare, "Arial");

            _heightmap = new HeightMap(Device, new Point(50, 50), 15.0f);



            _hmRenderer = new HeightMapRenderer(_heightmap, Device)
            {
                ShowSelection = true
            };

            _heightmap.Renderer = _hmRenderer;

            _editor            = new HeightMapEditorSelection(_heightmap, _hmRenderer);
            _hmRenderer.Editor = _editor;

            if (_hmRenderer.CreateParticles().IsFailure)
            {
                Debug.Print("Failed to create particles");
                Quit();
            }


            IsRunning = true;


            return(ResultCode.Success);
        }