19 lines
801 B
TypeScript
19 lines
801 B
TypeScript
/**
|
|
* Game world to three.js: Dagor is left-handed with Y up, three.js right-handed, so world z is
|
|
* mirrored (three z = -world z). A world heading (degrees of atan2(z, x)) then becomes the same
|
|
* angle of rotation about three's +Y, and a model's local +X is its front, +Y up, -Z its left.
|
|
*/
|
|
import { Vector3 } from 'three';
|
|
|
|
export const DEG = Math.PI / 180;
|
|
|
|
export function toThree(x: number, y: number, z: number, out: Vector3 = new Vector3()): Vector3 {
|
|
return out.set(x, y, -z);
|
|
}
|
|
|
|
/** Three.js direction of a world heading and pitch, in degrees. */
|
|
export function dirOf(yawDeg: number, pitchDeg: number, out: Vector3 = new Vector3()): Vector3 {
|
|
const c = Math.cos(pitchDeg * DEG);
|
|
return out.set(Math.cos(yawDeg * DEG) * c, Math.sin(pitchDeg * DEG), -Math.sin(yawDeg * DEG) * c);
|
|
}
|