(bytes: Uint8Array)
| 75 | * Decode camera state from raw bytes (72 bytes). |
| 76 | */ |
| 77 | export function decodeCameraFromBytes(bytes: Uint8Array): CameraViewState | null { |
| 78 | if (bytes.length !== 72) return null; |
| 79 | |
| 80 | const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); |
| 81 | |
| 82 | const px = view.getFloat64(0, true); |
| 83 | const py = view.getFloat64(8, true); |
| 84 | const pz = view.getFloat64(16, true); |
| 85 | const tx = view.getFloat64(24, true); |
| 86 | const ty = view.getFloat64(32, true); |
| 87 | const tz = view.getFloat64(40, true); |
| 88 | const qx = view.getFloat64(48, true); |
| 89 | const qy = view.getFloat64(56, true); |
| 90 | const qz = view.getFloat64(64, true); |
| 91 | |
| 92 | const qwSquared = 1 - qx * qx - qy * qy - qz * qz; |
| 93 | if (qwSquared < 0) return null; |
| 94 | const qw = Math.sqrt(qwSquared); |
| 95 | |
| 96 | return { |
| 97 | position: [px, py, pz], |
| 98 | target: [tx, ty, tz], |
| 99 | quaternion: [qx, qy, qz, qw], |
| 100 | distance: Math.sqrt( |
| 101 | (px - tx) * (px - tx) + |
| 102 | (py - ty) * (py - ty) + |
| 103 | (pz - tz) * (pz - tz) |
| 104 | ), |
| 105 | }; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Decode camera state from Base64URL binary format. |
no outgoing calls
no test coverage detected