37 lines
978 B
JavaScript
37 lines
978 B
JavaScript
export const ORBIT_VIEW_DIRECTIONS = Object.freeze([
|
|
"iso",
|
|
"+x",
|
|
"-x",
|
|
"+y",
|
|
"-y",
|
|
"+z",
|
|
"-z",
|
|
]);
|
|
|
|
const ORBITS = Object.freeze({
|
|
iso: Object.freeze({
|
|
yaw: -Math.PI / 4,
|
|
pitch: Math.asin(1 / Math.sqrt(3)),
|
|
}),
|
|
"+x": Object.freeze({ yaw: -Math.PI / 2, pitch: 0 }),
|
|
"-x": Object.freeze({ yaw: Math.PI / 2, pitch: 0 }),
|
|
"+y": Object.freeze({ yaw: Math.PI, pitch: 0 }),
|
|
"-y": Object.freeze({ yaw: 0, pitch: 0 }),
|
|
"+z": Object.freeze({ yaw: 0, pitch: Math.PI / 2 }),
|
|
"-z": Object.freeze({ yaw: Math.PI, pitch: -Math.PI / 2 }),
|
|
});
|
|
|
|
/**
|
|
* Return the orthographic camera orbit for a view from the named axis toward
|
|
* the array origin. A fresh object prevents one view from mutating another.
|
|
*/
|
|
export function orbitForViewDirection(direction = "iso") {
|
|
const orbit = ORBITS[direction];
|
|
if (!orbit) {
|
|
throw new RangeError(
|
|
"view direction must be one of: " + ORBIT_VIEW_DIRECTIONS.join(", "),
|
|
);
|
|
}
|
|
return { ...orbit };
|
|
}
|