forked from EXT/VR180-Web-Player
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
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);
|
|
});
|