1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
4import { useMemo, useRef } from 'react';
5import * as THREE from 'three';
8 calculateInterpolatedVelocity,
9} from '@/stores/scenarioStore';
10import { fersColors } from '@/theme';
11import { useDynamicScale } from '@/hooks/useDynamicScale';
13const VELOCITY_ARROW_LENGTH = 7; // Fixed base length (matches Boresight)
15interface VelocityArrowProps {
21 * Renders an arrow indicating the velocity vector of the platform.
22 * The direction indicates movement direction.
23 * Note: Length is fixed for visualization; actual speed is in properties.
25export function VelocityArrow({ platform, currentTime }: VelocityArrowProps) {
26 const groupRef = useRef<THREE.Group>(null);
28 // Apply dynamic scaling
29 useDynamicScale(groupRef);
31 const velocity = useMemo(
32 () => calculateInterpolatedVelocity(platform, currentTime),
33 [platform, currentTime]
36 const arrowHelper = useMemo(() => {
37 const speed = velocity.length();
38 // Don't render if static
39 if (speed < 0.001) return null;
41 const dir = velocity.clone().normalize();
42 const origin = new THREE.Vector3(0, 0, 0); // Local origin of the container
44 return new THREE.ArrowHelper(
47 VELOCITY_ARROW_LENGTH,
48 fersColors.physics.velocity
52 if (!arrowHelper) return null;
55 <group ref={groupRef}>
56 <primitive object={arrowHelper} />