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)); } }
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(); }
public Clipmap(SceneManager scene) { _scene = scene; _scene.RenderQueueStarted += (byte groupId, string invocation, out bool skipThisInvocation) => { if (groupId == _scene.RenderQueue.DefaultQueueGroup) { QueuePatches(_scene.RenderQueue); } skipThisInvocation = 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.PF_FLOAT32_RGB; tu.SetTextureFiltering(FilterOptions.FO_POINT, FilterOptions.FO_POINT, FilterOptions.FO_NONE); tu.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_WRAP); tu.SetBindingType(TextureUnitState.BindingType.BT_VERTEX); _shader.SetAuto(() => _shader.ModelViewProjectionMatrix, GpuProgramParameters.AutoConstantType.ACT_WORLDVIEWPROJ_MATRIX); //_shader.SetAuto(() => _shader.NormalMatrix, GpuProgramParameters.AutoConstantType.ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX); _shader.SetAuto(() => _shader.ScaleFactor, GpuProgramParameters.AutoConstantType.ACT_CUSTOM, 0); _shader.SetAuto(() => _shader.FineBlockOrigin, GpuProgramParameters.AutoConstantType.ACT_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; }