Beispiel #1
0
		public void ClampExtrudeAddHeightmap (Geovox.Matrix2<float> heights, Geovox.Matrix2<float> depth, byte type, int margins=0) //clamps/extrudes terrain to height-depth, adds depth with selected type
		{
			for (int x = heights.offsetX+margins; x<heights.offsetX+heights.sizeX-margins; x++) 
				for (int z = heights.offsetZ+margins; z<heights.offsetZ+heights.sizeZ-margins; z++)
			{
				Column column = WriteColumn(x,z);
				int clampLevel = (int)(heights[x,z] - depth[x,z]);
				
				column.Clamp(clampLevel); //clamp
				column.AddBlocks( column.GetTopType(), clampLevel - column.GetTopPoint() ); //extruding to clamp level
				column.AddBlocks( type, (int)depth[x,z] ); //adding type
			}
		}
Beispiel #2
0
		public void ExtrudeHeightmap (Geovox.Matrix2<float> heights, int margins=0) //raises the last block type so that data is never lower than heightmap
		{
			for (int x = heights.offsetX+margins; x<heights.offsetX+heights.sizeX-margins; x++) 
				for (int z = heights.offsetZ+margins; z<heights.offsetZ+heights.sizeZ-margins; z++)
					WriteColumn(x,z).AddBlocks( GetTopType(x,z), (int)heights[x,z]-GetTopPoint(x,z) );
		}
Beispiel #3
0
		public void ClampExtrudeHeightmap (Geovox.Matrix2<float> heights, int margins=0) //clamps and extrudes top type to level, so data become exactly the same as heightmap
		{
			for (int x = heights.offsetX+margins; x<heights.offsetX+heights.sizeX-margins; x++) 
				for (int z = heights.offsetZ+margins; z<heights.offsetZ+heights.sizeZ-margins; z++)
			{
				Column column = WriteColumn(x,z);
				int clampLevel = (int)heights[x,z];
				
				column.Clamp(clampLevel); //clamp
				column.AddBlocks( column.GetTopType(), clampLevel - column.GetTopPoint() ); //extruding to clamp level
			}
		}
Beispiel #4
0
		public void AddHeightmap (Geovox.Matrix2<float> heights, byte type, int margins=0)
		{
			for (int x = heights.offsetX+margins; x<heights.offsetX+heights.sizeX-margins; x++) 
				for (int z = heights.offsetZ+margins; z<heights.offsetZ+heights.sizeZ-margins; z++)
					WriteColumn(x,z).AddBlocks( type, (int)heights[x,z]);
		}
Beispiel #5
0
		public void MaxHeightmap (Geovox.Matrix2<float> heights, byte type, int margins=0) //same as add, but existing height is subtracted from add level
		{
			for (int x = heights.offsetX+margins; x<heights.offsetX+heights.sizeX-margins; x++) 
				for (int z = heights.offsetZ+margins; z<heights.offsetZ+heights.sizeZ-margins; z++)
					WriteColumn(x,z).AddBlocks( type, Mathf.Max(0, (int)heights[x,z]-ReadColumn(x,z).GetTopPoint()) );
		}
Beispiel #6
0
		public void ToHeightMatrix (Geovox.Matrix2<int> heights, bool[] exist, int margins=0)
		{
			//TODO: use exist array
			for (int x = heights.offsetX+margins; x<heights.offsetX+heights.sizeX-margins; x++) 
				for (int z = heights.offsetZ+margins; z<heights.offsetZ+heights.sizeZ-margins; z++)
					heights[x,z] = GetTopPoint(x,z,exist);
		}
Beispiel #7
0
		public void ClampHeightmap (Geovox.Matrix2<float> heights, int margins=0)
		{
			for (int x = heights.offsetX+margins; x<heights.offsetX+heights.sizeX-margins; x++) 
				for (int z = heights.offsetZ+margins; z<heights.offsetZ+heights.sizeZ-margins; z++)
					WriteColumn(x,z).Clamp( (int)heights[x,z] );
		}
Beispiel #8
0
		public void ToExistMatrix (Geovox.Matrix3<byte> matrix, bool[] exist)
		{
			for (int x = matrix.offsetX; x<matrix.offsetX+matrix.sizeX; x++) 
				for (int z = matrix.offsetZ; z<matrix.offsetZ+matrix.sizeZ; z++)
					ReadColumn(x,z).ToExistMatrix(matrix, exist, x,z);
		}
Beispiel #9
0
		public void SetBlocksWithMask (byte type, Geovox.Matrix3<bool> mask)
		{
			for (int x = mask.offsetX; x<mask.offsetX+mask.sizeX; x++) 
				for (int z = mask.offsetZ; z<mask.offsetZ+mask.sizeZ; z++)
			{
				//checking if this column needs to be set
				bool set = false;
				mask.SetPos(x,mask.offsetY,z);
				for (int y=mask.offsetY; y<mask.offsetY+mask.sizeY; y++)
				{
					if (mask.current) { set=true; break; }
					mask.MovePosNextY();
				}
				
				//setting
				if (set) WriteColumn(x,z).SetBlocksWithMask(type, mask, x, z);
			}
		}
