Merge pull request #9 from Louka3000/main

Better tracker rotation slider
This commit is contained in:
lucas lelievre authored and GitHub committed 2022-04-30 07:54:52 +02:00
commit 4eec83e5f4
1 file changed
+9 -2
+9 -2
View File
@@ -13,6 +13,7 @@ export function TrackerCard({ tracker, device }: { tracker: TrackerDataT, devic
const previousRot = useRef<{ x: number, y: number, z: number, w: number }>(tracker.rotation!)
const [velocity, setVelocity] = useState<number>(0);
const [rots, setRotation] = useState<number[]>([]);
const statusClass = useMemo(() => {
const statusMap: { [key: number]: string } = {
@@ -29,8 +30,14 @@ export function TrackerCard({ tracker, device }: { tracker: TrackerDataT, devic
useEffect(() => {
if (tracker.rotation) {
const rot = QuaternionFromQuatT(tracker.rotation).mul(QuaternionFromQuatT(previousRot.current).inverse());
const dif = Math.min(1, (rot.x**2 + rot.y**2 + rot.z**2) * 2.5)
setVelocity(dif);
const dif = Math.min(1, (rot.x ** 2 + rot.y ** 2 + rot.z ** 2) * 2.5)
// Use sum of rotation of last 3 frames (0.3sec) for smoother movement and better detection of slow movement.
if (rots.length === 3) {
rots.shift();
}
rots.push(dif);
setRotation(rots);
setVelocity(rots.reduce((a, b) => a + b));
previousRot.current = tracker.rotation;
}
}, [tracker.rotation])