mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-30 22:02:45 -08:00
Fix acceleration adjustement and add to visualizer (#804)
This commit is contained in:
1 parent
cdb4d15d60
commit
975f340a63
4 files changed
+45
-14
No files matched your search
@@ -5,11 +5,12 @@ import { Typography } from '../commons/Typography';
|
||||
import { formatVector3 } from '../../utils/formatting';
|
||||
import { Canvas, useLoader } from '@react-three/fiber';
|
||||
import * as THREE from 'three';
|
||||
import { PerspectiveCamera } from 'three';
|
||||
import { PerspectiveCamera, Vector3 } from 'three';
|
||||
import { Button } from '../commons/Button';
|
||||
import { QuatObject } from '../../maths/quaternion';
|
||||
import { useLocalization } from '@fluent/react';
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
||||
import { Vector3Object } from '../../maths/vector3';
|
||||
|
||||
const groundColor = '#4444aa';
|
||||
|
||||
@@ -25,10 +26,12 @@ export function TrackerModel({ model }: { model: string }) {
|
||||
}
|
||||
|
||||
function SceneRenderer({
|
||||
quat: { x, y, z, w },
|
||||
quat,
|
||||
vec,
|
||||
model,
|
||||
}: {
|
||||
quat: QuatObject;
|
||||
vec: Vector3Object;
|
||||
model: string;
|
||||
}) {
|
||||
return (
|
||||
@@ -41,11 +44,33 @@ function SceneRenderer({
|
||||
>
|
||||
<ambientLight intensity={0.5} />
|
||||
<spotLight position={[20, 20, 20]} angle={0.09} penumbra={1} />
|
||||
<group quaternion={new THREE.Quaternion(x, y, z, w)}>
|
||||
<group quaternion={new THREE.Quaternion(quat.x, quat.y, quat.z, quat.w)}>
|
||||
<TrackerModel model={model}></TrackerModel>
|
||||
<axesHelper args={[10]} />
|
||||
</group>
|
||||
|
||||
<arrowHelper
|
||||
args={[
|
||||
new Vector3(-Math.sign(vec.x), 0, 0),
|
||||
new Vector3(0, 0, 0),
|
||||
Math.sqrt(Math.abs(vec.x)) * 2,
|
||||
]}
|
||||
/>
|
||||
<arrowHelper
|
||||
args={[
|
||||
new Vector3(0, Math.sign(vec.y), 0),
|
||||
new Vector3(0, 0, 0),
|
||||
Math.sqrt(Math.abs(vec.y)) * 2,
|
||||
]}
|
||||
/>
|
||||
<arrowHelper
|
||||
args={[
|
||||
new Vector3(0, 0, -Math.sign(vec.z)),
|
||||
new Vector3(0, 0, 0),
|
||||
Math.sqrt(Math.abs(vec.z)) * 2,
|
||||
]}
|
||||
/>
|
||||
|
||||
<mesh position={[0, -3, 0]} rotation={[-Math.PI / 2, 0, 0]}>
|
||||
<planeGeometry args={[50, 50, 10, 10]} />
|
||||
<meshBasicMaterial
|
||||
@@ -82,6 +107,10 @@ export function IMUVisualizerWidget({ tracker }: { tracker: TrackerDataT }) {
|
||||
tracker?.rotationIdentityAdjusted ||
|
||||
tracker?.rotation ||
|
||||
new THREE.Quaternion();
|
||||
const vec =
|
||||
tracker?.linearAcceleration ||
|
||||
tracker?.rawAcceleration ||
|
||||
new THREE.Vector3();
|
||||
|
||||
return (
|
||||
<div className="bg-background-70 flex flex-col p-3 rounded-lg gap-2">
|
||||
@@ -127,6 +156,7 @@ export function IMUVisualizerWidget({ tracker }: { tracker: TrackerDataT }) {
|
||||
</Button>
|
||||
<SceneRenderer
|
||||
quat={{ ...quat }}
|
||||
vec={{ ...vec }}
|
||||
model={
|
||||
isExtension ? '/models/extension.gltf' : '/models/tracker.gltf'
|
||||
}
|
||||
|
||||
@@ -292,15 +292,14 @@ class Tracker @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the adjusted tracker acceleration after mounting corrections.
|
||||
* Gets the world-adjusted acceleration
|
||||
*/
|
||||
fun getAcceleration(): Vector3 {
|
||||
var vec = acceleration
|
||||
if (needsReset) {
|
||||
vec = resetsHandler.getMountingAdjustedRotationFrom(rotation).sandwich(vec)
|
||||
return if (needsReset) {
|
||||
resetsHandler.getReferenceAdjustedAccel(rotation, acceleration)
|
||||
} else {
|
||||
acceleration
|
||||
}
|
||||
|
||||
return vec
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -111,10 +111,10 @@ class TrackerResetsHandler(val tracker: Tracker) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a rotation and adjusts it to mounting
|
||||
* Get the adjusted accel from yawFixZeroReference
|
||||
*/
|
||||
fun getMountingAdjustedRotationFrom(rotation: Quaternion): Quaternion {
|
||||
return rotation * mountingOrientation * mountRotFix
|
||||
fun getReferenceAdjustedAccel(rawRot: Quaternion, accel: Vector3): Vector3 {
|
||||
return (adjustToReference(rawRot) / yawFix).sandwich(accel)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.eiren.util.Util
|
||||
import io.eiren.util.collections.FastList
|
||||
import io.eiren.util.logging.LogManager
|
||||
import io.github.axisangles.ktmath.Quaternion.Companion.fromRotationVector
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import org.apache.commons.lang3.ArrayUtils
|
||||
import solarxr_protocol.rpc.ResetType
|
||||
import java.net.DatagramPacket
|
||||
@@ -276,7 +277,7 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
|
||||
tracker = connection?.getTracker(packet.sensorId)
|
||||
if (tracker == null) return
|
||||
var rot17 = packet.rotation
|
||||
rot17 = AXES_OFFSET.times(rot17)
|
||||
rot17 = AXES_OFFSET * rot17
|
||||
when (packet.dataType) {
|
||||
UDPPacket17RotationData.DATA_TYPE_NORMAL -> {
|
||||
tracker.setRotation(rot17)
|
||||
@@ -297,7 +298,8 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
|
||||
is UDPPacket4Acceleration -> {
|
||||
tracker = connection?.getTracker(packet.sensorId)
|
||||
if (tracker == null) return
|
||||
tracker.setAcceleration(packet.acceleration)
|
||||
// Switch x and y around to adjust for different axes
|
||||
tracker.setAcceleration(Vector3(packet.acceleration.y, packet.acceleration.x, packet.acceleration.z))
|
||||
}
|
||||
is UDPPacket10PingPong -> {
|
||||
if (connection == null) return
|
||||
|
||||
Reference in new issue
Block a user