Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: How to obtain intersection with a plane

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2007
    Location
    Bergamo, Italy
    Posts
    3

    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

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,119

    Re: How to obtain intersection with a plane

    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.

  3. #3
    Intern Contributor
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    84

    Re: How to obtain intersection with a plane

    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
    Ido Ilan

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2007
    Location
    Bergamo, Italy
    Posts
    3

    Re: How to obtain intersection with a plane

    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

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,142

    Re: How to obtain intersection with a plane

    I think it should be glDepthMask...

  6. #6
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,119

    Re: How to obtain intersection with a plane

    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.

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2007
    Location
    Bergamo, Italy
    Posts
    3

    Re: How to obtain intersection with a 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •