Esempio n. 1
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="terrain"></param>
		private void InitBlendMaps( Axiom.Components.Terrain.Terrain terrain )
		{

			TerrainLayerBlendMap blendMap0 = terrain.GetLayerBlendMap( 1 );
			TerrainLayerBlendMap blendMap1 = terrain.GetLayerBlendMap( 2 );
			Real minHeight0 = 70;
			Real fadeDist0 = 40;
			Real minHeight1 = 70;
			Real fadeDist1 = 15;

			float[] pBlend1 = blendMap1.BlendPointer;
			int blendIdx = 0;
			for ( ushort y = 0; y < terrain.LayerBlendMapSize; y++ )
			{
				for ( ushort x = 0; x < terrain.LayerBlendMapSize; x++ )
				{
					float tx = 0;
					float 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();

		}
Esempio n. 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
		}