depthboundstest11/src/DepthBoundsTest11.cpp
static void CalcSphereBounds(const XMFLOAT3 center, float r, const float zoom[2], 
                             float minb[2], float maxb[2])
{
    // By default, assume that the full screen is covered
    minb[0] = minb[1] = -1.0f;
    maxb[0] = maxb[1] =  1.0f;

    // Once for x, once for y
    for (int i=0; i<2; i++)
    {
		float x;
		if (i == 0)
			x = center.x;
		else
			x = center.y;

        float z = center.z;
        float ds = x*x + z*z;
        float l = ds - r * r;

        if (l > 0.0f)
        {
            float s,c;
            l = sqrt(l);

            s = x * l - z * r;  // ds*sin(alpha)
            c = x * r + z * l;  // ds*cos(alpha)
            if (z*ds > -r*s)    // left/top intersection has positive z
                minb[i] = MAX(-1.0f, s*zoom[i]/c);

            s = z * r + x * l;  // ds*sin(beta)
            c = z * l - x * r;  // ds*cos(beta)
            if (z*ds > r*s)     // right/bottom intersection has positive z
                maxb[i] = MIN(1.0f, s*zoom[i]/c);
        }
    }
}
//--------------------------------------------------------------------------------------
// Calculates bounding rectangle in normalized device coordinates for
// the view-space sphere with center "center" and radius "r". "zoom"
// contains the first two diagonal entries of your projection matrix
// (which is assumed to be perspective). You should do a rough rejection
// test of the sphere against the frustum first.
// Taken from: http://blog.gmane.org/gmane.games.devel.algorithms/month=20100101
//--------------------------------------------------------------------------------------

Calculates bounding rectangle in normalized device coordinates for
the view-space sphere with center "center" and radius "r". "zoom"
contains the first two diagonal entries of your projection matrix
(which is assumed to be perspective). You should do a rough rejection
test of the sphere against the frustum first.
Calculates bounding rectangle in normalized device coordinates for the view - space sphere with center " center " and radius " r " . " zoom " contains the first two diagonal entries of your projection matrix ( which is assumed to be perspective ) . You should do a rough rejection test of the sphere against the frustum first .
static void CalcSphereBounds(const XMFLOAT3 center, float r, const float zoom[2], 
                             float minb[2], float maxb[2])
{
    minb[0] = minb[1] = -1.0f;
    maxb[0] = maxb[1] =  1.0f;
    for (int i=0; i<2; i++)
    {
		float x;
		if (i == 0)
			x = center.x;
		else
			x = center.y;
        float z = center.z;
        float ds = x*x + z*z;
        float l = ds - r * r;
        if (l > 0.0f)
        {
            float s,c;
            l = sqrt(l);
            s = x * l - z * r;  
            c = x * r + z * l;  
            if (z*ds > -r*s)    
                minb[i] = MAX(-1.0f, s*zoom[i]/c);
            s = z * r + x * l;  
            c = z * l - x * r;  
            if (z*ds > r*s)     
                maxb[i] = MIN(1.0f, s*zoom[i]/c);
        }
    }
}
static void CalcSphereBounds ( const XMFLOAT3 center , float r , const float zoom [ 2 ] , float minb [ 2 ] , float maxb [ 2 ] ) { minb [ 0 ] = minb [ 1 ] = -1.0f ; maxb [ 0 ] = maxb [ 1 ] = 1.0f ; for ( int i = 0 ; i < 2 ; i ++ ) { float x ; if ( i == 0 ) x = center . x ; else x = center . y ; float z = center . z ; float ds = x * x + z * z ; float l = ds - r * r ; if ( l > 0.0f ) { float s , c ; l = sqrt ( l ) ; s = x * l - z * r ; c = x * r + z * l ; if ( z * ds > - r * s ) minb [ i ] = MAX ( -1.0f , s * zoom [ i ] / c ) ; s = z * r + x * l ; c = z * l - x * r ; if ( z * ds > r * s ) maxb [ i ] = MIN ( 1.0f , s * zoom [ i ] / c ) ; } } }
Calculates bounding rectangle in normalized device coordinates for
the view-space sphere with center "center" and radius "r".
Calculates bounding rectangle in normalized device coordinates for the view - space sphere with center " center " and radius " r " .
// By default, assume that the full screen is covered
 // Once for x, once for y
 // ds*sin(alpha)
 // ds*cos(alpha)
 // left/top intersection has positive z
 // ds*sin(beta)
 // ds*cos(beta)
 // right/bottom intersection has positive z
