PDA

View Full Version : Intersect a cube with a cylinder



zappian
01-13-2015, 06:15 AM
Hi guys .

I want to produce something like this in open GL.

1586

Basicly doing the intersection of a cylinder and a cube/paralelipip.

I cant find any info how to do this online with open GL , what is the command to do it?

Agent D
01-13-2015, 08:53 AM
It sounds like you want to implement CSG (https://en.wikipedia.org/wiki/Constructive_solid_geometry) operations.

OpenGL(R) on it's own doesn't have any explicit support for that kind of thing. OpenGL(R) works with triangle meshes, not volumes.
(in other words: there is no command for this, this is way too high level)

You can of course use your favourite CSG model editing program, export to some triangle mesh format, load it in your GL program and render it.

AFAIK there's also a way of implementing CSG operations using the stencil buffer (well, union simply means rendering both, it gets more interesting
for intersections or subtraction).

There is a C++ library for doing that (http://www.opencsg.org/) and if you type OpenGL(R) and CSG into Google, you will a bunch of stackoverflow
posts, as well as posts on this forum and some explanations on how the stencil technique I mentioned works.
And some papers:
first (http://www.nigels.com/research/wscg2000.pdf)
second (http://www.13thmonkey.org/documentation/CAD/Linear-time-CSG-rendering-wscg2002.pdf)

Carmine
01-13-2015, 02:55 PM
there's also a way of implementing CSG operations using the stencil buffer ....

I've played with this stencil buffer stuff. Downloaded some code, put it on my windows desktop, and it worked! The code isn't that complicated but I don't really know why it works. I played with it quite a bit - commenting out things, changing order of commands. I even successfully integrated into a baseball simulation I wrote. Still don't know how it works.

The OP might want to know that the stencil buffer approach is a visual effect only. It does not actually do a boolean operation which results in a new mesh.