tengri/Content/Camera/Tests/FT_CameraLimits.ts

141 lines
5.9 KiB
TypeScript

// Camera/Tests/FT_CameraLimits.ts
import { AC_Camera } from '#root/Camera/Components/AC_Camera.ts';
import { AC_DebugHUD } from '#root/Debug/Components/AC_DebugHUD.ts';
import { AC_InputDevice } from '#root/Input/Components/AC_InputDevice.ts';
import { AC_ToastSystem } from '#root/Toasts/Components/AC_ToastSystem.ts';
import { EFunctionalTestResult } from '#root/UE/EFunctionalTestResult.ts';
import { FunctionalTest } from '#root/UE/FunctionalTest.ts';
import { MathLibrary } from '#root/UE/MathLibrary.ts';
import { Vector } from '#root/UE/Vector.ts';
/**
* Functional Test: Camera Limits and Constraints
* Tests pitch limits (-89°/+89°) and free yaw rotation
* Validates clamping behavior and overflow handling
*/
export class FT_CameraLimits extends FunctionalTest {
// ════════════════════════════════════════════════════════════════════════════════════════
// GRAPHS
// ════════════════════════════════════════════════════════════════════════════════════════
// ────────────────────────────────────────────────────────────────────────────────────────
// EventGraph
// ────────────────────────────────────────────────────────────────────────────────────────
/**
* Test execution - validates pitch/yaw limits
* Tests boundary conditions and clamping behavior
*/
EventStartTest(): void {
// Initialize system
this.ToastSystemComponent.InitializeToastSystem();
this.InputDeviceComponent.InitializeDeviceDetection(
this.ToastSystemComponent,
this.DebugHUDComponent
);
this.CameraComponent.InitializeCameraSystem(
this.InputDeviceComponent,
this.DebugHUDComponent
);
// Test 1: Test upper pitch limit clamping
const { PitchMin: pitchMin, PitchMax: pitchMax } =
this.CameraComponent.CameraSettings;
for (let i = 0; i < 100; i++) {
this.CameraComponent.ProcessLookInput(new Vector(0.0, -10.0, 0.0), 0.016);
this.CameraComponent.UpdateCameraRotation(0.016);
}
const rotation1Pitch = this.CameraComponent.GetCameraRotation().Pitch;
if (rotation1Pitch <= pitchMax + 0.1) {
// Test 2: Test lower pitch limit clamping
for (let i = 0; i < 200; i++) {
this.CameraComponent.ProcessLookInput(
new Vector(0.0, 10.0, 0.0),
0.016
);
this.CameraComponent.UpdateCameraRotation(0.016);
}
const rotation2Pitch = this.CameraComponent.GetCameraRotation().Pitch;
if (rotation2Pitch >= pitchMin - 0.1) {
// Test 3: Test free yaw rotation (no limits)
for (let i = 0; i < 100; i++) {
this.CameraComponent.ProcessLookInput(
new Vector(5.0, 0.0, 0.0),
0.016
);
this.CameraComponent.UpdateCameraRotation(0.016);
}
const rotation3Yaw = this.CameraComponent.GetCameraRotation().Yaw;
if (MathLibrary.abs(rotation3Yaw) >= 360.0) {
// Test 4: Test yaw can go negative
for (let i = 0; i < 200; i++) {
this.CameraComponent.ProcessLookInput(
new Vector(-5.0, 0.0, 0.0),
0.016
);
this.CameraComponent.UpdateCameraRotation(0.016);
}
const rotation4Yaw = this.CameraComponent.GetCameraRotation().Yaw;
if (rotation4Yaw <= -360.0) {
this.FinishTest(EFunctionalTestResult.Succeeded);
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Yaw should allow negative rotation beyond -360°, got ${rotation4Yaw}°`
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Yaw should allow free rotation beyond 360°, got ${rotation3Yaw}°`
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Pitch ${rotation2Pitch}° below minimum limit ${pitchMin}°`
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Pitch ${rotation1Pitch}° exceeds maximum limit ${pitchMax}°`
);
}
}
// ════════════════════════════════════════════════════════════════════════════════════════
// VARIABLES
// ════════════════════════════════════════════════════════════════════════════════════════
/**
* Camera system component - component under test
* @category Components
*/
private CameraComponent = new AC_Camera();
/**
* Input device detection system - required for camera initialization
* @category Components
*/
private InputDeviceComponent = new AC_InputDevice();
/**
* Toast notification system - required for input device initialization
* @category Components
*/
private ToastSystemComponent = new AC_ToastSystem();
/**
* Debug HUD system - displays test status and parameters
* @category Components
*/
private DebugHUDComponent = new AC_DebugHUD();
}