1
0

hand adjsutments
All checks were successful
Test / test (push) Successful in 9m30s

This commit is contained in:
Aiden
2026-06-10 14:32:47 +10:00
parent 5397bf1a5c
commit c1fbfd3b5e
4 changed files with 228 additions and 16 deletions

49
tests/hand-aim.test.mjs Normal file
View File

@@ -0,0 +1,49 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { computePalmAimRay } from '../vr180player/xr/hand-aim.js';
const wrist = { x: 0, y: 0, z: 0 };
const middleMetacarpal = { x: 0, y: 0.1, z: 0 };
const ringMetacarpal = { x: 0.025, y: 0.1, z: 0 };
test('computePalmAimRay points out from a right palm instead of following the index finger', () => {
const ray = computePalmAimRay({
handedness: 'right',
indexMetacarpal: { x: -0.035, y: 0.1, z: 0 },
middleMetacarpal,
pinkyMetacarpal: { x: 0.055, y: 0.1, z: 0 },
ringMetacarpal,
wrist
});
assert.ok(ray);
assert.equal(Math.round(ray.direction.x * 1000) / 1000, 0);
assert.equal(Math.round(ray.direction.y * 1000) / 1000, 0);
assert.equal(Math.round(ray.direction.z * 1000) / 1000, -1);
assert.equal(Math.round(ray.origin.z * 1000) / 1000, -0.035);
});
test('computePalmAimRay flips the palm normal for a left hand', () => {
const ray = computePalmAimRay({
handedness: 'left',
indexMetacarpal: { x: 0.035, y: 0.1, z: 0 },
middleMetacarpal,
pinkyMetacarpal: { x: -0.055, y: 0.1, z: 0 },
ringMetacarpal: { x: -0.025, y: 0.1, z: 0 },
wrist
});
assert.ok(ray);
assert.equal(Math.round(ray.direction.z * 1000) / 1000, -1);
});
test('computePalmAimRay returns null when palm joints cannot define a stable ray', () => {
assert.equal(computePalmAimRay({ handedness: 'right', wrist }), null);
assert.equal(computePalmAimRay({
handedness: 'right',
indexMetacarpal: { x: 0, y: 0.1, z: 0 },
pinkyMetacarpal: { x: 0, y: 0.1, z: 0 },
wrist
}), null);
});