Unstable v0.1300.0.0 (February 19th 2021)

This commit is contained in:
Joonas Rikkonen
2021-02-25 13:44:23 +02:00
parent b772654326
commit 24cbef485a
441 changed files with 21343 additions and 8562 deletions
@@ -678,27 +678,11 @@ namespace Barotrauma
public static List<Vector2[]> TriangulateConvexHull(List<Vector2> vertices, Vector2 center)
{
List<Vector2[]> triangles = new List<Vector2[]>();
int triangleCount = vertices.Count - 2;
vertices.Sort(new CompareCCW(center));
int lastIndex = 1;
for (int i = 0; i < triangleCount; i++)
for (int i = 0; i < vertices.Count; i++)
{
Vector2[] triangleVertices = new Vector2[3];
triangleVertices[0] = vertices[0];
int k = 1;
for (int j = lastIndex; j <= lastIndex + 1; j++)
{
triangleVertices[k] = vertices[j];
k++;
}
lastIndex += 1;
triangles.Add(triangleVertices);
triangles.Add(new Vector2[3] { center, vertices[i], vertices[(i + 1) % vertices.Count] });
}
return triangles;
}
@@ -739,7 +723,7 @@ namespace Barotrauma
return wrappedPoints;
}
public static List<Vector2[]> GenerateJaggedLine(Vector2 start, Vector2 end, int iterations, float offsetAmount)
public static List<Vector2[]> GenerateJaggedLine(Vector2 start, Vector2 end, int iterations, float offsetAmount, Rectangle? bounds = null)
{
List<Vector2[]> segments = new List<Vector2[]>
{
@@ -761,6 +745,26 @@ namespace Barotrauma
normal = new Vector2(-normal.Y, normal.X);
midPoint += normal * Rand.Range(-offsetAmount, offsetAmount, Rand.RandSync.Server);
if (bounds.HasValue)
{
if (midPoint.X < bounds.Value.X)
{
midPoint.X = bounds.Value.X + (bounds.Value.X - midPoint.X);
}
else if (midPoint.X > bounds.Value.Right)
{
midPoint.X = bounds.Value.Right - (midPoint.X - bounds.Value.Right);
}
if (midPoint.Y < bounds.Value.Y)
{
midPoint.Y = bounds.Value.Y + (bounds.Value.Y - midPoint.Y);
}
else if (midPoint.Y > bounds.Value.Bottom)
{
midPoint.Y = bounds.Value.Bottom - (midPoint.Y - bounds.Value.Bottom);
}
}
segments.Insert(i, new Vector2[] { startSegment, midPoint });
segments.Insert(i + 1, new Vector2[] { midPoint, endSegment });
@@ -916,6 +920,8 @@ namespace Barotrauma
return (float)Math.Pow(f, p);
}
public static float Pow2(float f) => f * f;
/// <summary>
/// Converts the alignment to a vector where -1,-1 is the top-left corner, 0,0 the center and 1,1 bottom-right
/// </summary>
@@ -946,12 +952,10 @@ namespace Barotrauma
/// Modified from:
/// http://www.gamefromscratch.com/post/2012/11/24/GameDev-math-recipes-Rotating-one-point-around-another-point.aspx
/// </summary>
public static Vector2 RotatePointAroundTarget(Vector2 point, Vector2 target, float degrees, bool clockWise = true)
public static Vector2 RotatePointAroundTarget(Vector2 point, Vector2 target, float radians, bool clockWise = true)
{
// (Math.PI / 180) * degrees
var angle = MathHelper.ToRadians(degrees);
var sin = Math.Sin(angle);
var cos = Math.Cos(angle);
var sin = Math.Sin(radians);
var cos = Math.Cos(radians);
if (!clockWise)
{
sin = -sin;