Game Development Reference
In-Depth Information
// Check if we ￿ re categorizing polygons from the same
// brush that we ￿ re using for categorization.
if currentBrush == this.Brush:
// Set all polygons from this brush to visible,
// in case they were set invisible before.
// (this avoids duplicate polygons)
for polygon in inputPolygons:
polygon.visible = true
// Categorize all polygons as touching and return.
touching.append(inputPolygons)
return
for inputPolygon in inputPolygons:
result = this.splitPolygons(inputPolygon ,
newPolygon, outside)
if result == Category.aligned:
// The brush we ￿ re touching now is not the brush the
// polygon belongs to, so it ￿ s a duplicate polygon.
// We only keep the duplicates that belong to the last
// brush it touches (it can become visible again later).
touching.append(inputPolygon)
inputPolygon.visible = False
else if result == Category.inverseAligned:
touchingInv.append(inputPolygon)
// ... same as above ...
inputPolygon.visible = False
else if result == Category.inside:
inside.append(inputPolygon)
else if result == Category.outside:
outside.append(inputPolygon)
function splitPolygons(inputPolygons , newPolygons, outside):
// Loop through all the polygons to split them
// by the planes of the other brush
finalResult = Category.inside
for cuttingPlane in self.Brush.planes:
result, outsidePolygon = inputPolygon.split(cuttingPlane)
if result == Category.outside:
return result;
elif result in (Category.aligned, Category.inverseAligned):
// We remember that one of the planes
// was aligned with our polygon ..
finalResult = result
elif result == Category.split:
// Add the part that was outside to
// our list of polygons ..
newPolygons.append(outsidePolygon)
// .. and add it to the outside category
outside.append(outsidePolygon)
// Note: remaining polygons are either
// completely inside,
// or plane (inverse) aligned
return finalResult
Listing 8.1. The brush categorization and clipping method.
Search WWH ::




Custom Search