1
0

Ravines: implemented linear finishing, now the ravine walls are smooth.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@685 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-07-20 16:22:07 +00:00
parent c3c149d62e
commit 917d75edbe

View File

@ -316,7 +316,48 @@ void cStructGenRavines::cRavine::Smooth(void)
void cStructGenRavines::cRavine::FinishLinear(void)
{
// TODO
// For each segment, use Bresenham's algorithm to draw a "line" of defpoints
// _X 2012_07_20: I tried modifying this algorithm to produce "thick" lines (only one coord change per point)
// But the results were about the same as the original, so I disposed of it again - no need to use twice the count of points
cDefPoints Pts;
std::swap(Pts, m_Points);
m_Points.reserve(Pts.size() * 3);
int PrevX = Pts.front().m_BlockX;
int PrevZ = Pts.front().m_BlockZ;
for (cDefPoints::const_iterator itr = Pts.begin() + 1, end = Pts.end(); itr != end; ++itr)
{
int x1 = itr->m_BlockX;
int z1 = itr->m_BlockZ;
int dx = abs(x1 - PrevX);
int dz = abs(z1 - PrevZ);
int sx = (PrevX < x1) ? 1 : -1;
int sz = (PrevZ < z1) ? 1 : -1;
int err = dx - dz;
int R = itr->m_Radius;
int T = itr->m_Top;
int B = itr->m_Bottom;
while (true)
{
m_Points.push_back(cDefPoint(PrevX, PrevZ, R, T, B));
if ((PrevX == x1) && (PrevZ == z1))
{
break;
}
int e2 = 2 * err;
if (e2 > -dz)
{
err -= dz;
PrevX += sx;
}
if (e2 < dx)
{
err += dx;
PrevZ += sz;
}
} // while (true)
} // for itr
}