private void TraversePositions(PositionArray positions, float px, float py, float dir, bool first) { SizeF ef1 = positions.CellSize; int num1 = positions.GetDist(px, py); float single1 = px; float single2 = py; float single3 = single1; float single4 = single2; if (dir == 0f) { single3 += ef1.Width; } else if (dir == 90f) { single4 += ef1.Height; } else if (dir == 180f) { single3 -= ef1.Width; } else { single4 -= ef1.Height; } while ((num1 > 1) && (positions.GetDist(single3, single4) == (num1 - 1))) { single1 = single3; single2 = single4; if (dir == 0f) { single3 += ef1.Width; } else if (dir == 90f) { single4 += ef1.Height; } else if (dir == 180f) { single3 -= ef1.Width; } else { single4 -= ef1.Height; } num1--; } if (first) { if (num1 > 1) { if ((dir == 180f) || (dir == 0f)) { single1 = (((float)System.Math.Floor((double)(single1 / ef1.Width))) * ef1.Width) + (ef1.Width / 2f); } else { single2 = (((float)System.Math.Floor((double)(single2 / ef1.Height))) * ef1.Height) + (ef1.Height / 2f); } } } else { single1 = (((float)System.Math.Floor((double)(single1 / ef1.Width))) * ef1.Width) + (ef1.Width / 2f); single2 = (((float)System.Math.Floor((double)(single2 / ef1.Height))) * ef1.Height) + (ef1.Height / 2f); } if (num1 > 1) { float single5 = dir; float single6 = single1; float single7 = single2; if (dir == 0f) { single5 = 90f; single7 += ef1.Height; } else if (dir == 90f) { single5 = 180f; single6 -= ef1.Width; } else if (dir == 180f) { single5 = 270f; single7 -= ef1.Height; } else if (dir == 270f) { single5 = 0f; single6 += ef1.Width; } if (positions.GetDist(single6, single7) == (num1 - 1)) { this.TraversePositions(positions, single6, single7, single5, false); } else { float single8 = single1; float single9 = single2; if (dir == 0f) { single5 = 270f; single9 -= ef1.Height; } else if (dir == 90f) { single5 = 0f; single8 += ef1.Width; } else if (dir == 180f) { single5 = 90f; single9 += ef1.Height; } else if (dir == 270f) { single5 = 180f; single8 -= ef1.Width; } if (positions.GetDist(single8, single9) == (num1 - 1)) { this.TraversePositions(positions, single8, single9, single5, false); } } } base.AddPoint(single1, single2); }
public void PrimitiveStructure(out VertexPositionColorTexture[] vertices, out short[] indeces) { List <VertexPositionColorTexture> vertexList = new List <VertexPositionColorTexture>(); List <short> indexList = new List <short>(); //Cut down a bit on boilerplate by adding a method void AddVertexIndex(Vector2 position, Vector2 TextureCoords) { indexList.Add((short)vertexList.Count); vertexList.Add(new VertexPositionColorTexture(new Vector3(position - Main.screenPosition, 0), Color, TextureCoords)); } //Check if the array is not too small first if (PositionArray.Length >= (TaperingType == StripTaperType.TaperBoth ? 3 : 2)) { //Iterate through the given array of positions for (int i = 0; i < PositionArray.Length - 1; i++) { int start = 0; int end = PositionArray.Length - 2; float progress = (i + 1) / (float)PositionArray.Length; //Modify width of the triangles based on progress through iterating through the array float widthModifier = 1; switch (TaperingType) { case StripTaperType.TaperStart: widthModifier *= progress; break; case StripTaperType.TaperEnd: widthModifier *= (1 - progress); break; case StripTaperType.TaperBoth: progress = (i + 1) / (float)(PositionArray.Length - 1); widthModifier *= (float)Math.Pow(1 - (Math.Abs(progress - 0.5f) * 2), 0.5f); break; } if (WidthDelegate != null) { widthModifier *= WidthDelegate.Invoke(progress); } //If on the first element of the array, add the vertices corresponding to the front of the trail if (i == start) { Vector2 currentPosition = PositionArray[i]; if (TaperingType == StripTaperType.TaperStart || TaperingType == StripTaperType.TaperBoth) //Only add the center point if set to taper at the start { AddVertexIndex(currentPosition, new Vector2(0.5f, 0)); } else { Vector2 currentWidthUnit = CurveNormal(PositionArray.ToList(), i); float startWidth = WidthDelegate == null ? 1 : WidthDelegate.Invoke(0); Vector2 currentLeft = currentPosition - (currentWidthUnit * Width * startWidth); Vector2 currentRight = currentPosition + (currentWidthUnit * Width * startWidth); AddVertexIndex(currentRight, new Vector2(1, 0)); AddVertexIndex(currentLeft, new Vector2(0, 0)); } } Vector2 nextPosition = PositionArray[i + 1]; if (i == end && (TaperingType == StripTaperType.TaperEnd || TaperingType == StripTaperType.TaperBoth)) //Only add the center point if set to taper at the end { AddVertexIndex(nextPosition, new Vector2(0.5f, 1)); } else //Add vertices based on the next position of the array { Vector2 nextWidthUnit = CurveNormal(PositionArray.ToList(), i + 1); Vector2 nextLeft = nextPosition - (nextWidthUnit * Width * widthModifier); Vector2 nextRight = nextPosition + (nextWidthUnit * Width * widthModifier); //Needs to be in opposite order with this tapering type to avoid backwards facing primitives if (TaperingType == StripTaperType.TaperBoth) { AddVertexIndex(nextLeft, new Vector2(0, progress)); AddVertexIndex(nextRight, new Vector2(1, progress)); } else { AddVertexIndex(nextRight, new Vector2(1, progress)); AddVertexIndex(nextLeft, new Vector2(0, progress)); } } } } vertices = vertexList.ToArray(); indeces = indexList.ToArray(); }