Skip to main content
gamedev.net
🔒 Locked

Union, intersection & difference

Started by Cacks Oct 12, 2005 at 5:49 AM 9 replies 3.3k views
Original Post
Cacks
Cacks
Hi guys, Im wondering if I draw 2 objects over one another, how can I get the Union, intersection & difference of these 2 objects? I'm thinking for intersection If there is anyway of drawing the overlapping region that is supposed to be clipped? Union? Maybe just draw one object over another? Difference? I'm not sure, any ideas? Eg would like to have a hole in my objects. Thanks!!
Reject the basic asumption of civialisation especially the importance of material possessions
Fruny
Fruny
You can play with the stencil buffer. If rendering A-B, render the B object to the stencil buffer and then the A object normally, setting things so that the stencil test fails where the B object was drawn. For A&unionB, render only where B was drawn.

Of course, this obviously only work in 2D. If you want to do Constructive Solid Geometry in 3D, you have to explicitely compute the intersection or difference, generating new triangles.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Cacks
Cacks
I was dreading that was the case. Don't suppose you know of any tutorials, or books?

Thanks for the reply!
Reject the basic asumption of civialisation especially the importance of material possessions
joanusdmentia
joanusdmentia
Actually, you can get 3D CSG working using the stencil and depth buffer. Have a read about it here. Of course this is only for *rendering*, you won't get a mesh you could use for collision detection out of it.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
Cacks
Cacks
Thanks for the link!

I was reading last night about tessellaion. I read I can make polygons with holes? Does any 1 know if this is the case? And could I make a cube with a hole in it usign this?
Reject the basic asumption of civialisation especially the importance of material possessions
James Trotter
James Trotter
Quote:
Original post by Cacks
Thanks for the link!

I was reading last night about tessellaion. I read I can make polygons with holes? Does any 1 know if this is the case? And could I make a cube with a hole in it usign this?


I'm not quite sure what you mean. Tessellation can be used to subdivide nonconvex polygons so that they can easily be rendered. GLU provides routines for polygon tessellation. Have a look at the specification, or this tutorial.

Though, I don't think this is what you really want. You should look up constructive solid geometry, as suggested already.
Cacks
Cacks
If I could draw a cuboid using polygons(faces) with holes, I could draw an open cuboid within it and look at the sides of this open cuboid through the holes in those polygons?

Does that sound completely wrong?
Reject the basic asumption of civialisation especially the importance of material possessions
James Trotter
James Trotter
Quote:
Original post by Cacks
If I could draw a cuboid using polygons(faces) with holes, I could draw an open cuboid within it and look at the sides of this open cuboid through the holes in those polygons?

Does that sound completely wrong?


Sure, but instead of actually having "polygons with holes", wouldn't it be more sensible to have "polygons around a hole"?
Have a look at this, it might be what you need.
haegarr
haegarr
As of my knowledge, none of the hardware renderers supports other faces than triangles directly. Even quads are at least internally divided up in tris. So I agree w/ James to "render polygons around holes".

However, if you have written a software renderer, than you may support holes directly, but I think most solutions out there will even divide up the polygon in such case. My modeler does support n-gons and holes, and I've chosen the way of tesselation into tris to render w/ OpenGL.
timw
timw
if you want a hole in a quad, why not just use a transparency modulating texture map? much faster. This is why I love raytracing, CSG is so straightforward.

tim
haegarr
haegarr
A hole in a quad by transparency will work, of course. But for a hole in a cube (as was also requested) it will not work good since those hole has to have more than 2 dimensions to look correct. So I think "geometric" holes are the better choice.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.