subtracting objects

Hallo,

Does anybody knows how I can subtract one object from another?
Like making a hole in a cube.

Thanks

Subtracting objects is rather difficult, but there’s nice trick with stencil buffer that lets you do it at speed linearly dependent from complexity of your objects (real cutting objects can take up to n^2 in worst case so forget about any realtime).
You should find it somewhere in demo section on this nice page http://www.delphi3d.net/

[This message has been edited by MickeyMouse (edited 02-18-2003).]

It depends what you mean. Given a mesh representing a cube and a mesh representing a sphere, you could calculate the resulting mesh. Alternatively, you might be able to use a rendering trick (such as the stencil buffer) to leave the meshes unaffected but render them as though one had been subtracted from the other.

Unfortunatly, i don’t really know how either method is done…

There is an example of the stencil buffer method here called “Composite solid geometry using the stencil buffer.”
http://www.opengl.org/developers/code/glut_examples/advanced/advanced.html

I think you don´t want to do this in realtime, but once in an editor-like program, don´t you?
Well than you should search for CSG (Constructive Solid Geometry). This is an operation which is performed on BSP-Trees (Binary Space Partitioning Trees).
So you should first check out some tutorials on BSP-Trees and implement them. If you are new to them, it will take some days to get familiar to them.
When you have understood and implemented BSP-Trees you can check out the CSG algorithm. It isn´t really hard, but it is a bit of work.

BSP-Demo at: http://nate.scuzzy.net/
Infos on CSG: http://www.cfxweb.net/~aggrav8d/tutorials/csg.html
and http://www.delphi3d.net/articles.php

On BSP-Trees you will find lots of tutorials with google. Finding information about CSG is a bit harder.

Hope that helps you.
Jan.