public static fint Atan2(fint F1, fint F2) { if (F2.raw == 0 && F1.raw == 0) { return(fint.zero); } fint result = fint.zero; if (F2 > fint.zero) { result = Atan(F1 / F2); } else if (F2 < fint.zero) { if (F1 >= fint.zero) { result = (PI - Atan(Abs(F1 / F2))); } else { result = -(PI - Atan(Abs(F1 / F2))); } } else { result = (F1 >= fint.zero ? PI : -PI) / fint.CreateFromInt(2); } return(result); }
public static FVector2 ClampMagnitude(FVector2 vector, fint maxLength) { if (vector.sqrMagnitude > maxLength * maxLength) { return(vector.normalized * maxLength); } return(vector); }
public static FVector3 Project(FVector3 vector, FVector3 onNormal) { fint num = FVector3.Dot(onNormal, onNormal); if (num.raw < 1) { return(FVector3.zero); } return(onNormal * FVector3.Dot(vector, onNormal) / num); }
public static FVector2 Normalize(FVector2 value) { fint magnitude = FVector2.Magnitude(value); if (magnitude.raw > 1) { return(value / magnitude); } return(FVector3.zero); }
/// <summary> /// Create a fixed-int number from parts. For example, to create 1.5 pass in 1 and 500. /// </summary> /// <param name="PreDecimal">The number above the decimal. For 1.5, this would be 1.</param> /// <param name="PostDecimal">The number below the decimal, to three digits. /// For 1.5, this would be 500. For 1.005, this would be 5.</param> /// <returns>A fixed-int representation of the number parts</returns> public static fint FromParts(int PreDecimal, int PostDecimal) { fint f = fint.CreateFromInt(PreDecimal); if (PostDecimal != 0) { f += (fint.CreateFromInt(PostDecimal) / fint.CreateFromInt(1000)); } return(f); }
public static fint Abs(fint F) { if (F.raw < 0) { return(-F); } else { return(F); } }
public static FVector2 MoveTowards(FVector2 current, FVector2 target, fint maxDistanceDelta) { FVector2 a = target - current; fint magnitude = a.magnitude; if (magnitude <= maxDistanceDelta || magnitude == fint.zero) { return(target); } return(current + a / magnitude * maxDistanceDelta); }
public static fint Clamp01(fint value) { if (value < fint.zero) { return(fint.zero); } if (value > fint.one) { return(fint.one); } return(value); }
private static fint sin_lookup(fint i, fint j) { if (j.raw > 0 && j < fint.CreateRaw(10) && i < fint.CreateRaw(90)) { return(fint.CreateRaw(SIN_TABLE[i.raw]) + ((fint.CreateRaw(SIN_TABLE[i.raw + 1]) - fint.CreateRaw(SIN_TABLE[i.raw])) / fint.CreateRaw(10)) * j); } else { return(fint.CreateRaw(SIN_TABLE[i.raw])); } }
public void Normalize() { fint magnitude = this.magnitude; if (magnitude.raw > 1) { this /= magnitude; } else { this = FVector2.Zero; } }
public void Normalize() { fint num = FVector3.Magnitude(this); if (num.raw > 1) { this /= num; } else { this = FVector3.zero; } }
public static fint Clamp(fint value, fint min, fint max) { if (value < min) { value = min; } else { if (value > max) { value = max; } } return(value); }
public static fint Sqrt(fint f) { if (f.raw > 0x3e8000) { return(Sqrt(f, 16 * 3 / 4)); } else if (f.raw > 0x64000) { return(Sqrt(f, 12 * 2 / 3)); } else { return(Sqrt(f, 8 * 2 / 3)); } }
public static fint Sqrt(fint f, int NumberOfIterations) { if (f.raw < 0) //NaN in Math.Sqrt { throw new ArithmeticException("Input Error"); } if (f.raw == 0) { return(fint.zero); } #if USE_OPTIMIZATIONS long fraw = f.raw; long frawshift = (fraw << fint.SHIFT_AMOUNT); long k = fraw + fint.one.raw >> 1; for (int i = 0; i < NumberOfIterations; i++) { k = (k + (frawshift / k)) >> 1; } if (k < 0) { throw new ArithmeticException("Overflow"); } return(fint.CreateRaw((int)k)); #else fint k = f + fint.one >> 1; for (int i = 0; i < NumberOfIterations; i++) { k = (k + (f / k)) >> 1; } if (k.raw < 0) { throw new ArithmeticException("Overflow"); } return(k); #endif }
public static fint Min(params fint[] values) { int num = values.Length; if (num == 0) { return(fint.zero); } fint num2 = values[0]; for (int i = 1; i < num; i++) { if (values[i] < num2) { num2 = values[i]; } } return(num2); }
public static fint Asin(fint F) { bool isNegative = F.raw < 0; F = Abs(F); if (F > fint.one) { throw new ArithmeticException("Bad Asin Input:" + F.ToFloat()); } fint f1 = mul(mul(mul(mul( fint.CreateRaw(145103 >> fint.SHIFT_AMOUNT), F) - fint.CreateRaw(599880 >> fint.SHIFT_AMOUNT), F) + fint.CreateRaw(1420468 >> fint.SHIFT_AMOUNT), F) - fint.CreateRaw(3592413 >> fint.SHIFT_AMOUNT), F) + fint.CreateRaw(26353447 >> fint.SHIFT_AMOUNT); fint f2 = HalfPI - (Sqrt(fint.one - F) * f1); return(isNegative ? -f2 : f2); }
public static fint Sin(fint i) { fint j = fint.zero; for ( ; i.raw < 0; i += fint.CreateRaw(25736)) { ; } if (i > fint.CreateRaw(25736)) { i %= fint.CreateRaw(25736); } fint k = (i * fint.CreateRaw(10)) / fint.CreateRaw(714); if (i.raw != 0 && i != fint.CreateRaw(6434) && i != fint.CreateRaw(12868) && i != fint.CreateRaw(19302) && i != fint.CreateRaw(25736)) { j = (i * fint.CreateRaw(100)) / fint.CreateRaw(714) - k * fint.CreateRaw(10); } if (k <= fint.CreateRaw(90)) { return(sin_lookup(k, j)); } if (k <= fint.CreateRaw(180)) { return(sin_lookup(fint.CreateRaw(180) - k, j)); } if (k <= fint.CreateRaw(270)) { return(-sin_lookup(k - fint.CreateRaw(180), j)); } else { return(-sin_lookup(fint.CreateRaw(360) - k, j)); } }
public void Set(fint new_x, fint new_y) { this.X = new_x; this.Y = new_y; }
public void Scale(FVector2 scale) { this.X *= scale.X; this.Y *= scale.Y; }
public void Set(fint new_x, fint new_y, fint new_z) { this.x = new_x; this.y = new_y; this.z = new_z; }
// // Constructors // public FVector2(fint x, fint y) { this.X = x; this.Y = y; }
private static fint mul(fint F1, fint F2) { return(F1 * F2); }
public static fint Cos(fint i) { return(Sin(i + fint.CreateRaw(6435))); }
public static fint Min(fint a, fint b) { return((a >= b) ? b : a); }
public static fint Max(fint a, fint b) { return((a <= b) ? b : a); }
public static fint Tan(fint i) { return(Sin(i) / Cos(i)); }
public static fint Acos(fint F) { return(HalfPI - Asin(F)); }
public void Scale(FVector3 scale) { this.x *= scale.x; this.y *= scale.y; this.z *= scale.z; }
public static FVector2 Lerp(FVector2 from, FVector2 to, fint t) { t = FMath.Clamp01(t); return(new FVector2(from.X + (to.X - from.X) * t, from.Y + (to.Y - from.Y) * t)); }
public static fint Atan(fint F) { return(Asin(F / Sqrt(fint.one + (F * F)))); }