Thread: drawing outline of clipped shape

1. drawing outline of clipped shape

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

2. Re: drawing outline of clipped shape

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.

3. Re: drawing outline of clipped shape

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

4. Re: drawing outline of clipped shape

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.

5. Re: drawing outline of clipped shape

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.

6. Re: drawing outline of clipped shape

Sounds somewhat similar to object capping 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).]

7. Re: drawing outline of clipped shape

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).]

8. Re: drawing outline of clipped shape

Couldn't you just store any new edges you introduce when clipping and then draw those? Or are you using a user clip plane?

9. Re: drawing outline of clipped shape

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.

10. Re: drawing outline of clipped shape

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

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•