Пример #1
0
        private void _initBlendMaps(Axiom.Components.Terrain.Terrain terrain)
        {
            var  blendMap0  = terrain.GetLayerBlendMap(1);
            var  blendMap1  = terrain.GetLayerBlendMap(2);
            Real minHeight0 = 70;
            Real fadeDist0  = 40;
            Real minHeight1 = 70;
            Real fadeDist1  = 15;

            var pBlend1  = blendMap1.BlendPointer;
            var blendIdx = 0;

            for (var y = 0; y < terrain.LayerBlendMapSize; y++)
            {
                for (var x = 0; x < terrain.LayerBlendMapSize; x++)
                {
                    Real tx = 0;
                    Real ty = 0;
                    blendMap0.ConvertImageToTerrainSpace(x, y, ref tx, ref ty);
                    Real height = terrain.GetHeightAtTerrainPosition(tx, ty);
                    Real val    = (height - minHeight0) / fadeDist0;
                    val = Utility.Clamp(val, 0, 1);

                    val = (height - minHeight1) / fadeDist1;
                    val = Utility.Clamp(val, 0, 1);
                    pBlend1[blendIdx++] = val;
                }
            }

            blendMap0.Dirty();
            blendMap1.Dirty();
            blendMap0.Update();
            blendMap1.Update();
        }
Пример #2
0
        public void DoTerrainModify(Axiom.Components.Terrain.Terrain terrain, Vector3 centrepos, Real timeElapsed)
        {
            var tsPos = Vector3.Zero;

            terrain.GetTerrainPosition(centrepos, ref tsPos);

#if !(WINDOWS_PHONE || XBOX || XBOX360 || ANDROID || IOS)
            if (Keyboard.IsKeyDown(SIS.KeyCode.Key_EQUALS) || Keyboard.IsKeyDown(SIS.KeyCode.Key_ADD) ||
                Keyboard.IsKeyDown(SIS.KeyCode.Key_MINUS) || Keyboard.IsKeyDown(SIS.KeyCode.Key_SUBTRACT))
            {
                switch (this.mode)
                {
                case Mode.EditHeight:
                {
                    // we need point coords
                    Real terrainSize = (terrain.Size - 1);
                    var  startx      = (long)((tsPos.x - this.brushSizeTerrainSpace) * terrainSize);
                    var  starty      = (long)((tsPos.y - this.brushSizeTerrainSpace) * terrainSize);
                    var  endx        = (long)((tsPos.x + this.brushSizeTerrainSpace) * terrainSize);
                    var  endy        = (long)((tsPos.y + this.brushSizeTerrainSpace) * terrainSize);
                    startx = Utility.Max(startx, 0L);
                    starty = Utility.Max(starty, 0L);
                    endx   = Utility.Min(endx, (long)terrainSize);
                    endy   = Utility.Min(endy, (long)terrainSize);
                    for (long y = starty; y <= endy; ++y)
                    {
                        for (long x = startx; x <= endx; ++x)
                        {
                            Real tsXdist = (x / terrainSize) - tsPos.x;
                            Real tsYdist = (y / terrainSize) - tsPos.y;

                            Real weight = Utility.Min((Real)1.0,
                                                      Utility.Sqrt(tsYdist * tsYdist + tsXdist * tsXdist) /
                                                      (Real)(0.5 * this.brushSizeTerrainSpace));
                            weight = 1.0 - (weight * weight);

                            var   addedHeight = weight * 250.0 * timeElapsed;
                            float newheight;
                            if (Keyboard.IsKeyDown(SIS.KeyCode.Key_EQUALS) || Keyboard.IsKeyDown(SIS.KeyCode.Key_ADD))
                            {
                                newheight = terrain.GetHeightAtPoint(x, y) + addedHeight;
                            }
                            else
                            {
                                newheight = terrain.GetHeightAtPoint(x, y) - addedHeight;
                            }
                            terrain.SetHeightAtPoint(x, y, newheight);
                        }
                    }
                    if (this.heightUpdateCountDown == 0)
                    {
                        this.heightUpdateCountDown = this.heightUpdateRate;
                    }
                }
                break;

                case Mode.EditBlend:
                {
                    var layer = terrain.GetLayerBlendMap(this.layerEdit);
                    // we need image coords
                    Real imgSize = terrain.LayerBlendMapSize;
                    var  startx  = (long)((tsPos.x - this.brushSizeTerrainSpace) * imgSize);
                    var  starty  = (long)((tsPos.y - this.brushSizeTerrainSpace) * imgSize);
                    var  endx    = (long)((tsPos.x + this.brushSizeTerrainSpace) * imgSize);
                    var  endy    = (long)((tsPos.y + this.brushSizeTerrainSpace) * imgSize);
                    startx = Utility.Max(startx, 0L);
                    starty = Utility.Max(starty, 0L);
                    endx   = Utility.Min(endx, (long)imgSize);
                    endy   = Utility.Min(endy, (long)imgSize);
                    for (var y = (int)starty; y <= endy; ++y)
                    {
                        for (var x = (int)startx; x <= endx; ++x)
                        {
                            Real tsXdist = (x / imgSize) - tsPos.x;
                            Real tsYdist = (y / imgSize) - tsPos.y;

                            Real weight = Utility.Min((Real)1.0,
                                                      Utility.Sqrt(tsYdist * tsYdist + tsXdist * tsXdist) /
                                                      (Real)(0.5 * this.brushSizeTerrainSpace));
                            weight = 1.0 - (weight * weight);

                            float paint = weight * timeElapsed;
                            var   imgY  = (int)(imgSize - y);
                            float val;
                            if (Keyboard.IsKeyDown(SIS.KeyCode.Key_EQUALS) || Keyboard.IsKeyDown(SIS.KeyCode.Key_ADD))
                            {
                                val = layer.GetBlendValue(x, imgY) + paint;
                            }
                            else
                            {
                                val = layer.GetBlendValue(x, imgY) - paint;
                            }
                            val = Utility.Clamp(val, 1.0f, 0.0f);
                            layer.SetBlendValue(x, imgY, val);
                        }
                    }

                    layer.Update();
                }
                break;

                case Mode.Normal:
                case Mode.Count:
                default:
                    break;
                }
                ;
            }
#endif
        }