Clipping Planes

Started by
3 comments, last by steveharper101 22 years, 9 months ago
I have calculated all the correct vertices from planes in a worldcraft mapfile. Only problem is the face data needs to be clipped against the planes I have no idea on how to do this could someone please help. Code would help Thanks ~Steve~
Advertisement
I just finished working on this very problem myself. I found this tutorial at this site that explains techniques for converting .map file geometry to polygons: http://www.uio.no/~stefanha/

Personally, I prefer the ''clipping the big polygon approach'', which I think is how qcsg does it. I''d be happy to share my approach with you if you''re interested.
Yes thanks I prefear this method too and have already begun an engine using this. If you could give us any info on clipping the large faces with planes it would be greatly apreciated please mail me at: steveharper@clara.com

Thanks Again

~Steve~
Sure, it's quite easy. Here are the steps I use to form a polygon from the 3-point face definition of a .MAP file brush, which you'd repeat for each face of the brush:

1. Make 3 orthogonal axes (u,v,n) starting from face point 2. Let n be the outward face normal formed by taking the cross product of the three points: (pt3 - pt1) ^ (pt2 - pt1). Let u be the vector formed by subtracting point 1 from point 2, and let v be the cross product of the face normal and u: n ^ u. Normalize these three vectors and you'll have a left-handed coordinate system with it's origin at point 2 on the face. The polygon that we form will be coplanar with the u/v plane and hence the brush face.

2. Make a big-ass polygon that lies on the u/v plane. You do this by finding 4 points on the u/v plane that are equidistant from the u,v,n origin. They should be distant enough so that no polygon in your 3D world could ever be so big. For example, I think the largest brush in Worldcraft can be 8192 units wide. So we'll need a polygon at least twice this size to ensure that we don't wind up with an incorrect size after clipping. (This is hard to explain but should make sense later when you think about what would happen if face point 2 lies on the edge of the world.) The way to find these 4 points is through a little vector scale and addition. You just multiply u, -u, v, and -v by say, 9999, and add these to face pt2, which is the origin of u,v,n, like this:

polyPt1 = facePt2 + (9999 * v)
polyPt2 = facePt2 + (9999 * u)
polyPt3 = facePt2 - (9999 * v)
polyPt4 = facePt2 - (9999 * u)

Now you've got your big-ass polygon. Notice that the winding order is clockwise.

3. Clip the big-ass polygon with all the other face planes in the brush. This step is simple. You just loop through all the other faces in the brush, forming a plane out of each one, and do standard Sutherland clipping on the big poly. If a face plane intersects the big polygon, you clip the big polygon (which gets smaller each time it's clipped) and keep the back portion for the next iteration. What you wind up with is a polygon that shares edges with all its neigboring faces in the brush, and this what we're after.


Hope this makes sense. Please don't take my word as an expert at this stuff because I'm quite new to it. I'm sure others have tackled the same problem in different ways.







Edited by - PigVomit on June 30, 2001 6:45:28 PM
Cheers for the help PigsVomit

This topic is closed to new replies.

Advertisement