在每行/行一次通过中检测边界(但首先不是角)的算法将是:
for each horizontal line
previousTag = getTag( first line pixel ) // land or water in our example
for each pixel of the line
currentTag = getTag( this pixel )
if ( previousTag == currentTag )
continue // not a border
else
// We got a vertical border, do what is needed
previousTag = currentTag
endforeach
endforeach
垂直线也是如此(不是增加 x,而是增加 y。我们也可以在这里知道我们是否有一个角而不是垂直边框:
for each vertical line
previousTag = getTag( first line pixel ) // land or water in our example
for each pixel of the line
currentTag = getTag( this pixel )
if ( previousTag == currentTag )
continue // not a border
else
if ( pixel on the right or on the left is a border )
// we got a corner
else
// we got a horizontal border
previousTag = currentTag
endforeach
endforeach
这应该是一个预处理过程,除非您的地形是动态的。无论如何不要在每一帧都这样做!