public RiverInfo(RiverGenerator rg) { riverPath = new List<Vertex>(); //reachTop = false; //reachRight = false; //reachBot = false; //reachLeft = false; fd = rg.fd; frp = rg.frp; ftm = rg.ftm; fmc = rg.fmc; reachedSides = new List<Direction>(); shape = RiverShape.atan; lowestPoint = new Vertex(666, 666, 666); globalRiverC = new GlobalCoordinates(100); }
/// <summary> /// calls depth function (currently MySinc) /// </summary> private float GetDepth(float origHeight, float distance, float width, float maxDepth, RiverShape shape) { float dif = origHeight - currentRiver.lowestPoint.height; if (dif < 0) dif = 0; if (currentRiver.lowestPoint.height == 666 && counter < 10) { //Debug.Log("?"); counter++; } if (origHeight == 666 && counter < 10) { Debug.Log("!"); counter++; } switch (shape) { case RiverShape.sinc: return MySinc(distance, width, (dif + 1) * maxDepth * 5); case RiverShape.atan: return MyArctan(distance, width, (dif + 1) * maxDepth); default: return MyArctan(distance, width, (dif + 1) * maxDepth); } }
/// <summary> /// digs river path (not corners) /// </summary> private void DigRiverPath(List<Vertex> path, int width, float widthFactor, float maxDepth, RiverShape shape) { for (int i = 0; i < path.Count - 1; i++) { Vertex previous = i > 0 ? path[i - 1] : path[i]; Vertex v1 = path[i]; Vertex v2 = path[i + 1]; Vertex next = i < path.Count - 2 ? path[i + 2] : path[i + 1]; DigRiverPart(v1, v2, previous, next, width, widthFactor, maxDepth, shape); } }
/// <summary> /// digs river part v1 -> v2 /// previous and next are used to determine which node does processed point belong to /// </summary> /// <param name="previous">node before v1</param> /// <param name="next">node after v2</param> private void DigRiverPart(Vertex v1, Vertex v2,Vertex previous, Vertex next, int width, float widthFactor, float maxDepth, RiverShape shape) { Vertex botLeft = fmc.CalculateBotLeft(v1, v2, width, widthFactor); Vertex topRight = fmc.CalculateTopRight(v1, v2, width, widthFactor); for (int x = botLeft.x; x < topRight.x; x++) { for (int z = botLeft.z; z < topRight.z; z++) { Vertex point = new Vertex(x, z); float distance = fmc.GetDistanceFromLine(point, v1, v2); float distV1 = fmc.GetDistance(point, v1); float distV2 = fmc.GetDistance(point, v2); float distanceFromCorners = Math.Max(distV1, distV2); float cornersDistance = fmc.GetDistance(v1, v2); if (lt.globalTerrainC.IsDefined(x, z)&& distance < widthFactor * width && distanceFromCorners <= cornersDistance) { //float depth = GetDepth(lt.globalTerrainC.GetValue(x, z), distance, width, maxDepth); float depth = GetDepth(lt.lm.GetCurrentHeight(x, z), distance, width, maxDepth, shape); float distanceFromPrevNext = 0; float PrevNextDistance = 0; if (distV1 < distV2) { distanceFromPrevNext = fmc.GetDistance(point, previous); PrevNextDistance = fmc.GetDistance(v1, previous); } else { distanceFromPrevNext = fmc.GetDistance(point, next); PrevNextDistance = fmc.GetDistance(v2, next); } if (depth < currentRiver.globalRiverC.GetValue(x, z) && (cornersDistance - distanceFromCorners) >= (PrevNextDistance - distanceFromPrevNext)) { currentRiver.globalRiverC.SetValue(x, z, depth); //globalRiverC.SetValue(x, z, -5); } } } } }
/// <summary> /// dig corners /// </summary> private void DigCorners(List<Vertex> path, int width, float widthFactor, float depth, RiverShape shape) { for (int i = 0; i < path.Count; i++) { Vertex previous = i > 0 ? path[i - 1] : path[i+1]; Vertex corner = path[i]; Vertex next = i < path.Count-1 ? path[i + 1] : path[i - 1]; DigCorner(corner, previous, next, width, widthFactor, depth, shape); } }
/// <summary> /// gigs only certain angle of corner /// the angle is determined by sharpness of the path (from prev->corner->next sequence) /// </summary> private void DigCorner(Vertex corner, Vertex previous, Vertex next, int width, float widthFactor, float maxDepth, RiverShape shape) { Vertex botLeft = new Vertex(corner.x - (int)(widthFactor * width), corner.z - (int)(widthFactor * width)); Vertex topRight = new Vertex(corner.x + (int)(widthFactor * width), corner.z + (int)(widthFactor * width)); float cornerPreviousDistance = fmc.GetDistance(corner, previous); float cornerNextDistance = fmc.GetDistance(corner, next); for (int x = botLeft.x; x < topRight.x; x++) { for (int z = botLeft.z; z < topRight.z; z++) { Vertex point = new Vertex(x, z); float distance = fmc.GetDistance(point, corner); if (lt.globalTerrainC.IsDefined(x, z) && distance < widthFactor * width)// && distance > distancePrevious && distance > distanceNext) { float pointPreviousDistance = fmc.GetDistance(point, previous); float pointNextDistance = fmc.GetDistance(point, next); if (pointPreviousDistance >= cornerPreviousDistance && pointNextDistance >= cornerNextDistance) { //float depth = GetDepth(lt.globalTerrainC.GetValue(x, z), distance, width, maxDepth); float depth = GetDepth(lt.lm.GetCurrentHeight(x, z), distance, width, maxDepth, shape); //if (depth < globalRiverC.GetValue(x, z)) if (!currentRiver.globalRiverC.IsDefined(x,z) || depth < currentRiver.globalRiverC.GetValue(x, z)) { currentRiver.globalRiverC.SetValue(x, z, depth); //globalRiverC.SetValue(x, z, -5); } } } } } }