I am trying to create clipping planes to define sections at different points of my objects in a opentk glControl , for that I define a variable "elevActual" that indicates the distance that the clipping plane will be created. By clicking a button I advance my clipping plane. The problem is that as the clipping plane advances, the objects that are behind the clipping plane are still displayed and I only want the section defined at the "elevActual" distance to be displayed.
double[] Elevyz = new double[] { -1, 0, 0, ElevActual };
// Definir planos de recorte YZ
if (tipVista == 2)// this indicate is in YZ plans
{
GL.PushMatrix();
GL.ClipPlane(ClipPlaneName.ClipPlane2, Elevyz);
GL.Enable(EnableCap.ClipPlane2);
}
...
GL.Disable(EnableCap.ClipDistance2);
GL.PopMatrix();// Cierre de la funcion de plano de corte
If you only want to view a section of the geometry, you must define two clipping planes. One at the beginning of the section and one at the end of the section. In the following start
and to
defines the range of the section. start
must be smaller than end
:
double[] Elevyz_start = new double[] { 1, 0, 0, -start };
double[] Elevyz_end = new double[] { -1, 0, 0, end };
GL.ClipPlane(ClipPlaneName.ClipPlane2, Elevyz_end);
GL.Enable(EnableCap.ClipPlane2);
GL.ClipPlane(ClipPlaneName.ClipPlane5, Elevyz_start);
GL.Enable(EnableCap.ClipPlane5);
The maximum number of clipping planes is guaranteed to be at least 6. See GL_MAX_CLIP_PLANES
respectively glClipPlane
.
The parameters to the clipping plane are interpreted as a Plane Equation.
The first 3 components of the plane equation are the normal vector to the clipping plane. The 4th component is the distance to the origin. Hence the sign of the distance depends on the direction on the normal vector. Therefore, start
is inverted when setting up the plane equation.