Hi all,
I’m building a slicing/repair program for a 3d printer.
I’m looking for a smart way to use a clipping plane for a 3d scene; but instead of cutting the top part of the 3d model; i would like to cut the bottom part.
So you could look from below towards the model; and then see the cross section and all parts that are not cut but above the clippingplane.
I think one way would be to display the whole scene inverted along the z-axis in the negative z-space and then clip it; but this wouldn’t be very intuitive for the user. (since everything would be upside down).
GL.ClipPlane takes an equation of an infinite plane; but this doesn’t seem to have a normal; it’s just ax+by+cz+d=0; a,b,c,d being the parameters.
Anybody an idea?
After some reading in the 1997 programming guide; i found a clean solution.
In case anyone interested:
glClipPlane works against the Modelview Matrix specified at the time of calling. It satisfies a certain condition (A B C D)M_-1 ( xe ye ze we ) _T >= 0 which determines what part it cuts away.
This gave me the idea of just multiplying the current model view matrix with a negative unity matrix. Hence flip it.
Worked perfectly.
Here the code (in C# OpenTK)
double[] planeEq = { 0, 0, -1, clippingheight }; // ax + by + cz + d = 0
GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.MultMatrix(new double[] { -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1 }); //multiply with negative unity to flip it and thus the equation for comparison.
GL.ClipPlane(ClipPlaneName.ClipPlane0, planeEq); //set the clipplane
GL.PopMatrix(); //pop the matrix again
GL.Enable(EnableCap.ClipPlane0);
[QUOTE=karatire;1280799]
GL.ClipPlane takes an equation of an infinite plane; but this doesn’t seem to have a normal; it’s just ax+by+cz+d=0; a,b,c,d being the parameters.[/QUOTE]
The normal is the vector (a,b,c). If (a,b,c) is a unit vector, -d is the distance of the origin from the plane. It may be more clear to re-arrange it as ax+by+c*z>=-d, i.e. dot([a,b,c],[x,y,z])>=-d.
Note that specifying (-a,-b,-c,-d) uses exactly the same plane, but clips the other side. The condition -ax-by-cz-d>=0 is exactly equivalent to ax+by+cz+d<=0.