Axiom.Core.BillboardSet.SetTextureStacksAndSlices C# (CSharp) Method

SetTextureStacksAndSlices() protected method

protected SetTextureStacksAndSlices ( int stacks, int slices ) : void
stacks int
slices int
return void
		protected void SetTextureStacksAndSlices( int stacks, int slices )
		{
			if ( stacks == 0 )
			{
				stacks = 1;
			}
			if ( slices == 0 )
			{
				slices = 1;
			}
			//  clear out any previous allocation
			this.textureCoords.Clear();
			//  make room
			this.textureCoords.Capacity = stacks * slices;
			while ( this.textureCoords.Count < stacks * slices )
			{
				this.textureCoords.Add( new RectangleF() );
			}
			ushort coordIndex = 0;
			//  spread the U and V coordinates across the rects
			for ( uint v = 0; v < stacks; ++v )
			{
				//  (float)X / X is guaranteed to be == 1.0f for X up to 8 million, so
				//  our range of 1..256 is quite enough to guarantee perfect coverage.
				float top = (float)v / (float)stacks;
				float bottom = ( (float)v + 1 ) / (float)stacks;
				for ( uint u = 0; u < slices; ++u )
				{
					RectangleF r = new RectangleF();
					r.Left = (float)u / (float)slices;
					r.Top = top;
					r.Width = ( (float)u + 1 ) / (float)slices - r.Left;
					r.Height = bottom - top;
					this.textureCoords[ coordIndex ] = r;
					++coordIndex;
				}
			}
			Debug.Assert( coordIndex == stacks * slices );
		}