How to obtain intersection with a plane

Hi all…

is it possible to obtain the intersection of a generic 3d object with a given plane, maybe as a raster image ?

thanks a lot,

Paolo

Of course it is possible.

Do the following steps:

  1. Clear stencil buffer
  2. Place clip plane where you want to clip your object
  3. use glDepthTest(GL_FALSE), glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE), glStencilFunc(GL_ALWAYS)
  4. Set stencil operations to GL_INCR, glCullFace(GL_BACK)
  5. draw your object
  6. Set stencil operations to GL_DECR, glCullFace(GL_FRONT)
  7. draw your object

Now you have stencill filled with the original value everywhere except the area on you clip plane where intersection is.
If you want to see that area you can draw full scene quad using stencil test.

This solution works in 2D and 3D.

Hi,

k_szczech is correct if you want to do it using rendering algorithm.
I’ve implemented this using simple plane to aabb tree intersection and got less that 1ms for hundreds thousands of polygons.

Ido

Hi k_szczech, hi Ido

first of all, thank a lot for your helps… I’m trying to do what you tell me but now I’m in trouble with glDepthTest() function… I’m working with QT4.3 and it seems that this functions are not available… probably is just a missing include problem…

thanks again,

 Paolo

I think it should be glDepthMask…

I think it should be glDepthMask
It should be glDisable(GL_DEPTH_TEST).
Apparently my mind were somewhere else when I wrote that. I’m just a bit overworked recently…

You just don’t need depth test for that. In similar algorithms - like stencil shadows you need depth test because shadow volumes are clipped by level’s geometry. In this case your object is clipped by a single plane.

Hi k_szczech

I’m still in trouble… glClipPlane works fine now, but I have 2 more doubt:

1: what about 2nd and 3rd parms of glStencilFunc and glStencilOp ?
3: how can I copy the stencil buffer back to the visible buffer ?

I’m sorry but I’me really new to opengl…

thanks a lot

Paolo