PDA

View Full Version : is it possible to calculate which vertices of a model are inside another model?



Sly_Raccoon
03-29-2016, 09:03 AM
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?

GClements
03-29-2016, 11:26 AM
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.

Sly_Raccoon
03-31-2016, 07:18 AM
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.

Regards,
SR