bool onlyAirBetween(Vector3S start, Vector3S end) { Vector3D s = new Vector3D(start); Vector3D e = new Vector3D(end); while ((s - e).Length > 1) { if (AirMap[(int)s.x, (int)s.z, (int)s.y] == TriBool.True) return false; } return true; }
public bool Within(Vector3D pos) { return Max.x >= pos.x && Max.z >= pos.z && Max.y >= pos.y && Min.x <= pos.x && Min.z <= pos.z && Min.y <= pos.y; }
public static Zone FindWithin(Vector3D pos) { foreach (var zone in Zones) { if (zone.ProtectedZone.Within(pos)) return zone; } return null; }
public static List<Zone> FindAllWithin(Vector3D pos) { var zones = new List<Zone>(); foreach (var zone in Zones) { if (zone.ProtectedZone.Within(pos)) zones.Add(zone); } return zones; }
/// <summary> /// Initializes a new instance of the <see cref="Cuboid"/> class. /// </summary> /// <param name="point1">The first <see cref="Vector3D"/>.</param> /// <param name="point2">The second <see cref="Vector3D"/>.</param> /// <remarks></remarks> public Cuboid(Vector3D point1, Vector3D point2) { Max = new Vector3D( Math.Max(point1.x, point2.x), Math.Max(point1.z, point2.z), Math.Max(point1.y, point2.y) ); Min = new Vector3D( Math.Min(point1.x, point2.x), Math.Min(point1.z, point2.z), Math.Min(point1.y, point2.y) ); }
public Zone(Vector3D point1, Vector3D point2, string owner, string name, byte minimumGroup, Level level, bool skipChecks = false) { ProtectedZone = new Cuboid(point1, point2); Owner = owner; Permission = minimumGroup; Zones.Add(this); Level = level; Name = name; if (skipChecks) return; ZoneList zones; if (Level.ExtraData.ContainsKey("zones")) { zones = ZoneList.FromString((string)Level.ExtraData.GetIfExist("zones"), Level); zones.Add(this); } else { zones = GetAllZonesForLevel(Level); } Level.ExtraData["zones"] = zones; }
public static Vector3D MinusY(Vector3D a, int b) { return new Vector3D(a.x, a.z, (double)(a.y - b)); }
public static Vector3D MinusAbs(Vector3D a, Vector3D b) { //Get positive int return new Vector3D((double)Math.Abs(a.x - b.x), (double)Math.Abs(a.z - b.z), (double)Math.Abs(a.y - b.y)); }
/// <summary> /// Causes a block change for the level /// </summary> /// <param name="vector">Position of the block</param> /// <param name="block">Block to set</param> /// <param name="p">A player who doesn't need the update.</param> public void BlockChange(Vector3D vector, byte block, Player p = null) { BlockChange((ushort)vector.x, (ushort)vector.z, (ushort)vector.y, block, p); }
/// <summary> /// Creates a path to another vector /// </summary> /// <param name="vectorTo">The vector to.</param> /// <returns>An enumeration of a path from a vector to a vector</returns> public IEnumerable<Vector3S> PathTo(Vector3S vectorTo) { Vector3D pos = new Vector3D(this); Vector3S rounded = pos.GetRounded(); while (rounded != vectorTo) { yield return rounded; pos.Move(1, new Vector3D(vectorTo)); rounded = pos.GetRounded(); } yield return vectorTo; yield break; Vector3S tempThis = new Vector3S(this); Vector3S a = vectorTo - this; Vector3S b = MathUtils.SignVector(a); a = MathUtils.AbsVector(a); Vector3S c = a * 2; int x, z, y; if ((a.x >= a.y) && (a.x >= a.z)) { x = 0; z = 1; y = 2; } else if ((a.y >= a.x) && (a.y >= a.z)) { x = 1; z = 2; y = 0; } else { x = 2; z = 0; y = 1; } int right = c.GetDimention(y) - a.GetDimention(x); int left = c.GetDimention(z) - a.GetDimention(x); for (int j = 0; j < a.GetDimention(x); j++) { yield return tempThis; if (right > 0) { tempThis.SetValueInDimention(y, (short)(b.GetDimention(y) + tempThis.GetDimention(y))); right -= c.GetDimention(x); } if (left > 0) { tempThis.SetValueInDimention(z, (short)(b.GetDimention(z) + tempThis.GetDimention(z))); left -= c.GetDimention(x); } right += c.GetDimention(y); left += c.GetDimention(z); tempThis.SetValueInDimention(x, (short)(b.GetDimention(x) + tempThis.GetDimention(x))); } yield return vectorTo; }
/// <summary> /// Gets a vector where every indices has been Math.Absoluted. /// </summary> /// <param name="Vector">The vector.</param> /// <returns>A absoluted Vector</returns> public static Vector3D AbsVector(Vector3D Vector) { return new Vector3D(Math.Abs(Vector.x), Math.Abs(Vector.z), Math.Abs(Vector.y)); }
public Vector3D(Vector3D v) : this(v.x, v.z, v.y) { }
/// <summary> /// Initializes a new instance of the <see cref="Cuboid"/> class. /// </summary> /// <remarks>Size is 0</remarks> public Cuboid() { Max = Min = new Vector3D(0, 0, 0); }
int Add(Vector3D from, Vector3D to) { fromList.Add(from); toList.Add(to); return fromList.Count; }
public Vector3D GetMove(double distance, Vector3D towards) { Vector3D ret = new Vector3D(x, z, y); ret.Move(distance, towards); return ret; }
/// <summary> /// Gets a vector where every indices has been Math.Tangented. /// </summary> /// <param name="Vector">The vector.</param> /// <returns>A tangified Vector</returns> public static Vector3D TanVector(Vector3D Vector) { return new Vector3D(Math.Tan(Vector.x), Math.Tan(Vector.z), Math.Tan(Vector.y)); }
public void Move(double distance, Vector3D towards) { Vector3D way = towards - this; double length = way.Length; x += (double)(way.x / length) * distance; y += (double)(way.y / length) * distance; z += (double)(way.z / length) * distance; }
/// <summary> /// Gets a vector where every indices has been signed /// </summary> /// <param name="Vector">The vector.</param> /// <returns>A signed Vector</returns> public static Vector3D SignVector(Vector3D Vector) { return new Vector3D(Math.Sign(Vector.x), Math.Sign(Vector.z), Math.Sign(Vector.y)); }
/// <summary> /// Determines whether the specified vector is in bounds of the level. /// </summary> /// <param name="vector">The vector.</param> /// <returns> /// <c>true</c> if [is in bounds] [the specified vector]; otherwise, <c>false</c>. /// </returns> public bool IsInBounds(Vector3D vector) { return IsInBounds((int)vector.x, (int)vector.z, (int)vector.y); }
/// <summary> /// Initializes a new instance of the <see cref="Cuboid"/> class. /// </summary> /// <param name="origin">The <see cref="Vector3D"/>.</param> /// <param name="size">The <see cref="Vector3S"/>.</param> /// <remarks></remarks> public Cuboid(Vector3D origin, Vector3S size) : this(origin, origin + size) { }