/// <summary> /// Get the larger of the point's two components. /// </summary> /// <returns>The maximum component of the point.</returns> /// <see cref="GetMin"/> /// <see cref="Size"/> /// <see cref="SizeSquared"/> public int GetMax() { return(FMath.Max(X, Y)); }
public bool ContainsNaN() { return(Origin.ContainsNaN() || BoxExtent.ContainsNaN() || !FMath.IsFinite(SphereRadius)); }
/// <summary> /// Helper function for rand implementations. /// </summary> /// <param name="a"></param> /// <returns>A random number in [0..A)</returns> public int RandHelper(int a) { // Can't just multiply GetFraction by A, as GetFraction could be == 1.0f return((a > 0) ? FMath.TruncToInt(GetFraction() * ((float)a - FMath.Delta)) : 0); }
/// <summary> /// Utility to check if all of the components of this vector are nearly zero given the tolerance. /// </summary> public bool IsNearlyZero3(float tolerance = FMath.KindaSmallNumber) { return(FMath.Abs(X) <= tolerance && FMath.Abs(Y) <= tolerance && FMath.Abs(Z) <= tolerance); }
/// <summary> /// Creates a rectangle from the right hand side of this rectangle. /// </summary> /// <param name="width">Width of the new rectangle (<= rectangles original width).</param> /// <returns>The new rectangle.</returns> public FIntRect Right(int width) { return(new FIntRect(FMath.Max(Min.X, Max.X - width), Min.Y, Max.X, Max.Y)); }
/// <summary> /// Calculates normalized version of vector without checking if it is non-zero. /// </summary> /// <returns>Normalized version of vector.</returns> public FVector4 GetUnsafeNormal3() { float scale = FMath.InvSqrt(X * X + Y * Y + Z * Z); return(new FVector4(X * scale, Y * scale, Z * scale, 0.0f)); }
/// <summary> /// Get the length (magnitude) of this vector, taking the W component into account /// </summary> /// <returns>The length of this vector</returns> public float Size() { return(FMath.Sqrt(X * X + Y * Y + Z * Z + W * W)); }
/// <summary> /// Test whether this sphere intersects another. /// </summary> /// <param name="other">The other sphere.</param> /// <param name="tolerance">Error tolerance.</param> /// <returns>true if spheres intersect, false otherwise.</returns> public bool Intersects(FSphere other, float tolerance = FMath.KindaSmallNumber) { return((Center - other.Center).SizeSquared() <= FMath.Square(FMath.Max(0.0f, other.W + W + tolerance))); }
/// <summary> /// Check whether two spheres are the same within specified tolerance. /// </summary> /// <param name="other">The other sphere.</param> /// <param name="tolerance">Error Tolerance.</param> /// <returns>true if spheres are equal within specified tolerance, otherwise false.</returns> public bool Equals(FSphere other, float tolerance = FMath.KindaSmallNumber) { return(Center.Equals(other.Center, tolerance) && FMath.Abs(W - other.W) <= tolerance); }
/// <summary> /// Performs a linear interpolation between two values, Alpha ranges from 0-1. /// </summary> public static FColor LerpStable(FColor a, FColor b, float alpha) { return(FMath.LerpStable(a, b, alpha)); }
/// <summary> /// Checks whether the given location is inside this sphere. /// </summary> /// <param name="v">The location to test for inside the bounding volume.</param> /// <param name="tolerance">Error Tolerance.</param> /// <returns>true if location is inside this volume.</returns> public bool IsInside(FVector v, float tolerance = FMath.KindaSmallNumber) { return((Center - v).SizeSquared() <= FMath.Square(W + tolerance)); }
/// <summary> /// Divide an int point and round down the result. /// </summary> /// <param name="lhs">The int point being divided.</param> /// <param name="divisor">What to divide the int point by.</param> /// <returns>A new divided int point.</returns> /// <see cref="DivideAndRoundUp(FIntPoint, int)"/> public static FIntPoint DivideAndRoundDown(FIntPoint lhs, int divisor) { return(new FIntPoint(FMath.DivideAndRoundDown(lhs.X, divisor), FMath.DivideAndRoundDown(lhs.Y, divisor))); }
/// <summary> /// Divide an int point and round up the result. /// </summary> /// <param name="lhs">The int point being divided.</param> /// <param name="divisor">What to divide the int point by.</param> /// <returns>A new divided int point.</returns> /// <see cref="DivideAndRoundDown"/> public static FIntPoint DivideAndRoundUp(FIntPoint lhs, FIntPoint divisor) { return(new FIntPoint(FMath.DivideAndRoundUp(lhs.X, divisor.X), FMath.DivideAndRoundUp(lhs.Y, divisor.Y))); }
/// <summary> /// Get the smaller of the point's two components. /// </summary> /// <returns>The minimum component of the point.</returns> /// <see cref="GetMax"/> /// <see cref="Size"/> /// <see cref="SizeSquared"/> public int GetMin() { return(FMath.Min(X, Y)); }
/// <summary> /// Similar to Lerp, but does not take the shortest path. Allows interpolation over more than 180 degrees. /// </summary> public static FRotator LerpRange(FRotator a, FRotator b, float alpha) { return(FMath.LerpRange(a, b, alpha)); }
/// <summary> /// Constructor /// </summary> /// <param name="vector">float vector converted to int</param> public FIntVector(FVector vector) { X = FMath.TruncToInt(vector.X); Y = FMath.TruncToInt(vector.Y); Z = FMath.TruncToInt(vector.Z); }
/// <summary> /// Check if the vector is of unit length, with specified tolerance. /// </summary> /// <param name="lengthSquaredTolerance">Tolerance against squared length.</param> /// <returns>true if the vector is a unit vector within the specified tolerance.</returns> public bool IsUnit3(float lengthSquaredTolerance = FMath.KindaSmallNumber) { return(FMath.Abs(1.0f - SizeSquared3()) < lengthSquaredTolerance); }
/// <summary> /// Gets the maximum value in the point. /// </summary> /// <returns>The maximum value in the point.</returns> public float GetMax() { return(FMath.Max(FMath.Max(X, Y), Z)); }
/// <summary> /// Get the length of this vector not taking W component into account. /// </summary> /// <returns>The length of this vector.</returns> public float Size3() { return(FMath.Sqrt(X * X + Y * Y + Z * Z)); }
/// <summary> /// Gets the minimum value in the point. /// </summary> /// <returns>The minimum value in the point.</returns> public float GetMin() { return(FMath.Min(FMath.Min(X, Y), Z)); }
/// <summary> /// Utility to check if there are any non-finite values (NaN or Inf) in this vector. /// </summary> public bool ContainsNaN() { return(!FMath.IsFinite(X) || !FMath.IsFinite(Y) || !FMath.IsFinite(Z) || !FMath.IsFinite(W)); }
/// <summary> /// Return the manhattan distance in degrees between this Rotator and the passed in one. /// </summary> /// <param name="rotator">the Rotator we are comparing with.</param> /// <returns>Distance(Manhattan) between the two rotators. </returns> public float GetManhattanDistance(FRotator rotator) { return(FMath.Abs(Yaw - rotator.Yaw) + FMath.Abs(Pitch - rotator.Pitch) + FMath.Abs(Roll - rotator.Roll)); }
/// <summary> /// Creates a rectangle from the bottom part of this rectangle. /// </summary> /// <param name="height">Height of the new rectangle (<= rectangles original height).</param> /// <returns>The new rectangle.</returns> public FIntRect Bottom(int height) { return(new FIntRect(Min.X, FMath.Max(Min.Y, Max.Y - height), Max.X, Max.Y)); }
/// <summary> /// Utility to check if there are any non-finite values (NaN or Inf) in this Rotator. /// </summary> /// <returns>true if there are any non-finite values in this Rotator, otherwise false.</returns> public bool ContainsNaN() { return(!FMath.IsFinite(Pitch) || !FMath.IsFinite(Yaw) || !FMath.IsFinite(Roll)); }
/// <summary> /// Test whether the spheres from two BoxSphereBounds intersect/overlap. /// </summary> /// <param name="a">First BoxSphereBounds to test.</param> /// <param name="b">Second BoxSphereBounds to test.</param> /// <param name="tolerance">Error tolerance added to test distance.</param> /// <returns>true if spheres intersect, false otherwise.</returns> public static bool SpheresIntersect(FBoxSphereBounds a, FBoxSphereBounds b, float tolerance = FMath.KindaSmallNumber) { return((a.Origin - b.Origin).SizeSquared() <= FMath.Square(FMath.Max(0.0f, a.SphereRadius + b.SphereRadius + tolerance))); }
/// <summary> /// Compresses a floating point angle into a byte. /// </summary> /// <param name="angle">The angle to compress.</param> /// <returns>The angle as a byte.</returns> public static byte CompressAxisToByte(float angle) { // map [0->360) to [0->256) and mask off any winding return((byte)(FMath.RoundToInt(angle * 256.0f / 360.0f) & 0xFF)); }
public void GenerateNewSeed() { Initialize(FMath.Rand()); }
/// <summary> /// Compress a floating point angle into a word. /// </summary> /// <param name="angle">The angle to compress.</param> /// <returns>The decompressed angle.</returns> public static ushort CompressAxisToShort(float angle) { // map [0->360) to [0->65536) and mask off any winding return((ushort)(FMath.RoundToInt(angle * 65536.0f / 360.0f) & 0xFFFF)); }
/// <summary> /// Returns a random unit vector, uniformly distributed, within the specified cone. /// </summary> /// <param name="dir">The center direction of the cone</param> /// <param name="horizontalConeHalfAngleRad">Horizontal half-angle of cone, in radians.</param> /// <param name="verticalConeHalfAngleRad">Vertical half-angle of cone, in radians.</param> /// <returns>Normalized vector within the specified cone.</returns> public FVector VRandCone(FVector dir, float horizontalConeHalfAngleRad, float verticalConeHalfAngleRad) { if ((verticalConeHalfAngleRad > 0.0f) && (horizontalConeHalfAngleRad > 0.0f)) { float randU = FRand(); float randV = FRand(); // Get spherical coords that have an even distribution over the unit sphere // Method described at http://mathworld.wolfram.com/SpherePointPicking.html float theta = 2.0f * FMath.PI * randU; float phi = FMath.Acos((2.0f * randV) - 1.0f); // restrict phi to [0, ConeHalfAngleRad] // where ConeHalfAngleRad is now a function of Theta // (specifically, radius of an ellipse as a function of angle) // function is ellipse function (x/a)^2 + (y/b)^2 = 1, converted to polar coords float coneHalfAngleRad = FMath.Square(FMath.Cos(theta) / verticalConeHalfAngleRad) + FMath.Square(FMath.Sin(theta) / horizontalConeHalfAngleRad); coneHalfAngleRad = FMath.Sqrt(1.0f / coneHalfAngleRad); // clamp to make a cone instead of a sphere phi = FMath.Fmod(phi, coneHalfAngleRad); // get axes we need to rotate around FMatrix dirMat = FMatrix.CreateRotation(dir.Rotation()); // note the axis translation, since we want the variation to be around X FVector dirZ = dirMat.GetUnitAxis(EAxis.X); FVector dirY = dirMat.GetUnitAxis(EAxis.Y); FVector result = dir.RotateAngleAxis(phi * 180.0f / FMath.PI, dirY); result = result.RotateAngleAxis(theta * 180.0f / FMath.PI, dirZ); // ensure it's a unit vector (might not have been passed in that way) result = result.GetSafeNormal(); return(result); } else { return(dir.GetSafeNormal()); } }
/// <summary> /// Get the component-wise max of two points. /// </summary> /// <see cref="ComponentMax"/> /// <see cref="GetMax"/> public FIntPoint ComponentMax(FIntPoint other) { return(new FIntPoint(FMath.Max(X, other.X), FMath.Max(Y, other.Y))); }