Platform SDK: DirectX |
The IDirect3DDevice7::ComputeSphereVisibility method calculates the visibility (complete, partial, or no visibility) of an array of spheres within the current viewport for this device.
HRESULT ComputeSphereVisibility( LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres, DWORD dwFlags, LPDWORD lpdwReturnValues );
Basic Clipping Flags
Combination and General Flags
Clip Intersection Flags
Clip Union Flags
If the method succeeds, the return value is D3D_OK.
If the method fails, the return value can be one of the following values:
D3DERR_INVALIDMATRIX |
DDERR_INVALIDOBJECT |
DDERR_INVALIDPARAMS |
Sphere visibility is computed by back-transforming the viewing frustum to the model space, using the inverse of the combined world, view, or projection matrices. If the combined matrix cannot be inverted (if the determinant is 0), the method fails, returning D3DERR_INVALIDMATRIX.
The following code fragment in C illustrates how you could use ComputeSphereVisibility.
D3DVECTOR center = {0,0,0}; D3DVALUE radius = 1; DWORD result = 0; res = m_pd3dDevice->ComputeSphereVisibility(¢er, &radius, 1, 0, &result); if (res == D3D_OK) { if (result & D3DSTATUS_CLIPINTERSECTIONALL) { // Sphere is outside if (result & D3DSTATUS_CLIPINTERSECTIONLEFT) printf("Sphere left outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONRIGHT) printf("Sphere right outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONTOP) printf("Sphere top outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONBOTTOM) printf("Sphere bottom outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONFRONT) printf("Sphere front outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONBACK) printf("Sphere back outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONGEN0) printf("Sphere gen0 outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONGEN1) printf("Sphere gen1 outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONGEN2) printf("Sphere gen2 outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONGEN3) printf("Sphere gen3 outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONGEN4) printf("Sphere gen4 outside\n"); if (result & D3DSTATUS_CLIPINTERSECTIONGEN5) printf("Sphere gen5 outside\n"); } else if (result & D3DSTATUS_CLIPUNIONALL) { // Sphere intersects the frustum if (result & D3DSTATUS_CLIPUNIONLEFT) printf("Sphere left intersect\n"); if (result & D3DSTATUS_CLIPUNIONRIGHT) printf("Sphere right intersect\n"); if (result & D3DSTATUS_CLIPUNIONTOP) printf("Sphere top intersect\n"); if (result & D3DSTATUS_CLIPUNIONBOTTOM) printf("Sphere bottom intersect\n"); if (result & D3DSTATUS_CLIPUNIONFRONT) printf("Sphere front intersect\n"); if (result & D3DSTATUS_CLIPUNIONBACK) printf("Sphere back intersect\n"); if (result & D3DSTATUS_CLIPUNIONGEN0) printf("Sphere gen0 intersect\n"); if (result & D3DSTATUS_CLIPUNIONGEN1) printf("Sphere gen1 intersect\n"); if (result & D3DSTATUS_CLIPUNIONGEN2) printf("Sphere gen2 intersect\n"); if (result & D3DSTATUS_CLIPUNIONGEN3) printf("Sphere gen3 intersect\n"); if (result & D3DSTATUS_CLIPUNIONGEN4) printf("Sphere gen4 intersect\n"); if (result & D3DSTATUS_CLIPUNIONGEN5) printf("Sphere gen5 intersect\n"); } else { printf("Sphere is inside\n"); } } else printf("Invalid return value\n");
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
Version: Requires DirectX 7.0.
Header: Declared in d3d.h.