Axiom.Core.StaticGeometry.GetRegionIndexes C# (CSharp) Method

GetRegionIndexes() protected method

protected GetRegionIndexes ( Vector3 point, ushort &x, ushort &y, ushort &z ) : void
point Vector3
x ushort
y ushort
z ushort
return void
		protected void GetRegionIndexes( Vector3 point, out ushort x, out ushort y, out ushort z )
		{
			// Scale the point into multiples of region and adjust for origin
			Vector3 scaledPoint = ( point - origin ) / regionDimensions;

			// Round down to 'bottom left' point which represents the cell index
			int ix = (int)System.Math.Floor( scaledPoint.x );
			int iy = (int)System.Math.Floor( scaledPoint.y );
			int iz = (int)System.Math.Floor( scaledPoint.z );

			// Check bounds
			if ( ix < regionMinIndex || ix > regionMaxIndex
				|| iy < regionMinIndex || iy > regionMaxIndex
				|| iz < regionMinIndex || iz > regionMaxIndex )
			{
				throw new Exception( "Point out of bounds in StaticGeometry.GetRegionIndexes" );
			}
			// Adjust for the fact that we use unsigned values for simplicity
			// (requires less faffing about for negatives give 10-bit packing
			x = (ushort)( ix + regionHalfRange );
			y = (ushort)( iy + regionHalfRange );
			z = (ushort)( iz + regionHalfRange );
		}