7.12.2012

Some interesting points about rect/cube clipping

Thinking about it, a clipping operation to draw from a source rect in buffer A to a destination rect in buffer B is actually a rather complex operation. First of all, both areas can be outside their actual buffer size/area. You need to perform a plain clipping to prevent out-of-range values, negative indices for arrays and so on. If that's done you need to make sure that you transer the source area from source space to destination space (though that's a pretty simple addition operation on a few vectors), build the intersection between both (the area we can iterate later to blit stuff) and create a translation vector to be added each time we want to convert the destination space to source space during destination iteration. So it's something you could theoretically solve using matrix transformations and preceding validity check. What's interesting about is that this generalization would make it possible to solve other clipping problems the same way or even problems I'd never think of solving using this method. Atleast I can freely combine my two clipping function with raw blitting operations to get optimal performance. Anyway, I always love the insight and general connection to deeper understanding of the very basic blocks that make up every-day computing features. Way more interesting that sticking existing stuff together.

No comments: