Adapted from this page, which was linked in Eric Lengyel's paper. Given a view matrix, projection matrix, and a point and a normal for the desired plane, it produces the right projection matrix.
rplane plane;
D3DXPlaneFromPointNormal(&plane, &p, &normal);
D3DXMATRIX matClipProj, WorldToProjection;
WorldToProjection = matView * matProjection;
D3DXMatrixInverse(&WorldToProjection, NULL, &WorldToProjection);
D3DXMatrixTranspose(&WorldToProjection, &WorldToProjection);
D3DXVECTOR4 clipPlane(plane.a, plane.b, plane.c, plane.d);
D3DXVECTOR4 projClipPlane;
// transform clip plane into projection space
D3DXVec4Transform(&projClipPlane, &clipPlane, &WorldToProjection);
D3DXMatrixIdentity(&matClipProj);
if (projClipPlane.w == 0) // or less than a really small value
{
// plane is perpendicular to the near plane
return;
}
if (projClipPlane.w > 0)
{
// flip plane to point away from eye
D3DXVECTOR4 clipPlane(-plane.a, -plane.b, -plane.c, -plane.d);
// transform clip plane into projection space
D3DXVec4Transform(&projClipPlane, &clipPlane, &WorldToProjection);
}
// put projection space clip plane in Z column
matClipProj(0, 2) = projClipPlane.x;
matClipProj(1, 2) = projClipPlane.y;
matClipProj(2, 2) = projClipPlane.z;
matClipProj(3, 2) = projClipPlane.w;
// multiply into projection matrix
D3DXMATRIX projClipMatrix = matProjection * matClipProj;
matProjection = projClipMatrix;