Exemplo n.º 1
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
		}