A modded EditSaber for making beat saber maps.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

265 lines
12 KiB

  1. /*
  2. By TK-Master
  3. */
  4. #pragma once
  5. //For the Anchor Conversion
  6. #include "Runtime/UMG/Public/UMG.h"
  7. #include "TKMathFunctionLibrary.generated.h"
  8. /* Speed Units Enum. */
  9. UENUM()
  10. enum ESpeedUnit
  11. {
  12. /* Centimeter / second (cm/s). This is default unreal velocity unit. */
  13. CentimeterPerSecond,
  14. /* Foot / second (ft/s). */
  15. FootPerSecond,
  16. /* Meter / second (m/s). */
  17. MeterPerSecond,
  18. /* Meter / minute (m/min). */
  19. MeterPerMinute,
  20. /* Kilometer / second (km/s). */
  21. KilometerPerSecond,
  22. /* Kilometer / minute (km/min). */
  23. KilometerPerMinute,
  24. /*Kilometer / hour (km/h). */
  25. KilometerPerHour,
  26. /* Mile / hour (mph). */
  27. MilePerHour,
  28. /* Knot (kn). Nautical mile per hour. */
  29. Knot,
  30. /* Mach (speed of sound) (M) at standard atm. */
  31. Mach,
  32. /* Speed of light. */
  33. SpeedOfLight,
  34. /* Yard / second. */
  35. YardPerSecond
  36. };
  37. UCLASS()
  38. class VICTORYBPLIBRARY_API UTKMathFunctionLibrary : public UBlueprintFunctionLibrary
  39. {
  40. GENERATED_BODY()
  41. public:
  42. UFUNCTION(BlueprintPure, Category = "Victory BP Library|Console")
  43. static float GetConsoleVariableFloat(FString VariableName);
  44. UFUNCTION(BlueprintPure, Category = "Victory BP Library|Console")
  45. static int32 GetConsoleVariableInt(FString VariableName);
  46. //Reverses the sign (- or +) of a float.
  47. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Float")
  48. static float NegateFloat(float A);
  49. //Reverses the sign (- or +) of an integer.
  50. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Integer")
  51. static int32 NegateInt(int32 A);
  52. //Reverses the sign (- or +) of a Vector2D.
  53. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector2D")
  54. static FVector2D NegateVector2D(FVector2D A);
  55. //Changes the size (length) of a Vector to the given size (normalized vector * size).
  56. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  57. static FVector SetVectorLength(FVector A, float size);
  58. //Converts radians to degrees.
  59. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  60. static FVector VectorRadiansToDegrees(FVector RadVector);
  61. //Converts degrees to radians.
  62. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  63. static FVector VectorDegreesToRadians(FVector DegVector);
  64. /**
  65. * Rounds an integer to the lower multiple of the given number.
  66. * If Skip Self is set to True it will skip to the previous multiple if the integer rounds to itself.
  67. * @param Multiple - The multiple number to round to.
  68. * @param skipSelf - Skip to the previous multiple if the integer rounds to itself.
  69. */
  70. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Integer")
  71. static int32 RoundToLowerMultiple(int32 A, int32 Multiple = 32, bool skipSelf = false);
  72. /**
  73. * Rounds an integer to the upper multiple of the given number.
  74. * If Skip Self is set to True it will skip to the next multiple if the integer rounds to itself.
  75. * @param Multiple - The multiple number to round to.
  76. * @param skipSelf - Skip to the next multiple if the integer rounds to itself.
  77. */
  78. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Integer")
  79. static int32 RoundToUpperMultiple(int32 A, int32 Multiple = 32, bool skipSelf = false);
  80. /** Rounds an integer to the nearest multiple of the given number. */
  81. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Integer")
  82. static int32 RoundToNearestMultiple(int32 A, int32 Multiple = 32);
  83. /** Returns true if the integer is a power of two number. */
  84. UFUNCTION(BlueprintPure, meta = (CompactNodeTitle = "PwrOf2"), Category = "Victory BP Library|TK-Master Math|Integer")
  85. static bool IsPowerOfTwo(int32 x);
  86. /** Returns true if the integer is a multiple of the given number. */
  87. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Integer")
  88. static bool IsMultipleOf(int32 A, int32 Multiple);
  89. /** Returns true if the number is even (false if it's odd). */
  90. UFUNCTION(BlueprintPure, meta = (CompactNodeTitle = "isEven"), Category = "Victory BP Library|TK-Master Math|Float")
  91. static bool IsEvenNumber(float A);
  92. /**
  93. * Find closest point on a Sphere to a Line.
  94. * When line intersects Sphere, then closest point to LineOrigin is returned.
  95. * @param SphereOrigin Origin of Sphere
  96. * @param SphereRadius Radius of Sphere
  97. * @param LineOrigin Origin of line
  98. * @param LineDir Direction of line.
  99. * @return Closest point on sphere to given line.
  100. */
  101. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  102. static FVector ClosestPointOnSphereToLine(FVector SphereOrigin, float SphereRadius, FVector LineOrigin, FVector LineDir);
  103. /** Find the point on line segment from LineStart to LineEnd which is closest to Point. */
  104. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  105. static FVector ClosestPointOnLineSeqment(FVector Point, FVector LineStart, FVector LineEnd);
  106. /** Returns true if the given Point vector is within a box (defined by BoxOrigin and BoxExtent). */
  107. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector|Intersection")
  108. static bool IsPointInsideBox(FVector Point, FVector BoxOrigin, FVector BoxExtent);
  109. /** Determines whether a line intersects a sphere. */
  110. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector|Intersection")
  111. static bool IsLineInsideSphere(FVector LineStart, FVector LineDir, float LineLength, FVector SphereOrigin, float SphereRadius);
  112. /**
  113. * Swept-Box vs Box test.
  114. * Sweps a box defined by Extend from Start to End points and returns whether it hit a box or not plus the hit location and hit normal if successful.
  115. */
  116. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector|Intersection")
  117. static bool LineExtentBoxIntersection(FBox inBox, FVector Start, FVector End, FVector Extent, FVector& HitLocation, FVector& HitNormal, float& HitTime);
  118. /**
  119. * Get the shortest distance between a point and a plane.
  120. * The output is signed so it holds information as to which side of the plane normal the point is.
  121. */
  122. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  123. static float SignedDistancePlanePoint(FVector planeNormal, FVector planePoint, FVector point);
  124. /**
  125. * Returns a vector point which is a projection from a point to a line (defined by the vector couple LineOrigin, LineDirection).
  126. * The line is infinite (in both directions).
  127. */
  128. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  129. static FVector ProjectPointOnLine(FVector LineOrigin, FVector LineDirection, FVector Point);
  130. /**
  131. * Performs a sphere vs box intersection test.
  132. * @param SphereOrigin the center of the sphere being tested against the box.
  133. * @param SphereRadius the size of the sphere being tested.
  134. * @param BoxOrigin the box origin being tested against.
  135. * @param BoxExtent the box extend (width, depth, height).
  136. * @return Whether the sphere/box intersect or not.
  137. */
  138. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector|Intersection")
  139. static bool SphereBoxIntersection(FVector SphereOrigin, float SphereRadius, FVector BoxOrigin, FVector BoxExtent);
  140. /**
  141. * Find closest points between 2 line segments.
  142. * @param (Line1Start, Line1End) defines the first line segment.
  143. * @param (Line2Start, Line2End) defines the second line segment.
  144. * @param LinePoint1 Closest point on segment 1 to segment 2.
  145. * @param LinePoint2 Closest point on segment 2 to segment 1.
  146. */
  147. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector|Intersection")
  148. static void ClosestPointsOfLineSegments(FVector Line1Start, FVector Line1End, FVector Line2Start, FVector Line2End, FVector& LinePoint1, FVector& LinePoint2);
  149. /**
  150. * Calculate the intersection point of two infinitely long lines. Returns true if lines intersect, otherwise false.
  151. * Note that in 3d, two lines do not intersect most of the time.
  152. * So if the two lines are not in the same plane, use Closest Points On Two Lines instead.
  153. * @param IntersectionPoint The intersection point of the lines. Returns zero if the lines do not intersect or the operation fails.
  154. * @param LinePoint1 Line point of the first line.
  155. * @param LineDir1 Line direction (normal) of the first line. Should be a normalized vector.
  156. * @param LinePoint2 Line point of the second line.
  157. * @param LineDir2 Line direction (normal) of the second line. Should be a normalized vector.
  158. * @return true if lines intersect, otherwise false.
  159. */
  160. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector|Intersection")
  161. static bool LineToLineIntersection(FVector& IntersectionPoint, FVector LinePoint1, FVector LineDir1, FVector LinePoint2, FVector LineDir2);
  162. /*
  163. * Calculate the closest points between two infinitely long lines.
  164. * If lines are intersecting (not parallel) it will return false! Use Line To Line Intersection instead.
  165. * @param closestPointLine1 The closest point of line1 to line2. Returns zero if the lines intersect.
  166. * @param closestPointLine2 The closest point of line2 to line1. Returns zero if the lines intersect.
  167. * @param linePoint1 Line point of the first line.
  168. * @param lineVec1 Line direction (normal) of the first line. Should be a normalized vector.
  169. * @param linePoint2 Line point of the second line.
  170. * @param lineVec2 Line direction (normal) of the second line. Should be a normalized vector.
  171. * @return true if lines are parallel, false otherwise.
  172. */
  173. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  174. static bool ClosestPointsOnTwoLines(FVector& closestPointLine1, FVector& closestPointLine2, FVector linePoint1, FVector lineVec1, FVector linePoint2, FVector lineVec2);
  175. /*
  176. * Returns 0 if point is on the line segment.
  177. * Returns 1 if point is not on the line segment and it is on the side of linePoint1.
  178. * Returns 2 if point is not on the line segment and it is on the side of linePoint2.
  179. */
  180. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  181. static int32 PointOnWhichSideOfLineSegment(FVector linePoint1, FVector linePoint2, FVector point);
  182. /*
  183. * Returns true if the two line segments are intersecting and not parallel.
  184. * If you need the intersection point, use Closest Points On Two Lines.
  185. */
  186. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector|Intersection")
  187. static bool AreLineSegmentsCrossing(FVector pointA1, FVector pointA2, FVector pointB1, FVector pointB2);
  188. /*Snaps vector to nearest grid multiple.*/
  189. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  190. static FVector GridSnap(FVector A, float Grid);
  191. /*Converts UMG layout offsets to another anchor.*/
  192. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Anchor", meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
  193. static void ConvertAnchorToAnchor(UObject* WorldContextObject, FAnchors CurrentAnchor, FMargin Offsets, FAnchors TargetAnchor, FMargin& ConvertedOffsets);
  194. /*Converts Physics Linear Velocity to a more useful speed unit.*/
  195. UFUNCTION(BlueprintPure, Category = "Victory BP Library|TK-Master Math|Vector")
  196. static float ConvertPhysicsLinearVelocity(FVector Velocity, TEnumAsByte<enum ESpeedUnit> SpeedUnit);
  197. //------------------------------------------------------------
  198. //Physics functions! (why aren't these exposed by Epic yet?!)
  199. /**
  200. * Get the current world velocity of a point on a physics-enabled component.
  201. * @param Point - Point in world space.
  202. * @param DrawDebugInfo - Draw debug point & string.
  203. * @param BoneName - If a SkeletalMeshComponent, name of body to get velocity of. 'None' indicates root body.
  204. * @return The velocity of the point in world space.
  205. */
  206. UFUNCTION(BlueprintCallable, Category = "Physics")
  207. static FVector GetVelocityAtPoint(UPrimitiveComponent* Target, FVector Point, FName BoneName = NAME_None, bool DrawDebugInfo = false);
  208. /*
  209. * Set the physx center of mass offset.
  210. * Note: this offsets the physx-calculated center of mass (it is not an offset from the pivot point).
  211. */
  212. UFUNCTION(BlueprintCallable, Category = "Physics")
  213. static void SetCenterOfMassOffset(UPrimitiveComponent* Target, FVector Offset, FName BoneName = NAME_None);
  214. };