v0.13.0.11

This commit is contained in:
Joonas Rikkonen
2021-04-22 17:33:08 +03:00
parent 0697d7fc64
commit 8bb31f2893
391 changed files with 17271 additions and 5949 deletions
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using Barotrauma.Extensions;
using System.Linq;
namespace Barotrauma
{
@@ -723,7 +724,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[]>
{
@@ -745,6 +746,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 });
@@ -900,6 +921,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>
@@ -930,12 +953,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;
@@ -1046,6 +1067,16 @@ namespace Barotrauma
if (diff == 0) { return v >= max ? 1f : 0f; }
return MathHelper.Clamp((v - min) / diff, 0f, 1f);
}
public static float Min(params float[] vals)
{
return vals.Min();
}
public static float Max(params float[] vals)
{
return vals.Max();
}
}
class CompareCCW : IComparer<Vector2>