예제 #1
0
        public void SetPosition2(IntFloatVector2 pos)
        {
            var x    = pos.X.Integer * 2 + 1;
            var y    = pos.Y.Integer * 2 + 1;
            var oldX = Position.X.Integer * 2 + 1;
            var oldY = Position.Y.Integer * 2 + 1;

            Position = pos;

            // for slice updates we are only interested in the integer part
            if (x == oldX && y == oldY)
            {
                return;
            }

            if (y > oldY)
            {
                UpdateRows((_n - oldY) & _n, Math.Min((y - oldY), _n));
            }
            else if (oldY > y)
            {
                UpdateRows((_n - y) & _n, Math.Min((oldY - y), _n));
            }

            if (x > oldX)
            {
                UpdateColumns((_n - oldX) & _n, Math.Min((x - oldX), _n));
            }
            else if (oldX > x)
            {
                UpdateColumns((_n - x) & _n, Math.Min((oldX - x), _n));
            }
        }
예제 #2
0
        public void MoveBy(float dx, float dy)
        {
            if (Math.Abs(dx) < 0.0000001f && Math.Abs(dy) < 0.0000001f)
            {
                return;
            }

            Position = Position.MoveBy(dx, dy);
            UpdatePosition();
        }
예제 #3
0
        public Clipmap(SceneManager scene)
        {
            _scene = scene;
            _scene.QueueStarted += (sender, args) =>
            {
                if (args.RenderQueueId == _scene.GetRenderQueue().DefaultRenderGroup)
                {
                    QueuePatches(_scene.GetRenderQueue());
                }
                args.SkipInvocation = false;
            };

            using (var testMap = (Bitmap)Image.FromFile(@"height.jpg"))
            {
                _testMapWidth  = testMap.Width;
                _testMapHeight = testMap.Height;
                _testMap       = new float[_testMapWidth * _testMapHeight];
                var i = 0;
                for (var y = 0; y < testMap.Height; y++)
                {
                    for (var x = 0; x < testMap.Width; x++)
                    {
                        _testMap[i++] = testMap.GetPixel(x, y).R / 255.0f;
                    }
                }
            }


            var tu = _shader.Sampler(() => _shader.Heightmap);

            tu.DesiredFormat = PixelFormat.FLOAT32_RGB;
            tu.SetTextureFiltering(FilterOptions.Point, FilterOptions.Point, FilterOptions.None);
            tu.SetTextureAddressingMode(TextureAddressing.Wrap);
            tu.BindingType = TextureBindingType.Vertex;

            _shader.SetAuto(() => _shader.ModelViewProjectionMatrix, GpuProgramParameters.AutoConstantType.WorldViewProjMatrix);
            //_shader.SetAuto(() => _shader.NormalMatrix, GpuProgramParameters.AutoConstantType.ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX);
            _shader.SetAuto(() => _shader.ScaleFactor, GpuProgramParameters.AutoConstantType.Custom, 0);
            _shader.SetAuto(() => _shader.FineBlockOrigin, GpuProgramParameters.AutoConstantType.Custom, 1);

            Position = new IntFloatVector2(new IntFloat(-_testMapWidth / 4), new IntFloat(-_testMapHeight / 4));

            Locations = new PatchLocations(H, M);

            var scale    = Scale;
            var scaleInt = 1;

            for (var i = 0; i < Levels; i++)
            {
                _levels[i] = new ClipmapLevel(scale, scaleInt, this);
                var level = _levels[i];
                tu.SetTextureName(level.Heightmap.Name);
                var m = _shader.CloneMaterial("ClipmapLevel" + i);
                _levels[i].Material = m;

                scale    *= 2.0f;
                scaleInt *= 2;
            }

            UpdatePosition();
            Reset();

            _initialized = true;
        }