Platform SDK: DirectX

Setting and Retrieving Clip Planes

[C++]

You set and retrieve user-defined clip planes by calling the IDirect3DDevice7::SetClipPlane and IDirect3DDevice7::GetClipPlane methods. The coefficients that describe the plane are in a four-element array of type D3DVALUE.

The SetClipPlane method accepts two parameters. The first parameter is the zero-based index of the clip plane being set, and the second parameter is the address of a buffer that contains the coefficients for the general plane equation.

Note  The coefficients passed to SetClipPlane take the form of the general plane equation. If the values in the array you pass with the method were labeled A, B, C, and D (in the order they appear in memory), they would fit into the general plane equation so that Ax + By + Cz + D = 0. A point with world-space coordinates (x, y, z) is visible in the half space of the plane if Ax + By + Cz + D >= 0. Points that exist on or behind the clipping plane are clipped from the scene.

The following code shows how this method is called in C++.

// For this example, the pd3dDevice variable is a valid
// pointer to an IDirect3DDevice7 interface.

    // Set-up a clipping plane such that vertices with
    // x<=0 will be clipped.
    D3DVALUE clip[4];
    ZeroMemory( (LPVOID)clip, sizeof(clip) );

    clip[0] = 1.0f; 
    pd3dDevice->SetClipPlane( 0, clip );

Setting coefficients for a clip plane does not enable clipping with that plane. For more information, see Enabling and Disabling Clip Planes.

You can define up to 32 (D3DMAXUSERCLIPPLANES) clip planes. Therefore, the highest index you can pass to the SetClipPlane method is 31. If you pass an invalid value, the method will fail, returning DDERR_INVALIDPARAMS.

The IDirect3DDevice7::GetClipPlane method is semantically similar to its counterpart. The following C++ code retrieves the coefficients currently set for the clip plane at index 2.

// For this example, the pd3dDevice variable is a valid
// pointer to an IDirect3DDevice7 interface.

    D3DVALUE clip[4];
    pd3dDevice->GetClipPlane( 2, clip );
[Visual Basic]

You set and retrieve user-defined clip planes by calling the Direct3DDevice7.SetClipPlane and Direct3DDevice7.GetClipPlane methods. The coefficients that describe the plane are in a four-element array of type D3DVALUE.

The first parameter to SetClipPlane is the zero-based index of the clip plane being set, and the remaining parameters contain the coefficients for the general plane equation.

Note  The coefficients passed to SetClipPlane take the form of the general plane equation. If the values in the array you pass with the method were labeled A, B, C, and D (in the order they appear in memory), they would fit into the general plane equation so that Ax + By + Cz + D = 0. A point with world-space coordinates (x, y, z) is visible in the half space of the plane if Ax + By + Cz + D >= 0. Points that exist on or behind the clipping plane are clipped from the scene.

The following code shows how this method is called in Visual Basic.

' For this example, the d3dDevice variable is a valid
' reference to an Direct3DDevice object.

    ' Set-up a clipping plane such that vertices with
    ' x<=0 will be clipped.
    Dim A As Single, B As Single, _
        C As Single, D As Single
           
    A = 1#
    
    Call d3dDevice.SetClipPlane(0, A, B, C, D)

Setting coefficients for a clip plane does not enable clipping with that plane. For more information, see Enabling and Disabling Clip Planes.

You can define up to 32 (D3DMAXUSERCLIPPLANES) clip planes. Therefore, the highest index you can pass to the SetClipPlane method is 31. If you pass an invalid value, the method will fail, returning DDERR_INVALIDPARAMS.

The Direct3DDevice7.GetClipPlane method is semantically similar to its counterpart. The following Visual Basic code retrieves the coefficients currently set for the clip plane at index 2.

' For this example, the d3dDevice variable is a valid
' reference to an Direct3DDevice object.

    Dim A As Single, B As Single, _
        C As Single, D As Single
    
    Call d3dDevice.GetClipPlane(2, A, B, C, D)