PDA

View Full Version : drawing outline of clipped shape



fox
03-28-2001, 03:51 AM
Hi

say I have a cube, which I clip as it intersects the floor - how could I draw the outline of the 2d shape of the cube as it intersects the floor? - i'm not quite sure how you would do this if the cube was rotated 45 degrees say

cheers

billy
03-28-2001, 04:26 AM
The only way I can think of to do this is to calculate the intersection between 3D planes which represent the floor and faces of the cube.
However, there might be a more efficient way to do this, that I don't know of.

coredump
03-28-2001, 04:28 AM
one way would be to find all the edges(12) that intersect with your floor(simple line-plane intersection). now you can draw a polygon using these intersection points.

b

maxuser
03-28-2001, 07:05 PM
Hmmm...I'm guessing this approach will have nasty artifacts, but it's worth a shot. Render the floor as usual (with the z-buffer enabled), then render the cube with the depth test set to GL_EQUAL, i.e. glDepthFunc(GL_EQUAL). (Remember to change the depth test back to GL_LESS when you're done rendering the cube.) When rendering the cube, only the pixels where the cube's depth matches the floor's depth (i.e. their intersection) will be modified. I imagine that this will produce a flickering, disconnected outline (if at all visible) because of the quantized rasterization process. (It would work perfectly at infinite resolutions, but I'm sure that's not much consolation.) So try it out, and in the meantime I'll try to think of a better approach.

maxuser
03-28-2001, 07:06 PM
Hmmm...I'm guessing this approach will have nasty artifacts, but it's worth a shot. Render the floor as usual (with the z-buffer enabled), then render the cube with the depth test set to GL_EQUAL, i.e. glDepthFunc(GL_EQUAL). (Remember to change the depth test back to GL_LESS when you're done rendering the cube.) When rendering the cube, only the pixels where the cube's depth matches the floor's depth (i.e. their intersection) will be modified. I imagine that this will produce a flickering, disconnected outline (if at all visible) because of the quantized rasterization process. (It would work perfectly at infinite resolutions, but I'm sure that's not much consolation.) So try it out, and in the meantime I'll try to think of a better approach.

JasonM [ATI]
03-28-2001, 08:15 PM
Sounds somewhat similar to object capping (http://www.ati.com/na/pages/resource_centre/dev_rel/sdk/rage128sdk/OpenGL/Samples/Rage128StencilCap.html) using a stencil buffer and a user clip plane. In your case, the clip plane would be co-planar with the floor. Note that this capping works with more complex shapes than just boxes.

-Jason


[This message has been edited by JasonM [ATI] (edited 03-28-2001).]

fox
03-29-2001, 01:48 AM
object capping seems like an interesting thing to do - I can already get the object object to be clipped when it intersects the floor but drawing the outline of where it intersects the floor is more diificult I guess I'll have to use the stencil buffer and have it drawing the line or polygon of the area that is cliiped - any other suggestion - or simpler ways of going about doing this?

cheers


[This message has been edited by fox (edited 03-29-2001).]

harsman
03-29-2001, 02:36 AM
Couldn't you just store any new edges you introduce when clipping and then draw those? Or are you using a user clip plane?

fox
03-29-2001, 03:29 AM
Originally posted by harsman:
Couldn't you just store any new edges you introduce when clipping and then draw those? Or are you using a user clip plane?

Yes - it is the sides of the shapes which are basically planes that are being clipped -I do this just by turning depth-testing off.

Tone
03-29-2001, 11:52 AM
I agree that the stencil buffer is the way to go. Use glStencilOp(GL_KEEP, GL_INVERT, GL_INVERT) while drawing the object. Then draw whatever you want the intersection to look like where the stencil bit equals one. Hope this helps

Tone