95 lines
2.9 KiB
TypeScript
95 lines
2.9 KiB
TypeScript
// UE/SystemLibrary.ts
|
|
|
|
import { BlueprintFunctionLibrary } from '#root/UE/BlueprintFunctionLibrary.ts';
|
|
import type { Color } from '#root/UE/Color.ts';
|
|
import type { Float } from '#root/UE/Float.ts';
|
|
import { LinearColor } from '#root/UE/LinearColor.ts';
|
|
import type { Vector } from '#root/UE/Vector.ts';
|
|
|
|
/**
|
|
* System Library: Core Mathematical Functions
|
|
* Wrapper for JavaScript Math functions with UE5 compatibility
|
|
* Provides deterministic mathematical operations for movement calculations
|
|
*/
|
|
class MathLibraryClass extends BlueprintFunctionLibrary {
|
|
constructor(
|
|
outer: null | BlueprintFunctionLibrary = null,
|
|
name: string = 'MathLibrary'
|
|
) {
|
|
super(outer, name);
|
|
}
|
|
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
// FUNCTIONS
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
|
|
/**
|
|
* Convert degrees to radians
|
|
* @param Degrees - Angle in degrees
|
|
* @returns Angle in radians
|
|
* @example
|
|
* // Convert 90 degrees to radians
|
|
* DegreesToRadians(90) // returns π/2
|
|
*/
|
|
public DegreesToRadians(Degrees: Float): Float {
|
|
return (Degrees * Math.PI) / 180;
|
|
}
|
|
|
|
/**
|
|
* Calculate sine of angle in radians
|
|
* @param Value - Angle in radians
|
|
* @returns Sine value (-1 to 1)
|
|
*/
|
|
public Sin(Value: Float): Float {
|
|
return Math.sin(Value);
|
|
}
|
|
|
|
/**
|
|
* Calculate cosine of angle in radians
|
|
* @param Value - Angle in radians
|
|
* @returns Cosine value (-1 to 1)
|
|
*/
|
|
public Cos(Value: Float): Float {
|
|
return Math.cos(Value);
|
|
}
|
|
|
|
/**
|
|
* Calculate arccosine (inverse cosine) of value
|
|
* @param Value - Input value (-1 to 1)
|
|
* @returns Angle in radians (0 to π)
|
|
*/
|
|
public Acos(Value: Float): Float {
|
|
return Math.acos(Value);
|
|
}
|
|
|
|
/**
|
|
* Calculate dot product of two vectors
|
|
* @param Vector1 - First vector
|
|
* @param Vector2 - Second vector
|
|
* @returns Dot product scalar value
|
|
* @example
|
|
* // Dot product of perpendicular vectors
|
|
* Dot(new Vector(1,0,0), new Vector(0,1,0)) // returns 0
|
|
*/
|
|
public Dot(Vector1: Vector, Vector2: Vector): Float {
|
|
return (
|
|
Vector1.X * Vector2.X + Vector1.Y * Vector2.Y + Vector1.Z * Vector2.Z
|
|
);
|
|
}
|
|
|
|
public ColorToLinearColor(color: Color): LinearColor {
|
|
return new LinearColor(
|
|
color.R / 255,
|
|
color.G / 255,
|
|
color.B / 255,
|
|
color.A / 255
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Global instance of math library
|
|
* Used throughout the movement system for mathematical calculations
|
|
*/
|
|
export const MathLibrary = new MathLibraryClass();
|