Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: is it possible to calculate which vertices of a model are inside another model?

  1. #1
    Newbie Newbie
    Join Date
    Dec 2015

    is it possible to calculate which vertices of a model are inside another model?

    Hi All,

    I have two identical models, which move independently, I would like to alter one models colour for the vertices which are inside the bounds of the other model, I have the means to modify the colour of each vertex independently, so my issue is in checking where a vertex is in relation to the other model.

    Is this even possible? can anyone point me anywhere to look?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    If a line segment between a point known to be outside a closed surface to some other point P intersects the surface an odd number of times, then P is inside the surface, otherwise it is outside.

    Performing such a test is potentially quite slow if the surface consists of many polygons. One way to speed it up using OpenGL is to use stencil tests. Render the points with depth writes enabled. Clear the stencil buffer. Render the surface with depth tests enabled, depth writes disabled, stencil tests disabled, stencil writes enabled, and glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT). Read the stencil buffer pixels corresponding to the points; if the value has been inverted, the point is inside the surface.

    Note that the rendered surface must fit within the viewport and depth range, and if you're testing multiple points, they must map to distinct pixels.

  3. #3
    Newbie Newbie
    Join Date
    Dec 2015
    Cheers GClements,

    I shall definitely look into the stencil testing option, it's not something I'm familiar with so will have to do some reading.


Posting Permissions

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