Axiom.Core.Frustum.ProjectSphere C# (CSharp) Method

ProjectSphere() public method

public ProjectSphere ( Sphere sphere, float &left, float &top, float &right, float &bottom ) : bool
sphere Axiom.Math.Sphere
left float
top float
right float
bottom float
return bool
		public virtual bool ProjectSphere( Sphere sphere, out float left, out float top, out float right, out float bottom )
		{
			// initialise
			left = bottom = -1.0f;
			right = top = 1.0f;

			// Transform light position into camera space
			Vector3 eyeSpacePos = this.ViewMatrix.TransformAffine( sphere.Center );

			if ( eyeSpacePos.z < 0 )
			{
				float r = sphere.Radius;
				// early-exit
				if ( eyeSpacePos.LengthSquared <= r * r )
					return false;

				Vector3 screenSpacePos = this.ProjectionMatrix * eyeSpacePos;

				// perspective attenuate
				Vector3 spheresize = new Vector3( r, r, eyeSpacePos.z );
				spheresize = this.ProjectionMatrixRSDepth * spheresize;

				float possLeft = screenSpacePos.x - spheresize.x;
				float possRight = screenSpacePos.x + spheresize.x;
				float possTop = screenSpacePos.y + spheresize.y;
				float possBottom = screenSpacePos.y - spheresize.y;

				left = Utility.Max( -1.0f, possLeft );
				right = Utility.Min( 1.0f, possRight );
				top = Utility.Min( 1.0f, possTop );
				bottom = Utility.Max( -1.0f, possBottom );
			}

			return ( left != -1.0f ) || ( top != 1.0f ) || ( right != 1.0f ) || ( bottom != -1.0f );
		}