forked from EXT/VR180-Web-Player
This commit is contained in:
49
tests/hand-aim.test.mjs
Normal file
49
tests/hand-aim.test.mjs
Normal 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);
|
||||
});
|
||||
Reference in New Issue
Block a user