[213] Kameras als Modell-Elemente und Begehen (WASD) im 3D
Project.cameras (Rust Camera: Standpunkt + Augenhöhe über Geschoss, Ziel, Bildwinkel, Perspektive/ Axonometrie/Parallel, Sonnenstand) auf der neuen Klasse "Kameras" (92). Grundriss-Symbol im Kern (plan/cameras.rs: Gehäuse, Sichtkegel, Ziel, Name, schmale Pick-Bänder), Griffe im Kern (camera.rs, grips.rs: Standpunkt, Ziel, Bildwinkel/Sichtbreite), Auswahl/Entf, Objekt-Info CameraSection, Liste im Panel Ausschnitte, "Kamera aus aktueller Ansicht anlegen", "Kamera öffnen" (auch per Doppelklick auf das Symbol), cameraToView() für das Rendering [211]. Begehen im 3D: Umschalt+F, W/A/S/D/Pfeile, Q/E, Umschalt/Alt, Umschauen um den Augpunkt (viewport/walk.ts). Beispiel: Kamera im Musterhaus komplex.
This commit is contained in:
64 files changed
+2031
-50
No files matched your search
@@ -11,6 +11,8 @@ kommt als Teile aus dem Kern (`src/plan/toWalls3d.ts`). Weg eines Modells in den
|
||||
| `Wasm3DViewport.tsx` | die 3D-Ansicht: Canvas, Maus und Tastatur, Auswahl, Griffe, Cursor-HUD, Live-Schnitt |
|
||||
| `Viewport3D.tsx` | Zugang zur Ansicht (`Viewport3D = Wasm3DViewport`) und die geteilten Typen (`RenderDisplay`, `DisplayResolver`) |
|
||||
| `useWasm3dRenderer.ts` | Hook: lädt render3d, hält Modell, Kamera und Punktwolken, zeichnet; Typ `Camera3d` |
|
||||
| `cameraView.ts` | [213] Kamera-Element (`Project.cameras`) ↔ Sicht des Viewports: `cameraToView`, `cameraFromView`, Brennweite, Geschoss zur Höhe |
|
||||
| `walk.ts` | [213] Begehen (WASD): Bewegung und Umschauen als reine Funktionen auf dem Orbit-Zustand |
|
||||
| `cameraBridge.ts` | Kamera von aussen lesen und setzen, Bild-Schnappschuss, Live-Schnittebene (für BCF-Viewpoints) |
|
||||
|
||||
## Abgleich mit render3d
|
||||
|
||||
@@ -81,6 +81,9 @@ import {
|
||||
type OrbitState,
|
||||
type V3 as CamV3,
|
||||
} from "./cameraBridge";
|
||||
import { NO_KEYS, WALK_SPEED, anyKey, lookAround, speedFactor, stepWalk, walkKeyAllowed, walkKeyOf, type WalkKeys } from "./walk";
|
||||
import { loadShortcutOverrides, matchesShortcut } from "../state/keyboardShortcuts";
|
||||
import { createCameraFromView } from "../state/cameraActions";
|
||||
|
||||
/** Ein per 3D-Klick getroffenes Bauteil, oder null (Leerraum). */
|
||||
export type Pick3dHit =
|
||||
@@ -594,6 +597,10 @@ export function Wasm3DViewport({
|
||||
// stabile Pointer-Listener-Effekt stets den aktuellen Befehlszustand liest.
|
||||
const commandActiveRef = useRef(commandActive);
|
||||
commandActiveRef.current = commandActive;
|
||||
// [213] Begehen-Modus (Umschalt+F / Knopf): WASD, Q/E und Pfeile bewegen die Kamera, Maus ziehen schaut um.
|
||||
const [walkMode, setWalkMode] = useState(false);
|
||||
const walkModeRef = useRef(false);
|
||||
walkModeRef.current = walkMode;
|
||||
const onWorkplanePointRef = useRef(onWorkplanePoint);
|
||||
onWorkplanePointRef.current = onWorkplanePoint;
|
||||
const onWorkplaneConfirmRef = useRef(onWorkplaneConfirm);
|
||||
@@ -1381,6 +1388,89 @@ export function Wasm3DViewport({
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, []);
|
||||
|
||||
// [213] Begehen (WASD): Umschalt+F schaltet den Modus, darin bewegen W/A/S/D und die Pfeiltasten die Kamera
|
||||
// (vor/zurück/seitlich in der Horizontalen, Augenhöhe bleibt), Q/E senken und heben, Umschalt = schneller, Alt =
|
||||
// langsamer. Die Tasten gelten NUR im Modus — sonst kollidieren sie mit „s" (Spiegeln), „d" (Drehen), „q" (Messen).
|
||||
// Pro Frame (rAF) mit gekapptem Zeitschritt; Textfelder und Befehls-Modifikatoren (Strg/Cmd) sperren. Rechnung rein
|
||||
// in `walk.ts`. Die Handler laufen in der Capture-Phase und verbrauchen die Bewegungstasten, damit globale Kürzel
|
||||
// nicht zusätzlich feuern.
|
||||
useEffect(() => {
|
||||
if (!ready) return;
|
||||
const keys: WalkKeys = { ...NO_KEYS };
|
||||
const mods = { shift: false, alt: false };
|
||||
let raf = 0;
|
||||
let last = 0;
|
||||
const redrawOrbit = () => {
|
||||
redrawRef.current = () => {
|
||||
if (orbitRef.current) render(orbitCamera(orbitRef.current));
|
||||
};
|
||||
redrawRef.current();
|
||||
};
|
||||
const tick = (now: number) => {
|
||||
raf = 0;
|
||||
if (!walkModeRef.current || !anyKey(keys)) return;
|
||||
const o = orbitRef.current;
|
||||
if (o) {
|
||||
const dt = last ? (now - last) / 1000 : 0;
|
||||
orbitRef.current = stepWalk(o, keys, dt, WALK_SPEED * speedFactor(mods.shift, mods.alt));
|
||||
redrawOrbit();
|
||||
}
|
||||
last = now;
|
||||
raf = requestAnimationFrame(tick);
|
||||
};
|
||||
const start = () => {
|
||||
if (raf === 0) {
|
||||
last = 0;
|
||||
raf = requestAnimationFrame(tick);
|
||||
}
|
||||
};
|
||||
const release = () => {
|
||||
Object.assign(keys, NO_KEYS);
|
||||
};
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
mods.shift = e.shiftKey;
|
||||
mods.alt = e.altKey;
|
||||
if (!walkKeyAllowed(e, document.activeElement)) return;
|
||||
if (!e.repeat && matchesShortcut(e, "walkMode", loadShortcutOverrides())) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setWalkMode((w) => !w);
|
||||
release();
|
||||
return;
|
||||
}
|
||||
if (!walkModeRef.current || commandActiveRef.current || gripDragRef.current) return;
|
||||
if (e.key === "Escape") {
|
||||
setWalkMode(false);
|
||||
release();
|
||||
return;
|
||||
}
|
||||
const k = walkKeyOf(e.code);
|
||||
if (!k) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
keys[k] = true;
|
||||
start();
|
||||
};
|
||||
const onKeyUp = (e: KeyboardEvent) => {
|
||||
mods.shift = e.shiftKey;
|
||||
mods.alt = e.altKey;
|
||||
const k = walkKeyOf(e.code);
|
||||
if (k && keys[k]) {
|
||||
keys[k] = false;
|
||||
e.stopPropagation();
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown, true);
|
||||
window.addEventListener("keyup", onKeyUp, true);
|
||||
window.addEventListener("blur", release);
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKeyDown, true);
|
||||
window.removeEventListener("keyup", onKeyUp, true);
|
||||
window.removeEventListener("blur", release);
|
||||
cancelAnimationFrame(raf);
|
||||
};
|
||||
}, [ready, render]);
|
||||
|
||||
// Maus-Navigation (LINKS = Orbit, MITTE/RECHTS = Pan, RAD = Zoom, s.
|
||||
// Datei-Kommentar MAUS-SCHEMA). Verlässt damit IMMER die Praeset-Kamera und
|
||||
// wechselt auf die freie perspektivische Orbit-Kamera (Kontinuität über den
|
||||
@@ -1398,7 +1488,7 @@ export function Wasm3DViewport({
|
||||
};
|
||||
|
||||
let drag: {
|
||||
mode: "orbit" | "pan";
|
||||
mode: "orbit" | "pan" | "look";
|
||||
button: number;
|
||||
x: number;
|
||||
y: number;
|
||||
@@ -1469,7 +1559,8 @@ export function Wasm3DViewport({
|
||||
};
|
||||
|
||||
const onPointerDown = (e: PointerEvent) => {
|
||||
const mode = e.button === 0 ? "orbit" : e.button === 1 || e.button === 2 ? "pan" : null;
|
||||
// [213] Im Begehen-Modus schaut auch die rechte Taste um (statt zu schwenken); die mittlere schwenkt weiter.
|
||||
const mode = e.button === 0 ? "orbit" : e.button === 2 && walkModeRef.current ? "look" : e.button === 1 || e.button === 2 ? "pan" : null;
|
||||
if (!mode) return;
|
||||
e.preventDefault();
|
||||
drag = {
|
||||
@@ -1525,7 +1616,10 @@ export function Wasm3DViewport({
|
||||
return;
|
||||
}
|
||||
const h = canvas.clientHeight || 1;
|
||||
if (drag.mode === "orbit") {
|
||||
if (drag.mode === "look" || (drag.mode === "orbit" && walkModeRef.current)) {
|
||||
// [213] Umschauen um den Augpunkt (Orbit-Zustand bleibt die Wahrheit, das Ziel wandert mit).
|
||||
orbitRef.current = lookAround(o, dx, dy);
|
||||
} else if (drag.mode === "orbit") {
|
||||
// Winkel je Pixel wie OrbitControls: voller Umlauf über die Viewport-Höhe.
|
||||
o.yaw += (2 * Math.PI * dx) / h;
|
||||
o.pitch = Math.max(
|
||||
@@ -1716,6 +1810,30 @@ export function Wasm3DViewport({
|
||||
Darstellungsart kommen von der Oberleiste (TopBar); das Grid-Overlay
|
||||
unten ist der einzige eigene Umschalter hier. */}
|
||||
<canvas ref={canvasRef} data-engine="render3d" />
|
||||
{/* [213] Begehen (WASD) und Kamera aus der aktuellen Ansicht anlegen. */}
|
||||
<div className="viewport3d-tools" data-testid="viewport3d-tools">
|
||||
<button
|
||||
type="button"
|
||||
className={`viewport3d-tool${walkMode ? " is-on" : ""}`}
|
||||
aria-pressed={walkMode}
|
||||
title={t("walk.hint")}
|
||||
data-testid="walk-toggle"
|
||||
onPointerDown={(e) => e.stopPropagation()}
|
||||
onClick={() => setWalkMode((w) => !w)}
|
||||
>
|
||||
{t("walk.toggle")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="viewport3d-tool"
|
||||
title={t("viewport3d.camera.create")}
|
||||
data-testid="camera-create-3d"
|
||||
onPointerDown={(e) => e.stopPropagation()}
|
||||
onClick={() => createCameraFromView()}
|
||||
>
|
||||
{t("camera.defaultName")}+
|
||||
</button>
|
||||
</div>
|
||||
{/* Achsen-Lock-Führungslinie (Pfeiltasten während eines Endpunkt-/
|
||||
Verschiebe-Griff-Drags, s. `axisLockRef`-Dateikommentar) — SketchUp-
|
||||
Vorbild: eine durchgezogene farbige Linie durch den Anker markiert
|
||||
|
||||
@@ -242,6 +242,14 @@ export function getCamera(): ViewCamera | null {
|
||||
return r ? viewCameraFromCamera3d(r.camera, r.aspect) : null;
|
||||
}
|
||||
|
||||
/** [213] Abstand zwischen Augpunkt und Blickziel der Live-Kamera (Meter), oder null ohne Viewport. */
|
||||
export function getCameraTargetDistance(): number | null {
|
||||
const r = api?.read();
|
||||
if (!r) return null;
|
||||
const d = len(sub(r.camera.target, r.camera.eye));
|
||||
return Number.isFinite(d) && d > 0 ? d : null;
|
||||
}
|
||||
|
||||
/** Kamera setzen. `false` ohne Viewport oder bei unbrauchbarer Kamera (NaN, Nullvektor). */
|
||||
/** [C10] Systemeinstellung „Bewegung reduzieren": Kamerafahrten springen dann direkt ans Ziel. */
|
||||
export function prefersReducedMotion(): boolean {
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Camera, Project } from "../model/types";
|
||||
import { emptyProject } from "../model/sampleProject";
|
||||
import {
|
||||
cameraEye,
|
||||
cameraFromView,
|
||||
cameraToView,
|
||||
clampFov,
|
||||
floorForHeight,
|
||||
focalFromFov,
|
||||
fovFromFocal,
|
||||
isometricAim,
|
||||
nextCameraName,
|
||||
} from "./cameraView";
|
||||
import { camera3dFromViewCamera, viewCameraFromCamera3d } from "./cameraBridge";
|
||||
|
||||
const level = (id: string, baseElevation: number, kind: "floor" | "section" = "floor") =>
|
||||
({ id, name: id, kind, visible: true, locked: false, baseElevation, floorHeight: 2.8 }) as Project["drawingLevels"][number];
|
||||
|
||||
const project = (): Project => ({
|
||||
...emptyProject,
|
||||
drawingLevels: [level("eg", 0), level("og", 3), level("schnitt", 0, "section")],
|
||||
});
|
||||
|
||||
const cam = (over: Partial<Camera> = {}): Camera => ({
|
||||
id: "k1",
|
||||
type: "camera",
|
||||
name: "Süd",
|
||||
floorId: "og",
|
||||
categoryCode: "92",
|
||||
position: { x: 2, y: -3 },
|
||||
eyeHeight: 1.6,
|
||||
target: { x: 2, y: 7 },
|
||||
targetHeight: 4.6,
|
||||
fovDeg: 50,
|
||||
projection: "perspective",
|
||||
...over,
|
||||
});
|
||||
|
||||
describe("[213] Kamera → Ansicht", () => {
|
||||
it("Augenhöhe liegt über der Geschoss-OK; Blickrichtung zeigt zum Ziel", () => {
|
||||
const p = project();
|
||||
expect(cameraEye(p, cam())).toEqual([2, -3, 4.6]);
|
||||
const v = cameraToView(p, cam())!;
|
||||
expect(v.kind).toBe("perspective");
|
||||
expect(v.position).toEqual([2, -3, 4.6]);
|
||||
expect(v.direction[0]).toBeCloseTo(0, 12);
|
||||
expect(v.direction[1]).toBeCloseTo(1, 12);
|
||||
expect(v.direction[2]).toBeCloseTo(0, 12);
|
||||
expect(v.fovDeg).toBe(50);
|
||||
// Up steht senkrecht zur Blickrichtung und zeigt nach oben.
|
||||
expect(v.up[2]).toBeCloseTo(1, 12);
|
||||
expect(v.up[0] * v.direction[0] + v.up[1] * v.direction[1] + v.up[2] * v.direction[2]).toBeCloseTo(0, 12);
|
||||
});
|
||||
|
||||
it("geneigter Blick: Up bleibt senkrecht und normiert", () => {
|
||||
const v = cameraToView(project(), cam({ targetHeight: 0 }))!;
|
||||
expect(v.direction[2]).toBeLessThan(0);
|
||||
expect(Math.hypot(...v.up)).toBeCloseTo(1, 12);
|
||||
expect(v.up[0] * v.direction[0] + v.up[1] * v.direction[1] + v.up[2] * v.direction[2]).toBeCloseTo(0, 12);
|
||||
expect(v.up[2]).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("senkrechter Blick nach unten: Up ist Norden (Grundriss-Lage)", () => {
|
||||
const v = cameraToView(project(), cam({ target: { x: 2, y: -3 }, targetHeight: 0 }))!;
|
||||
expect(v.direction[2]).toBeCloseTo(-1, 12);
|
||||
expect(v.up[1]).toBeCloseTo(1, 9);
|
||||
});
|
||||
|
||||
it("Axonometrie und Parallel sind orthogonal mit Sichthöhe; Bildwinkel wird geklemmt", () => {
|
||||
const a = cameraToView(project(), cam({ projection: "axonometric", orthoHeight: 8 }))!;
|
||||
expect(a.kind).toBe("orthogonal");
|
||||
expect(a.orthoHeight).toBe(8);
|
||||
expect(cameraToView(project(), cam({ projection: "parallel" }))!.orthoHeight).toBe(10);
|
||||
expect(cameraToView(project(), cam({ fovDeg: 500 }))!.fovDeg).toBe(120);
|
||||
expect(clampFov(NaN)).toBe(50);
|
||||
});
|
||||
|
||||
it("Standpunkt gleich Ziel oder NaN: keine Ansicht", () => {
|
||||
expect(cameraToView(project(), cam({ target: { x: 2, y: -3 }, targetHeight: 4.6 }))).toBeNull();
|
||||
expect(cameraToView(project(), cam({ position: { x: NaN, y: 0 } }))).toBeNull();
|
||||
});
|
||||
|
||||
it("liefert dieselbe Struktur wie die aktive 3D-Ansicht: Umweg über die Viewport-Kamera ist verlustfrei", () => {
|
||||
const v = cameraToView(project(), cam({ targetHeight: 2 }), 1.5)!;
|
||||
const c3 = camera3dFromViewCamera(v, 10)!;
|
||||
const back = viewCameraFromCamera3d(c3, 1.5)!;
|
||||
expect(back.kind).toBe(v.kind);
|
||||
back.position.forEach((x, i) => expect(x).toBeCloseTo(v.position[i], 9));
|
||||
back.direction.forEach((x, i) => expect(x).toBeCloseTo(v.direction[i], 9));
|
||||
back.up.forEach((x, i) => expect(x).toBeCloseTo(v.up[i], 9));
|
||||
expect(back.fovDeg).toBeCloseTo(v.fovDeg, 9);
|
||||
expect(back.aspect).toBe(1.5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("[213] Ansicht → Kamera", () => {
|
||||
it("Standpunkt bestimmt Geschoss und Augenhöhe; Ziel liegt auf der Blickachse", () => {
|
||||
const p = project();
|
||||
const view = cameraToView(p, cam({ targetHeight: 3.6 }))!;
|
||||
const made = cameraFromView(p, view, { id: "k2", name: "Neu", fallbackFloorId: "eg", distance: Math.hypot(10, 1) });
|
||||
expect(made.floorId).toBe("og");
|
||||
expect(made.eyeHeight).toBeCloseTo(1.6, 9);
|
||||
expect(made.position).toEqual({ x: 2, y: -3 });
|
||||
expect(made.target.x).toBeCloseTo(2, 9);
|
||||
expect(made.target.y).toBeCloseTo(7, 9);
|
||||
expect(made.targetHeight).toBeCloseTo(3.6, 9);
|
||||
expect(made.projection).toBe("perspective");
|
||||
expect(made.categoryCode).toBe("92");
|
||||
expect(made.type).toBe("camera");
|
||||
// Wieder in die Ansicht: dieselbe Kamera.
|
||||
const again = cameraToView(p, made)!;
|
||||
again.position.forEach((x, i) => expect(x).toBeCloseTo(view.position[i], 9));
|
||||
again.direction.forEach((x, i) => expect(x).toBeCloseTo(view.direction[i], 9));
|
||||
});
|
||||
|
||||
it("orthografische Ansicht wird zur Parallelprojektion mit Sichthöhe", () => {
|
||||
const p = project();
|
||||
const view = cameraToView(p, cam({ projection: "axonometric", orthoHeight: 12 }))!;
|
||||
const made = cameraFromView(p, view, { id: "k3", name: "Ortho", fallbackFloorId: "eg" });
|
||||
expect(made.projection).toBe("parallel");
|
||||
expect(made.orthoHeight).toBe(12);
|
||||
});
|
||||
|
||||
it("Geschoss zu einer Höhe: höchstes mit OK ≤ z, sonst das unterste, Schnitte zählen nicht", () => {
|
||||
const p = project();
|
||||
expect(floorForHeight(p, 4.6, "x")).toBe("og");
|
||||
expect(floorForHeight(p, 2.99, "x")).toBe("eg");
|
||||
expect(floorForHeight(p, -5, "x")).toBe("eg");
|
||||
expect(floorForHeight(p, NaN, "x")).toBe("x");
|
||||
expect(floorForHeight({ ...p, drawingLevels: [] }, 1, "fallback")).toBe("fallback");
|
||||
});
|
||||
|
||||
it("Namen zählen hoch", () => {
|
||||
const p = { ...project(), cameras: [cam({ name: "Kamera 1" }), cam({ id: "k2", name: "Kamera 2" })] };
|
||||
expect(nextCameraName(p, "Kamera")).toBe("Kamera 3");
|
||||
expect(nextCameraName(project(), "Kamera")).toBe("Kamera 1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("[213] Brennweite und Axonometrie", () => {
|
||||
it("Brennweite ↔ Bildwinkel (24 mm Sensorhöhe)", () => {
|
||||
expect(fovFromFocal(focalFromFov(50))).toBeCloseTo(50, 9);
|
||||
expect(fovFromFocal(35)).toBeCloseTo(37.85, 1);
|
||||
});
|
||||
|
||||
it("Isometrie-Ausrichtung behält das Ziel im Blick und neigt 35.264°", () => {
|
||||
const p = project();
|
||||
const c = cam({ projection: "axonometric" });
|
||||
const aim = isometricAim(p, c);
|
||||
const next = { ...c, ...aim };
|
||||
const v = cameraToView(p, next)!;
|
||||
// Blick nach oben-rechts hinten: 45° im Grundriss, 35.264° nach unten.
|
||||
expect(v.direction[0]).toBeCloseTo(Math.SQRT1_2 * Math.cos(Math.atan(1 / Math.SQRT2)), 6);
|
||||
expect(v.direction[1]).toBeCloseTo(Math.SQRT1_2 * Math.cos(Math.atan(1 / Math.SQRT2)), 6);
|
||||
expect(v.direction[2]).toBeCloseTo(-Math.sin(Math.atan(1 / Math.SQRT2)), 6);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,152 @@
|
||||
// [213] Kamera-Element (`Project.cameras`) ↔ Sicht des 3D-Viewports. Reine Funktionen, ohne React und Engine.
|
||||
//
|
||||
// `cameraToView` liefert dieselbe Struktur wie die aktive 3D-Ansicht (`getCamera()` der `cameraBridge`: Modell-
|
||||
// Koordinaten, z oben) — damit setzt „Kamera öffnen" den Viewport exakt, und das Rendering ([211]) kann eine
|
||||
// gespeicherte Kamera wie die Live-Ansicht verwenden. `cameraFromView` legt umgekehrt aus der Live-Ansicht ein
|
||||
// Kamera-Element an (Standpunkt → Geschoss + Augenhöhe).
|
||||
|
||||
import type { Camera, DrawingLevel, Project, Vec2 } from "../model/types";
|
||||
import { CAMERA_CATEGORY } from "../model/derivedCategories";
|
||||
import type { V3, ViewCamera } from "./cameraBridge";
|
||||
|
||||
/** Vorgaben wie im Kern (`camera.rs`). */
|
||||
export const DEFAULT_EYE_HEIGHT = 1.6;
|
||||
export const DEFAULT_FOV_DEG = 50;
|
||||
export const DEFAULT_ORTHO_HEIGHT = 10;
|
||||
export const MIN_FOV_DEG = 5;
|
||||
export const MAX_FOV_DEG = 120;
|
||||
/** Sensorhöhe für die Kleinbild-Brennweite (mm), wie im Kern. */
|
||||
export const SENSOR_HEIGHT_MM = 24;
|
||||
/** Blickweite beim Anlegen aus einer Ansicht, wenn der Viewport keinen Zielabstand meldet (m). */
|
||||
export const DEFAULT_AIM_DISTANCE = 10;
|
||||
|
||||
/** Kleinbild-Brennweite (mm) zum vertikalen Bildwinkel (Grad). */
|
||||
export function focalFromFov(fovDeg: number): number {
|
||||
return SENSOR_HEIGHT_MM / 2 / Math.tan((fovDeg * Math.PI) / 360);
|
||||
}
|
||||
|
||||
/** Vertikaler Bildwinkel (Grad) zur Kleinbild-Brennweite (mm). */
|
||||
export function fovFromFocal(mm: number): number {
|
||||
return (2 * Math.atan(SENSOR_HEIGHT_MM / 2 / mm) * 180) / Math.PI;
|
||||
}
|
||||
|
||||
export function clampFov(fovDeg: number): number {
|
||||
return Number.isFinite(fovDeg) && fovDeg > 0 ? Math.min(MAX_FOV_DEG, Math.max(MIN_FOV_DEG, fovDeg)) : DEFAULT_FOV_DEG;
|
||||
}
|
||||
|
||||
const finite = (...v: number[]): boolean => v.every(Number.isFinite);
|
||||
|
||||
/** Höhe der Geschoss-OK (m), 0 ohne Angabe. */
|
||||
export function floorBase(project: Project, floorId: string): number {
|
||||
const z = project.drawingLevels.find((l) => l.id === floorId)?.baseElevation;
|
||||
return typeof z === "number" && Number.isFinite(z) ? z : 0;
|
||||
}
|
||||
|
||||
/** Augpunkt der Kamera in Modell-Koordinaten (Meter, z oben). */
|
||||
export function cameraEye(project: Project, cam: Camera): V3 {
|
||||
return [cam.position.x, cam.position.y, floorBase(project, cam.floorId) + (Number.isFinite(cam.eyeHeight) ? cam.eyeHeight : DEFAULT_EYE_HEIGHT)];
|
||||
}
|
||||
|
||||
/** Ziel der Kamera in Modell-Koordinaten. */
|
||||
export function cameraTarget(cam: Camera): V3 {
|
||||
return [cam.target.x, cam.target.y, cam.targetHeight];
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Sicht der Kamera: Standpunkt, normierte Blickrichtung und Up-Vektor (senkrecht zur Blickrichtung, aus der
|
||||
* Modell-Senkrechten; bei exakt senkrechtem Blick gilt die Grundriss-Richtung „oben = Norden"). Perspektive →
|
||||
* `perspective`, Axonometrie und Parallel → `orthogonal`. Null bei Standpunkt = Ziel oder nicht endlichen Zahlen.
|
||||
*/
|
||||
export function cameraToView(project: Project, cam: Camera, aspect = 16 / 9): ViewCamera | null {
|
||||
const eye = cameraEye(project, cam);
|
||||
const tgt = cameraTarget(cam);
|
||||
if (!finite(...eye, ...tgt)) return null;
|
||||
const d: V3 = [tgt[0] - eye[0], tgt[1] - eye[1], tgt[2] - eye[2]];
|
||||
const len = Math.hypot(d[0], d[1], d[2]);
|
||||
if (!(len > 1e-9)) return null;
|
||||
const dir: V3 = [d[0] / len, d[1] / len, d[2] / len];
|
||||
// Up aus der Modell-Senkrechten; ist der Blick (fast) senkrecht, aus der Nordrichtung.
|
||||
const ref: V3 = Math.abs(dir[2]) > 0.9999 ? [0, 1, 0] : [0, 0, 1];
|
||||
const k = ref[0] * dir[0] + ref[1] * dir[1] + ref[2] * dir[2];
|
||||
const upRaw: V3 = [ref[0] - dir[0] * k, ref[1] - dir[1] * k, ref[2] - dir[2] * k];
|
||||
const ul = Math.hypot(upRaw[0], upRaw[1], upRaw[2]);
|
||||
const up: V3 = [upRaw[0] / ul, upRaw[1] / ul, upRaw[2] / ul];
|
||||
const ortho = cam.projection !== "perspective";
|
||||
return {
|
||||
kind: ortho ? "orthogonal" : "perspective",
|
||||
position: eye,
|
||||
direction: dir,
|
||||
up,
|
||||
fovDeg: clampFov(cam.fovDeg),
|
||||
orthoHeight: cam.orthoHeight && cam.orthoHeight > 0 ? cam.orthoHeight : DEFAULT_ORTHO_HEIGHT,
|
||||
aspect: Number.isFinite(aspect) && aspect > 0 ? aspect : 16 / 9,
|
||||
};
|
||||
}
|
||||
|
||||
/** Geschoss, auf dem ein Standpunkt der Höhe `z` steht: das höchste Geschoss mit OK ≤ z (sonst das unterste, sonst `fallback`). */
|
||||
export function floorForHeight(project: Project, z: number, fallback: string): string {
|
||||
const floors = project.drawingLevels.filter((l: DrawingLevel) => l.kind === "floor");
|
||||
if (!floors.length || !Number.isFinite(z)) return fallback;
|
||||
const base = (l: DrawingLevel) => (typeof l.baseElevation === "number" && Number.isFinite(l.baseElevation) ? l.baseElevation : 0);
|
||||
const sorted = [...floors].sort((a, b) => base(a) - base(b));
|
||||
let hit = sorted[0];
|
||||
for (const l of sorted) if (base(l) <= z + 1e-6) hit = l;
|
||||
return hit.id;
|
||||
}
|
||||
|
||||
/** Nächster freier Name „Kamera 1", „Kamera 2" … (`label` = Namensstamm). */
|
||||
export function nextCameraName(project: Project, label: string): string {
|
||||
const used = new Set((project.cameras ?? []).map((c) => c.name));
|
||||
for (let n = 1; ; n++) if (!used.has(`${label} ${n}`)) return `${label} ${n}`;
|
||||
}
|
||||
|
||||
export interface CameraFromViewOptions {
|
||||
id: string;
|
||||
name: string;
|
||||
/** Geschoss des Symbols; fehlt = das Geschoss, auf dem der Standpunkt steht. */
|
||||
floorId?: string;
|
||||
/** Rückfall-Geschoss, wenn das Projekt kein Geschoss kennt (aktive Ebene). */
|
||||
fallbackFloorId: string;
|
||||
/** Abstand des Ziels vom Standpunkt (m); fehlt = 10 m (orthografisch: die Sichthöhe). */
|
||||
distance?: number;
|
||||
categoryCode?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kamera-Element aus der Sicht des Viewports (Modell-Koordinaten): Standpunkt → Geschoss + Augenhöhe, Ziel auf
|
||||
* der Blickachse im Abstand `distance`. Orthografische Sichten werden zu „parallel" (das Preset-Verhalten der
|
||||
* Axonometrie ist eine Ausrichtung, kein eigener Zustand der Sicht).
|
||||
*/
|
||||
export function cameraFromView(project: Project, view: ViewCamera, o: CameraFromViewOptions): Camera {
|
||||
const [px, py, pz] = view.position;
|
||||
const floorId = o.floorId ?? floorForHeight(project, pz, o.fallbackFloorId);
|
||||
const ortho = view.kind === "orthogonal";
|
||||
const dist = o.distance !== undefined && Number.isFinite(o.distance) && o.distance > 0 ? o.distance : ortho ? Math.max(view.orthoHeight, 1) : DEFAULT_AIM_DISTANCE;
|
||||
const target: Vec2 = { x: px + view.direction[0] * dist, y: py + view.direction[1] * dist };
|
||||
const cam: Camera = {
|
||||
id: o.id,
|
||||
type: "camera",
|
||||
name: o.name,
|
||||
floorId,
|
||||
categoryCode: o.categoryCode ?? CAMERA_CATEGORY,
|
||||
position: { x: px, y: py },
|
||||
eyeHeight: pz - floorBase(project, floorId),
|
||||
target,
|
||||
targetHeight: pz + view.direction[2] * dist,
|
||||
fovDeg: clampFov(view.fovDeg),
|
||||
projection: ortho ? "parallel" : "perspective",
|
||||
};
|
||||
if (ortho) cam.orthoHeight = view.orthoHeight;
|
||||
return cam;
|
||||
}
|
||||
|
||||
/** Axonometrie-Ausrichtung („Isometrie"): Blick aus Südwest von oben (45° Azimut, 35.264° Neigung) auf dasselbe Ziel. */
|
||||
export function isometricAim(project: Project, cam: Camera): Pick<Camera, "position" | "eyeHeight"> {
|
||||
const eye = cameraEye(project, cam);
|
||||
const tgt = cameraTarget(cam);
|
||||
const dist = Math.max(Math.hypot(tgt[0] - eye[0], tgt[1] - eye[1], tgt[2] - eye[2]), 5);
|
||||
const pitch = Math.atan(1 / Math.SQRT2);
|
||||
const horiz = dist * Math.cos(pitch);
|
||||
const from: V3 = [tgt[0] - horiz * Math.SQRT1_2, tgt[1] - horiz * Math.SQRT1_2, tgt[2] + dist * Math.sin(pitch)];
|
||||
return { position: { x: from[0], y: from[1] }, eyeHeight: from[2] - floorBase(project, cam.floorId) };
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { orbitCamera } from "./cameraBridge";
|
||||
import type { OrbitState } from "./cameraBridge";
|
||||
import { NO_KEYS, lookAround, orbitEye, speedFactor, stepWalk, walkKeyAllowed, walkKeyOf, walkVelocity } from "./walk";
|
||||
|
||||
const orbit = (over: Partial<OrbitState> = {}): OrbitState => ({
|
||||
yaw: 0,
|
||||
pitch: 0.4,
|
||||
dist: 10,
|
||||
target: [0, 1.6, 0],
|
||||
ortho: false,
|
||||
orthoHalfHeight: 5,
|
||||
...over,
|
||||
});
|
||||
|
||||
const near = (a: readonly number[], b: readonly number[], eps = 1e-9) => a.forEach((x, i) => expect(x).toBeCloseTo(b[i], -Math.log10(eps)));
|
||||
|
||||
describe("[213] Begehen: Tasten", () => {
|
||||
it("W/A/S/D, Pfeile und Q/E; alles andere ist keine Bewegung", () => {
|
||||
expect(walkKeyOf("KeyW")).toBe("forward");
|
||||
expect(walkKeyOf("ArrowUp")).toBe("forward");
|
||||
expect(walkKeyOf("KeyS")).toBe("back");
|
||||
expect(walkKeyOf("ArrowLeft")).toBe("left");
|
||||
expect(walkKeyOf("KeyD")).toBe("right");
|
||||
expect(walkKeyOf("KeyQ")).toBe("down");
|
||||
expect(walkKeyOf("KeyE")).toBe("up");
|
||||
expect(walkKeyOf("KeyT")).toBeNull();
|
||||
expect(walkKeyOf("Digit3")).toBeNull();
|
||||
});
|
||||
|
||||
it("Shift schneller, Alt langsamer, beide gleichen sich teils aus", () => {
|
||||
expect(speedFactor(false, false)).toBe(1);
|
||||
expect(speedFactor(true, false)).toBe(4);
|
||||
expect(speedFactor(false, true)).toBe(0.25);
|
||||
expect(speedFactor(true, true)).toBe(1);
|
||||
});
|
||||
|
||||
it("Befehls-Modifikator oder Textfeld sperren das Begehen", () => {
|
||||
expect(walkKeyAllowed({ ctrlKey: false, metaKey: false }, null)).toBe(true);
|
||||
expect(walkKeyAllowed({ ctrlKey: true, metaKey: false }, null)).toBe(false);
|
||||
expect(walkKeyAllowed({ ctrlKey: false, metaKey: true }, null)).toBe(false);
|
||||
const el = (tagName: string, isContentEditable = false) => ({ tagName, isContentEditable }) as unknown as Element;
|
||||
expect(walkKeyAllowed({ ctrlKey: false, metaKey: false }, el("INPUT"))).toBe(false);
|
||||
expect(walkKeyAllowed({ ctrlKey: false, metaKey: false }, el("TEXTAREA"))).toBe(false);
|
||||
expect(walkKeyAllowed({ ctrlKey: false, metaKey: false }, el("DIV", true))).toBe(false);
|
||||
expect(walkKeyAllowed({ ctrlKey: false, metaKey: false }, el("DIV"))).toBe(true);
|
||||
expect(walkKeyAllowed({ ctrlKey: false, metaKey: false }, el("CANVAS"))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("[213] Begehen: Bewegung", () => {
|
||||
it("vorwärts läuft in der Blickrichtung, waagrecht (Augenhöhe bleibt trotz Neigung)", () => {
|
||||
// yaw 0: Augpunkt liegt bei +x vom Ziel, Blick geht nach −x.
|
||||
const v = walkVelocity({ ...NO_KEYS, forward: true }, 0, 3);
|
||||
near(v, [-3, 0, 0]);
|
||||
const o = orbit({ pitch: 0.9 });
|
||||
const eye0 = orbitEye(o);
|
||||
const n = stepWalk(o, { ...NO_KEYS, forward: true }, 1 / 60);
|
||||
const eye1 = orbitEye(n);
|
||||
expect(eye1[1]).toBeCloseTo(eye0[1], 12);
|
||||
expect(eye1[0]).toBeLessThan(eye0[0]);
|
||||
// Abstand, Winkel und Projektion bleiben.
|
||||
expect(n.dist).toBe(o.dist);
|
||||
expect(n.pitch).toBe(o.pitch);
|
||||
expect(n.yaw).toBe(o.yaw);
|
||||
});
|
||||
|
||||
it("seitwärts steht senkrecht auf der Blickrichtung; rechts ist rechts", () => {
|
||||
// Blick nach −x (yaw 0), Weltoben +y: rechts ist −z.
|
||||
near(walkVelocity({ ...NO_KEYS, right: true }, 0, 2), [0, 0, -2]);
|
||||
near(walkVelocity({ ...NO_KEYS, left: true }, 0, 2), [0, 0, 2]);
|
||||
// Gedreht um 90°: Blick nach −z, rechts ist +x.
|
||||
near(walkVelocity({ ...NO_KEYS, forward: true }, Math.PI / 2, 2), [0, 0, -2]);
|
||||
near(walkVelocity({ ...NO_KEYS, right: true }, Math.PI / 2, 2), [2, 0, 0]);
|
||||
});
|
||||
|
||||
it("diagonal ist nicht schneller; Gegentasten heben sich auf; Q/E senkrecht", () => {
|
||||
const d = walkVelocity({ ...NO_KEYS, forward: true, right: true }, 0.3, 3);
|
||||
expect(Math.hypot(d[0], d[2])).toBeCloseTo(3, 12);
|
||||
near(walkVelocity({ ...NO_KEYS, forward: true, back: true }, 0.3, 3), [0, 0, 0]);
|
||||
near(walkVelocity({ ...NO_KEYS, up: true }, 0.3, 3), [0, 3, 0]);
|
||||
near(walkVelocity({ ...NO_KEYS, down: true }, 0.3, 3), [0, -3, 0]);
|
||||
});
|
||||
|
||||
it("Weg = Tempo × Zeit; langer Zeitschritt wird gekappt; ohne Taste oder dt bleibt der Zustand", () => {
|
||||
const o = orbit();
|
||||
const n = stepWalk(o, { ...NO_KEYS, forward: true }, 0.05, 4);
|
||||
expect(n.target[0]).toBeCloseTo(-0.2, 12);
|
||||
const slow = stepWalk(o, { ...NO_KEYS, forward: true }, 5, 4);
|
||||
expect(slow.target[0]).toBeCloseTo(-0.4, 12); // höchstens 0.1 s
|
||||
expect(stepWalk(o, NO_KEYS, 1)).toBe(o);
|
||||
expect(stepWalk(o, { ...NO_KEYS, forward: true }, 0)).toBe(o);
|
||||
expect(stepWalk(o, { ...NO_KEYS, forward: true }, NaN)).toBe(o);
|
||||
expect(stepWalk(o, { ...NO_KEYS, forward: true }, 1, 0)).toBe(o);
|
||||
});
|
||||
|
||||
it("die Kamera zeigt nach dem Gehen weiter in dieselbe Richtung", () => {
|
||||
const o = orbit({ yaw: 1.2, pitch: 0.3 });
|
||||
const c0 = orbitCamera(o);
|
||||
const c1 = orbitCamera(stepWalk(o, { ...NO_KEYS, forward: true, right: true }, 0.08));
|
||||
const dir = (c: { eye: number[]; target: number[] }) => {
|
||||
const d = [c.target[0] - c.eye[0], c.target[1] - c.eye[1], c.target[2] - c.eye[2]];
|
||||
const l = Math.hypot(d[0], d[1], d[2]);
|
||||
return d.map((x) => x / l);
|
||||
};
|
||||
near(dir(c1), dir(c0), 1e-9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("[213] Begehen: Umschauen", () => {
|
||||
it("der Augpunkt bleibt stehen, die Blickrichtung dreht", () => {
|
||||
const o = orbit({ yaw: 0.7, pitch: 0.2 });
|
||||
const eye = orbitEye(o);
|
||||
const n = lookAround(o, 120, -40);
|
||||
near(orbitEye(n), eye, 1e-9);
|
||||
expect(n.yaw).toBeGreaterThan(o.yaw); // Maus nach rechts → Blick nach rechts
|
||||
expect(n.pitch).toBeLessThan(o.pitch); // Maus nach oben → Blick hebt sich
|
||||
expect(n.dist).toBe(o.dist);
|
||||
});
|
||||
|
||||
it("Neigung ist geklemmt; ohne Bewegung bleibt der Zustand", () => {
|
||||
const o = orbit();
|
||||
const steep = lookAround(o, 0, 1e6);
|
||||
expect(steep.pitch).toBeLessThan(Math.PI / 2);
|
||||
expect(steep.pitch).toBeGreaterThan(1.5);
|
||||
expect(lookAround(o, 0, 0)).toBe(o);
|
||||
expect(lookAround(o, NaN, 3)).toBe(o);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
// [213] Begehen im 3D (WASD): reine Bewegungsrechnung auf dem Orbit-Zustand des Viewports, ohne React und Engine.
|
||||
//
|
||||
// Der Orbit-Zustand (`OrbitState`, world Y-oben) beschreibt die Kamera als Blickziel + Abstand + Winkel. Den Augpunkt
|
||||
// verschieben heisst, das Blickziel um denselben Vektor verschieben — Abstand und Winkel bleiben. Vorwärts und
|
||||
// seitwärts laufen in der Horizontalen (Augenhöhe bleibt, auch bei geneigtem Blick); Q/E bewegen senkrecht.
|
||||
// Umschauen dreht die Blickrichtung um den Augpunkt (nicht um das Ziel wie der Orbit).
|
||||
|
||||
import { PITCH_LIMIT } from "./cameraBridge";
|
||||
import type { OrbitState, V3 } from "./cameraBridge";
|
||||
|
||||
/** Gedrückte Bewegungstasten. */
|
||||
export interface WalkKeys {
|
||||
forward: boolean;
|
||||
back: boolean;
|
||||
left: boolean;
|
||||
right: boolean;
|
||||
up: boolean;
|
||||
down: boolean;
|
||||
}
|
||||
|
||||
export const NO_KEYS: WalkKeys = { forward: false, back: false, left: false, right: false, up: false, down: false };
|
||||
|
||||
/** Grundgeschwindigkeit (m/s), Shift ×4, Alt ×0.25. */
|
||||
export const WALK_SPEED = 3;
|
||||
export const FAST_FACTOR = 4;
|
||||
export const SLOW_FACTOR = 0.25;
|
||||
/** Längster Zeitschritt (s): nach einem Hänger (Tab im Hintergrund) kein Sprung durchs Haus. */
|
||||
export const MAX_DT = 0.1;
|
||||
/** Mausempfindlichkeit beim Umschauen (Radiant je Pixel). */
|
||||
export const LOOK_RAD_PER_PX = 0.0035;
|
||||
|
||||
/** Taste (`KeyboardEvent.code`) → Bewegung; `null` für alle anderen. W/S/A/D und Pfeile vor/zurück/seitlich, Q/E runter/hoch. */
|
||||
export function walkKeyOf(code: string): keyof WalkKeys | null {
|
||||
switch (code) {
|
||||
case "KeyW":
|
||||
case "ArrowUp":
|
||||
return "forward";
|
||||
case "KeyS":
|
||||
case "ArrowDown":
|
||||
return "back";
|
||||
case "KeyA":
|
||||
case "ArrowLeft":
|
||||
return "left";
|
||||
case "KeyD":
|
||||
case "ArrowRight":
|
||||
return "right";
|
||||
case "KeyQ":
|
||||
return "down";
|
||||
case "KeyE":
|
||||
return "up";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Ist irgendeine Bewegungstaste gedrückt? */
|
||||
export const anyKey = (k: WalkKeys): boolean => k.forward || k.back || k.left || k.right || k.up || k.down;
|
||||
|
||||
/** Tempo-Faktor aus Shift (schneller) und Alt (langsamer); beide = Grundtempo. */
|
||||
export function speedFactor(shift: boolean, alt: boolean): number {
|
||||
return (shift ? FAST_FACTOR : 1) * (alt ? SLOW_FACTOR : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Geschwindigkeit (world, m/s) aus den gedrückten Tasten. Vorwärts = horizontale Blickrichtung (die Höhe bleibt),
|
||||
* seitwärts = rechts, hoch/runter = world Y. Gegensätzliche Tasten heben sich auf; diagonale Bewegung ist nicht
|
||||
* schneller als geradeaus (die waagrechte Richtung wird normiert).
|
||||
*/
|
||||
export function walkVelocity(keys: WalkKeys, yaw: number, speed: number): V3 {
|
||||
const fwd = (keys.forward ? 1 : 0) - (keys.back ? 1 : 0);
|
||||
const side = (keys.right ? 1 : 0) - (keys.left ? 1 : 0);
|
||||
const vert = (keys.up ? 1 : 0) - (keys.down ? 1 : 0);
|
||||
// Horizontale Blickrichtung f = (−cos yaw, 0, −sin yaw), rechts s = (sin yaw, 0, −cos yaw) (wie im Pan des Viewports).
|
||||
const hx = -Math.cos(yaw) * fwd + Math.sin(yaw) * side;
|
||||
const hz = -Math.sin(yaw) * fwd - Math.cos(yaw) * side;
|
||||
const hl = Math.hypot(hx, hz);
|
||||
const k = hl > 1e-12 ? speed / hl : 0;
|
||||
return [hx * k, vert * speed, hz * k];
|
||||
}
|
||||
|
||||
/** Orbit-Zustand nach `dt` Sekunden Gehen; derselbe Zustand ohne Taste oder bei unbrauchbarem `dt`. */
|
||||
export function stepWalk(o: OrbitState, keys: WalkKeys, dt: number, speed: number = WALK_SPEED): OrbitState {
|
||||
if (!anyKey(keys) || !(dt > 0) || !Number.isFinite(dt) || !(speed > 0)) return o;
|
||||
const v = walkVelocity(keys, o.yaw, speed);
|
||||
const s = Math.min(dt, MAX_DT);
|
||||
return { ...o, target: [o.target[0] + v[0] * s, o.target[1] + v[1] * s, o.target[2] + v[2] * s] };
|
||||
}
|
||||
|
||||
/** Augpunkt (world) des Orbit-Zustands. */
|
||||
export function orbitEye(o: OrbitState): V3 {
|
||||
const pitch = Math.max(-PITCH_LIMIT, Math.min(PITCH_LIMIT, o.pitch));
|
||||
const r = o.dist * Math.cos(pitch);
|
||||
return [o.target[0] + r * Math.cos(o.yaw), o.target[1] + o.dist * Math.sin(pitch), o.target[2] + r * Math.sin(o.yaw)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Umschauen um den Augpunkt: Maus nach rechts (`dx` > 0) dreht den Blick nach rechts, Maus nach unten (`dy` > 0)
|
||||
* senkt ihn. Der Augpunkt bleibt exakt stehen (das Blickziel wandert auf der neuen Blickachse mit); der Neigungswinkel
|
||||
* ist wie beim Orbit geklemmt.
|
||||
*/
|
||||
export function lookAround(o: OrbitState, dx: number, dy: number, radPerPx: number = LOOK_RAD_PER_PX): OrbitState {
|
||||
if (!Number.isFinite(dx) || !Number.isFinite(dy) || (dx === 0 && dy === 0)) return o;
|
||||
const eye = orbitEye(o);
|
||||
const yaw = o.yaw + dx * radPerPx;
|
||||
const pitch = Math.max(-PITCH_LIMIT, Math.min(PITCH_LIMIT, o.pitch + dy * radPerPx));
|
||||
const r = o.dist * Math.cos(pitch);
|
||||
return { ...o, yaw, pitch, target: [eye[0] - r * Math.cos(yaw), eye[1] - o.dist * Math.sin(pitch), eye[2] - r * Math.sin(yaw)] };
|
||||
}
|
||||
|
||||
/** Darf die Taste das Begehen starten (kein Textfeld im Fokus, kein Befehls-Modifikator)? */
|
||||
export function walkKeyAllowed(e: { ctrlKey: boolean; metaKey: boolean }, active: Element | null): boolean {
|
||||
if (e.ctrlKey || e.metaKey) return false;
|
||||
if (!active) return true;
|
||||
const tag = active.tagName;
|
||||
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return false;
|
||||
return !(active as HTMLElement).isContentEditable;
|
||||
}
|
||||
Reference in new issue
Block a user