Accumulated uncommitted work: GHOST Web backend, WebGL/GPU web layer, web workflow engine and protocol, tooling, docs and task records. Large generated evidence, user-testing archives, build snapshots and imported test assets remain untracked. Co-Authored-By: Claude Code <noreply@anthropic.com>
41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
#pragma once
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
constexpr float GHOST_NDOF_AXIS_SCALE = 1.0f / 350.0f;
|
|
|
|
struct GHOST_NDOFHIDReport {
|
|
int translation[3] = {0, 0, 0};
|
|
int rotation[3] = {0, 0, 0};
|
|
uint32_t buttons = 0;
|
|
unsigned fields = 0;
|
|
};
|
|
|
|
/* Shared RawInput/WebHID decoding; axes follow Blender's existing Win32 NDOF mapping. */
|
|
inline bool GHOST_NDOF_decode_hid(uint8_t report, const uint8_t *data, size_t size,
|
|
GHOST_NDOFHIDReport &out)
|
|
{
|
|
out = {};
|
|
if (!data) return false;
|
|
const auto axis = [&](size_t offset) -> int {
|
|
return int(int16_t(uint16_t(data[offset]) | (uint16_t(data[offset + 1]) << 8)));
|
|
};
|
|
if (report == 1 && (size == 6 || size == 12)) {
|
|
out.translation[0] = axis(0); out.translation[1] = -axis(4); out.translation[2] = axis(2);
|
|
out.fields = 1;
|
|
if (size == 12) {
|
|
out.rotation[0] = -axis(6); out.rotation[1] = axis(10); out.rotation[2] = -axis(8);
|
|
out.fields |= 2;
|
|
}
|
|
}
|
|
else if (report == 2 && size == 6) {
|
|
out.rotation[0] = -axis(0); out.rotation[1] = axis(4); out.rotation[2] = -axis(2);
|
|
out.fields = 2;
|
|
}
|
|
else if (report == 3 && size >= 1 && size <= 64) {
|
|
for (size_t i = 0; i < size && i < 4; ++i) out.buttons |= uint32_t(data[i]) << (8 * i);
|
|
out.fields = 4;
|
|
}
|
|
return out.fields != 0;
|
|
}
|