Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import { mat4, vec3 } from 'gl-matrix';
import type { Point3 } from '../../../types';
export function normalizePlanarRotation(rotation = 0): number {
return ((rotation % 360) + 360) % 360;
}
export function rotatePlanarViewUp(args: {
rotation?: number;
viewPlaneNormal: Point3;
viewUp: Point3;
}): Point3 {
const { rotation = 0, viewPlaneNormal, viewUp } = args;
const normalizedRotation = normalizePlanarRotation(rotation);
if (normalizedRotation === 0) {
return [...viewUp] as Point3;
}
const rotationMatrix = mat4.fromRotation(
mat4.create(),
(normalizedRotation * Math.PI) / 180,
viewPlaneNormal as unknown as vec3
);
return vec3.transformMat4(
vec3.create(),
viewUp as unknown as vec3,
rotationMatrix
) as Point3;
}
export function applyPlanarViewFlip(args: {
flipHorizontal?: boolean;
flipVertical?: boolean;
viewPlaneNormal: Point3;
viewUp: Point3;
}): {
viewPlaneNormal: Point3;
viewUp: Point3;
} {
const { flipHorizontal, flipVertical, viewPlaneNormal, viewUp } = args;
const shouldFlipNormal = Boolean(flipHorizontal) !== Boolean(flipVertical);
return {
viewPlaneNormal: shouldFlipNormal
? (vec3.negate(
vec3.create(),
viewPlaneNormal as unknown as vec3
) as Point3)
: ([...viewPlaneNormal] as Point3),
viewUp: flipVertical
? (vec3.negate(vec3.create(), viewUp as unknown as vec3) as Point3)
: ([...viewUp] as Point3),
};
}
|