void dropStoneLine( int x, int y, int stoneSize, int stoneWeight) {
// 判断坐标是否在屏幕范围内
if ((x + stoneSize) > m_width || (y + stoneSize) > m_height
|| (x - stoneSize) < 0 || (y - stoneSize) < 0) {
return ;
}
for ( int posx = x - stoneSize; posx < x + stoneSize; ++posx) {
for ( int posy = y - stoneSize; posy < y + stoneSize; ++posy) {
m_buf1 [ m_width * posy + posx] = -40;
}
}
}
// xs , ys : 起始点, xe , ye : 终止点
// size : 波源半径, weight : 波源能量
void breasenhamDrop ( int xs, int ys, int xe, int ye, int size, intweight)
{
int dx = xe - xs;
int dy = ye - ys;
dx = (dx >= 0) ? dx : -dx;
dy = (dy >= 0) ? dy : -dy;
if (dx == 0 && dy == 0) {
dropStoneLine(xs, ys, size, weight);
}
else if (dx == 0) {
int yinc = (ye - ys != 0) ? 1 : -1;
for ( int i = 0; i < dy; ++i){
dropStoneLine (xs, ys, size, weight);
ys += yinc;
}
}
else if (dy == 0) {
int xinc = (xe - xs != 0) ? 1 : -1;
for ( int i = 0; i < dx; ++i){
dropStoneLine(xs, ys, size, weight);
xs += xinc;
}
}
else if (dx > dy) {
int p = (dy << 1) - dx;
int inc1 = (dy << 1);
int inc2 = ((dy - dx) << 1);
int xinc = (xe - xs != 0) ? 1 : -1;
int yinc = (ye - ys != 0) ? 1 : -1;
for ( int i = 0; i < dx; ++i) {
dropStoneLine(xs, ys, size, weight);
xs += xinc;
if (p < 0) {
p += inc1;
}
else {
ys += yinc;
p += inc2;
}
}
}
else {
int p = (dx << 1) - dy;
int inc1 = (dx << 1);
int inc2 = ((dx - dy) << 1);
int xinc = (xe - xs != 0) ? 1 : -1;
int yinc = (ye - ys != 0) ? 1 : -1;
for ( int i = 0; i < dy; ++i) {
dropStoneLine(xs, ys, size, weight);
ys += yinc;
if (p < 0) {
p += inc1;
}
else {
xs += xinc;
p += inc2;
}
}
}
}
|