mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-20 17:11:20 -08:00
Merge pull request #9 from Louka3000/main
Better tracker rotation slider
This commit is contained in:
1 file changed
+9
-2
@@ -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])
|
||||
|
||||
Reference in new issue
Block a user