Beispiel #10
0
			/*public void FromMatrix (Matrix2<byte> matrix, int x) //for grass
				{
					list.Clear();
					matrix.SetPos(x, 0);
				
					byte curType = 255; //should be unequal to matrix.current

					for (int z=0; z<matrix.offsetZ+matrix.sizeZ; z++)
					{
						if (matrix.current != curType || list[list.Count-1] >= specialLevel) //if type changed or prev level is more than 245 - creating new list entry
						{
							curType = matrix.current;
						
							list.Add(curType); //type
							list.Add(0);	//depth
						}
					
						list[list.Count-1]++; //adding depth to last entry
						matrix.MovePosNextZ();
					}
				
					//removing top level
					while (list.Count != 0 && list[list.Count-2]==0)
						list.RemoveRange(list.Count-2, 2);
				}*/
			
			public void SetBlocksWithMask (byte t, Geovox.Matrix3<bool> mask, int x, int z)
			{
				ToMatrix(setBlockMatrix, 0,0);
				
				mask.SetPos(x,mask.offsetY,z);
				setBlockMatrix.SetPos(0,mask.offsetY,0);
				
				for (int y=mask.offsetY; y<mask.offsetY+mask.sizeY; y++)
				{
					if (mask.current) setBlockMatrix[0,y,0] = t;
					mask.MovePosNextY();
					setBlockMatrix.MovePosNextY();
				}
				
				FromMatrix(setBlockMatrix, 0,0);
			}
Beispiel #11
0
			public void FromMatrix (Geovox.Matrix3<byte> matrix, int x, int z)
			{
				list.Clear();
				matrix.SetPos(x, 0, z);
				
				byte curType = 255; //should be unequal to matrix.current
				
				for (int y=0; y<matrix.offsetY+matrix.sizeY; y++)
				{
					if (matrix.current != curType || list[list.Count-1] >= specialLevel) //if type changed or prev level is more than 245 - creating new list entry
					{
						curType = matrix.current;
						
						list.Add(curType); //type
						list.Add(0);	//depth
					}
					
					list[list.Count-1]++; //adding depth to last entry
					matrix.MovePosNextY();
				}
				
				//removing top level
				while (list.Count != 0 && list[list.Count-2]==0)
					list.RemoveRange(list.Count-2, 2);
			}
Beispiel #12
0
			public void ToExistMatrix (Geovox.Matrix3<byte> matrix, bool[] exist, int x, int z) //0 if block is empty, 255 if filled
			{
				matrix.SetPos(x, matrix.offsetY, z);
				
				//resetting matrix if column empty
				if(list.Count==0)
				{
					for(int y=matrix.offsetY;y<matrix.offsetY+matrix.sizeY;y++)
					{
						matrix.current = 0;
						matrix.MovePosNextY();
					}
					return;
				}
				
				//writing byte column to matrix
				int i = 0;
				int curMaxLevel = GetLevel(0);
				byte curType = GetType(0);
				
				for(int y=0; y<matrix.offsetY+matrix.sizeY; y++) //starting from 0, not from offsetY
				{
					//changing cur type if reached type max level
					if(y >= curMaxLevel)
					{
						i++;
						
						if(i >= count) curType = 0;
						else
						{
							curType = GetType(i);
							if (curType >= exist.Length) curType = 0;
							curMaxLevel += GetLevel(i);
						}
					}
					
					//filling matrix
					if(y >= matrix.offsetY)
					{
						//matrix.current = exist[curType] ? 255 | 0;
						if (curType>=exist.Length) curType=0;
						
						if (exist[curType]) matrix.current = 255;
						else matrix.current = 0;
						
						matrix.MovePosNextY();
					}
				}
			}
Beispiel #13
0
			public void ToMatrix (Geovox.Matrix3<byte> matrix, int x, int z) 
			{
				matrix.SetPos(x, matrix.offsetY, z);
				
				//resetting matrix if column empty
				if(list.Count==0)
				{
					for(int y=matrix.offsetY;y<matrix.offsetY+matrix.sizeY;y++)
					{
						matrix.current = 0;
						matrix.MovePosNextY();
					}
					return;
				}
				
				//writing byte column to matrix
				int i = 0;
				int curMaxLevel = GetLevel(0);
				byte curType = GetType(0);
				
				for(int y=0; y<matrix.offsetY+matrix.sizeY; y++) //starting from 0, not from offsetY
				{
					//changing cur type if reached type max level
					if(y >= curMaxLevel)
					{
						i++;
						
						if(i >= count) curType = 0;
						else
						{
							curType = GetType(i);
							curMaxLevel += GetLevel(i);
						}
					}
					
					//filling matrix
					if(y >= matrix.offsetY)
					{
						matrix.current = curType;
						matrix.MovePosNextY();
					}
				}
			}
Beispiel #14
0
		public void SetColumnMatrix (Geovox.Matrix2<Column> matrix)
		{
			for (int x = matrix.offsetX; x<matrix.offsetX+matrix.sizeX; x++) 
				for (int z = matrix.offsetZ; z<matrix.offsetZ+matrix.sizeZ; z++)
			{
				//manually copy column list (as column is the struct)
				List<byte> list = WriteColumn(x,z).list;
				list.Clear();
				list.AddRange( matrix[x,z].list );
			}
		}