/// <summary> /// Sorts a list of points around a center. /// </summary> /// <param name="center"></param> /// <param name="points"></param> /// <param name="clockwise"></param> /// <returns>Returns a sorted list of points around a center.</returns> public static Vector2[] SortAroundCenter(Vector2 center, Vector2[] points, bool clockwise) { List <Vector2> sortedPoints = null; sortedPoints = Hedra.Copy(points.ToList()); sortedPoints.Sort((v1, v2) => { float angle1 = Hedra.Angle(center, center + Vector2.left, v1); float angle2 = Hedra.Angle(center, center + Vector2.left, v2); if (angle1 > angle2) { return(1); } else if (angle1 == angle2) { return(0); } else { return(-1); } }); return(sortedPoints.ToArray()); }
/// <summary> /// Hard clamps the value to the nearest limit. /// </summary> /// <param name="value">Value to clamp.</param> /// <param name="upperLimit"></param> /// <param name="centerLimit"></param> /// <param name="bottomLimit"></param> /// <returns></returns> public static Vector2 HardClamp(Vector2 value, int bottomLimit, int centerLimit, int upperLimit) { Vector2 clampedValue = new Vector2( Hedra.HardClamp(value.x, bottomLimit, centerLimit, upperLimit), Hedra.HardClamp(value.y, bottomLimit, centerLimit, upperLimit) ); return(clampedValue); }
/// <summary> /// Hard clamps the value to the nearest limit. /// </summary> /// <param name="value">Value to clamp.</param> /// <param name="upperLimit"></param> /// <param name="centerLimit"></param> /// <param name="bottomLimit"></param> /// <returns></returns> public static Vector3 HardClamp(Vector3 value, float bottomLimit, float centerLimit, float upperLimit) { Vector3 clampedValue = new Vector3( Hedra.HardClamp(value.x, bottomLimit, centerLimit, upperLimit), Hedra.HardClamp(value.y, bottomLimit, centerLimit, upperLimit), Hedra.HardClamp(value.z, bottomLimit, centerLimit, upperLimit) ); return(clampedValue); }
/// <summary> /// Returns the angle degrees between vectors A and B. /// https://www.gamedev.net/forums/topic/509720-angle-between-two-3d-points/ /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <returns></returns> public static float Angle(Vector3 A, Vector3 B) { Vector3 a = A.normalized; Vector3 b = B.normalized; Vector3 perpendicular = Vector3.Cross(a, b).normalized; Vector3 normal = Hedra.Abs(perpendicular); // atan2((Vb x Va).Vn, Va.Vb) - https://stackoverflow.com/questions/5188561/signed-angle-between-two-3d-vectors-with-same-origin-within-the-same-plane return(Mathf.Atan2(Vector3.Dot(perpendicular, normal), Vector3.Dot(a, b)) * Mathf.Rad2Deg); }
public static void DrawWireCube(Collider collider, Quaternion rotation) { if (collider == null) { return; } if (collider is BoxCollider) { BoxCollider box = (BoxCollider)collider; Hedra.DrawWireCube(box.bounds.center, box.size, rotation); } else { Hedra.DrawWireCube(collider.bounds.center, collider.bounds.size, rotation); } }