View Full Version : How to obtain intersection with a plane
07-24-2007, 06:34 AM
is it possible to obtain the intersection of a generic 3d object with a given plane, maybe as a raster image ?
thanks a lot,
07-24-2007, 07:39 AM
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.
07-24-2007, 11:12 AM
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.
07-25-2007, 01:04 AM
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...
07-25-2007, 04:54 AM
I think it should be glDepthMask...
07-25-2007, 06:19 AM
I think it should be glDepthMaskIt 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.
07-27-2007, 08:12 AM
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
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.