Sign in to follow this  

3D Clipping

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I have been reading gamedev.net for some time now (and gained valuable insights, thanks) and finally decided to take a more active stance and start participating on the forums. So, I have a question to ask: I have an old P166 machine with win98 and no hardware acceleration at my disposal where I work, and decided to write a DOS-based software scanline renderer for fun. I implemented a 3D frustum clipper using an algorithm I came up with after some thinking. It works nicely but I wonder if it could be sped up somehow by modifying it or using a different algo altogether. The algorithm is currently as follows (in pseudo):
clip3d(list<vertex> &L)
{
 for(each frustum plane P)
 {
  for(each consecutive pair of vertices V,W in L)
  {
   if(edge V,W intersects P)
    calculate new vertex and insert into L between V and W
  }
  for(each vertex V in L)
  {
   if(V outside P)
    erase V
  }
 }
}
It is quite nice in that it handles arbitrary n-gons, but I don't strictly need that feature. Triangles are enough for my purposes. The intersection calculation itself is quite optimized (using the knowledge that frustum planes are of form x=±z,y=±z etc) but if you know any handy tricks that I might not be aware of, I'd like to hear :) BTW, the clipper may obviously spit out n-gons with n>3. Currently I render them as a triangle fan, but should I implement a generic convex poly rasterizer instead? [Edited by - Sharlin on October 8, 2004 2:19:26 PM]

Share this post


Link to post
Share on other sites
Hi Sharlin,

You don't have to explicity insert and eraze vertices. Just start with an empty second list (best just make that a statically allocated buffer), and add vertices to it. When an edge is completely visible, add the end vertex. If the edge goes from inside to outside, compute the intersection and add that. If an edge is completely outside, add nothing. And when an edge goes from outside to inside, calculate the intersection, add it, and also the end vertex of that edge. This is the Sutherland-Hodgman algorithm. It works for convex polygons. When you start with a triangle, every new clipped polygon (per plane) will be convex too.

For rasterization, the easiest and at the same time most accurate way is to render convex n-gons as a triangle fan. Trust me, it's too much trouble and doesn't gain you much by rasterizing them as one whole.

Share this post


Link to post
Share on other sites

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this