diff --git a/gui/src/components/onboarding/pages/mounting/ManualMounting.tsx b/gui/src/components/onboarding/pages/mounting/ManualMounting.tsx index 9bb8ea4794..48bc007b9a 100644 --- a/gui/src/components/onboarding/pages/mounting/ManualMounting.tsx +++ b/gui/src/components/onboarding/pages/mounting/ManualMounting.tsx @@ -1,10 +1,14 @@ -import { useMemo, useState } from 'react'; +import { useCallback, useMemo, useState } from 'react'; import { AssignTrackerRequestT, BodyPart, RpcMessage } from 'solarxr-protocol'; import { FlatDeviceTracker } from '@/hooks/app'; import { useOnboarding } from '@/hooks/onboarding'; import { useTrackers } from '@/hooks/tracker'; import { useWebsocketAPI } from '@/hooks/websocket-api'; -import { MountingOrientationDegreesToQuatT } from '@/maths/quaternion'; +import { + MountingOrientationDegreesToQuatT, + QuaternionFromQuatT, + similarQuaternions, +} from '@/maths/quaternion'; import { Button } from '@/components/commons/Button'; import { TipBox } from '@/components/commons/TipBox'; import { Typography } from '@/components/commons/Typography'; @@ -62,10 +66,31 @@ export function ManualMountingPage() { setSelectRole(BodyPart.NONE); }; + const getCurrRotation = useCallback( + (role: BodyPart) => { + if (role === BodyPart.NONE) return undefined; + + const trackers = trackerPartGrouped[role] || []; + const [mountingOrientation, ...orientation] = trackers + .map((td) => td.tracker.info?.mountingOrientation) + .filter((orientation) => !!orientation) + .map((orientation) => QuaternionFromQuatT(orientation)); + + const identicalOrientations = + mountingOrientation !== undefined && + orientation.every((quat) => + similarQuaternions(quat, mountingOrientation) + ); + return identicalOrientations ? mountingOrientation : undefined; + }, + [trackerPartGrouped] + ); + return ( <> setSelectRole(BodyPart.NONE)} onDirectionSelected={onDirectionSelected}