Tuesday, 27th June 2006

Clipping (adjusting walls to ensure that they are in the field of view so that they can be drawn correctly is being a right pain).

Firstly, I rewrote some of the really ugly wall-handling code:


Clipping follows the fairly simple maths:

Clip = (Y0 - m × X0) ÷ (1 - m)

(Where m is the gradient of the wall). The resulting Clip value then corresponds to the new (X,Y) coordinate - if you want to clip to x=-y all that's needed is (1 - m) becomes (1 + m) and Clip must be negated before using it as the new X coordinate.


The result (with added adjustment layer to turn the grey clipped line into red for clarity's sake) seems to work pretty well.


...or not. When implemented with the rest of the code, something goes rather wrong when I look at the wall from the wrong side. Thankfully, that was a simple bug in the division routine, causing it to trash the accumulator when one of the operands was negative (the accumulator itself formed part of one of the operands).


With that fixed, things look a bit more positive, but it's still rather unstable.

FirstPreviousNextLast RSSSearchBrowse by dateIndexTags