FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
VelocityArrow.tsx
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
3
4import { useMemo, useRef } from 'react';
5import * as THREE from 'three';
6import {
7 Platform,
8 calculateInterpolatedVelocity,
9} from '@/stores/scenarioStore';
10import { fersColors } from '@/theme';
11import { useDynamicScale } from '@/hooks/useDynamicScale';
12
13const VELOCITY_ARROW_LENGTH = 7; // Fixed base length (matches Boresight)
14
15interface VelocityArrowProps {
16 platform: Platform;
17 currentTime: number;
18}
19
20/**
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.
24 */
25export function VelocityArrow({ platform, currentTime }: VelocityArrowProps) {
26 const groupRef = useRef<THREE.Group>(null);
27
28 // Apply dynamic scaling
29 useDynamicScale(groupRef);
30
31 const velocity = useMemo(
32 () => calculateInterpolatedVelocity(platform, currentTime),
33 [platform, currentTime]
34 );
35
36 const arrowHelper = useMemo(() => {
37 const speed = velocity.length();
38 // Don't render if static
39 if (speed < 0.001) return null;
40
41 const dir = velocity.clone().normalize();
42 const origin = new THREE.Vector3(0, 0, 0); // Local origin of the container
43
44 return new THREE.ArrowHelper(
45 dir,
46 origin,
47 VELOCITY_ARROW_LENGTH,
48 fersColors.physics.velocity
49 );
50 }, [velocity]);
51
52 if (!arrowHelper) return null;
53
54 return (
55 <group ref={groupRef}>
56 <primitive object={arrowHelper} />
57 </group>
58 );
59}