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?

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.

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.