有朋友说我的源码有些地方填充不到... 四向联通是这样的,改成八向就可以了 /** * 种子填充算法,八向连通,用来生成水平面 * @param fillPointY 填充点的y坐标 */ void ObjectLiquid::boundaryFill4(int x, int z, Real fillPointY) { int index = x + z*(mXSize+1); Real currentPiontY = mHeightMapData[index]; // 得到当前点的高度 // 如果当前点的高度小于水平面,同时没有被标记(防止重复查找) if(currentPiontY <= fillPointY && mFlagData[index] == false && x+1 < mXSize+1 && x-1 > 0 && z+1 < mZSize+1 && z-1 > 0){ // 保存该点水深 mWaterDepthData[index] = (fillPointY - currentPiontY); // 标记该点 mFlagData[index] = true; // 继续查找相邻的8个点 boundaryFill4(x+1, z, fillPointY); boundaryFill4(x-1, z, fillPointY); boundaryFill4(x, z+1, fillPointY); boundaryFill4(x, z-1, fillPointY); // boundaryFill4(x-1, z-1, fillPointY); boundaryFill4(x+1, z-1, fillPointY); boundaryFill4(x-1, z+1, fillPointY); boundaryFill4(x+1, z+1, fillPointY); }else{ // 边界点也要计算在内 mFlagData[index] = true; } }