mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: moved to astro
This commit is contained in:
1 parent
292df5f5d9
commit
a1721eb05e
150 files changed
+386
-363
No files matched your search
@@ -0,0 +1,80 @@
|
||||
import { normalizeAngleRad, PitchLimits, YawLimits } from '@blitzkit/core';
|
||||
import { clamp } from 'lodash';
|
||||
import { degToRad } from 'three/src/math/MathUtils';
|
||||
|
||||
export function applyPitchYawLimits(
|
||||
pitch: number, // rad
|
||||
yaw: number, // rad
|
||||
pitchLimits: PitchLimits, // deg
|
||||
yawLimits?: YawLimits, // deg
|
||||
verticalStabilizer = false,
|
||||
) {
|
||||
let newPitch = pitch;
|
||||
let newYaw = yaw;
|
||||
|
||||
if (yawLimits) {
|
||||
newYaw = normalizeAngleRad(
|
||||
clamp(newYaw, -degToRad(yawLimits.max), -degToRad(yawLimits.min)),
|
||||
);
|
||||
}
|
||||
|
||||
const depressionBuff = verticalStabilizer ? degToRad(3) : 0;
|
||||
const elevationBuff = verticalStabilizer ? degToRad(4) : 0;
|
||||
let lowerPitch = -degToRad(pitchLimits.max) - depressionBuff;
|
||||
let upperPitch = -degToRad(pitchLimits.min) + elevationBuff;
|
||||
const transition = degToRad(pitchLimits.transition ?? 10);
|
||||
|
||||
if (pitchLimits.back) {
|
||||
const range = degToRad(pitchLimits.back.range);
|
||||
const yawRotatedAbs = Math.abs(normalizeAngleRad(newYaw - Math.PI));
|
||||
|
||||
if (yawRotatedAbs <= range + transition) {
|
||||
if (yawRotatedAbs <= range) {
|
||||
// inside range
|
||||
lowerPitch = -degToRad(pitchLimits.back.max);
|
||||
upperPitch = -degToRad(pitchLimits.back.min);
|
||||
} else {
|
||||
// inside transition
|
||||
const transitionProgress = (yawRotatedAbs - range) / transition;
|
||||
const maxInterpolatedPitch =
|
||||
(1 - transitionProgress) * pitchLimits.back.max +
|
||||
transitionProgress * pitchLimits.max;
|
||||
const minInterpolatedPitch =
|
||||
(1 - transitionProgress) * pitchLimits.back.min +
|
||||
transitionProgress * pitchLimits.min;
|
||||
|
||||
lowerPitch = -degToRad(maxInterpolatedPitch);
|
||||
upperPitch = -degToRad(minInterpolatedPitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pitchLimits.front) {
|
||||
const range = degToRad(pitchLimits.front.range);
|
||||
const yawAbs = Math.abs(normalizeAngleRad(newYaw));
|
||||
|
||||
if (yawAbs <= range + transition) {
|
||||
if (yawAbs <= range) {
|
||||
// inside range
|
||||
lowerPitch = -degToRad(pitchLimits.front.max);
|
||||
upperPitch = -degToRad(pitchLimits.front.min);
|
||||
} else {
|
||||
// inside transition
|
||||
const transitionProgress = (yawAbs - range) / transition;
|
||||
const maxInterpolatedPitch =
|
||||
(1 - transitionProgress) * pitchLimits.front.max +
|
||||
transitionProgress * pitchLimits.max;
|
||||
const minInterpolatedPitch =
|
||||
(1 - transitionProgress) * pitchLimits.front.min +
|
||||
transitionProgress * pitchLimits.min;
|
||||
|
||||
lowerPitch = -degToRad(maxInterpolatedPitch);
|
||||
upperPitch = -degToRad(minInterpolatedPitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newPitch = clamp(newPitch, lowerPitch, upperPitch);
|
||||
|
||||
return [newPitch, newYaw];
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Vector3, Vector3Tuple } from 'three';
|
||||
import { rotateDavaVector } from './rotateDavaVector';
|
||||
|
||||
export function correctZYTuple(tuple: Vector3Tuple) {
|
||||
return rotateDavaVector(new Vector3(tuple[0], tuple[1], -tuple[2]));
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { I_HAT } from '@blitzkit/core';
|
||||
import { Vector3 } from 'three';
|
||||
|
||||
export function rotateDavaVector(vector: Vector3) {
|
||||
return vector.applyAxisAngle(I_HAT, Math.PI / 2);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { I_HAT } from '@blitzkit/core';
|
||||
import { Vector3 } from 'three';
|
||||
|
||||
export function unrotateDavaVector(vector: Vector3) {
|
||||
return vector.applyAxisAngle(I_HAT, -Math.PI / 2);
|
||||
}
|
||||
Reference in new issue
Block a user