Volume Intersection Problem

I would like to be able to show which parts of a polygonal model lie within an ellipsoidal volume. I’m hoping this can be done with a multi-pass rendering involving stencil operations. Can anyone point me to a tutorial similar to what I’m trying to do? Reading the documentation on stencil planes and stencil operations is not good enough (for me). I need to see code or pseudo-code that does something similar to the problem I’m trying to solve. Thanks.


In the case you don’t want to link again a third party library, see this source code.The functions that may interest you in the file are firstInsideSecond,fixDepth,and.

Thanks for posting that code. It is better for me than using a library of canned routines because I may actually learn how to use stencil operations to accomplish my goal. I’ll play with the code this weekend to see if I can figure out how to accomplish my objective.

I have brought that sample code onto my home PC, compiled, and run it successfully. It’s an excellent demo. Next I have to try and figure out how it works :slight_smile:

Draw a closed ellipsoid, toggling a stencil bit for each fragment that is in front of the z-buffer.
The stencil bits that are one have an odd number of ellipsoid surfaces in front of it, and therefore are inside the ellipsoid volume.

See also: