FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
BoresightArrow.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 { fersColors } from '@/theme';
7import { useDynamicScale } from '@/hooks/useDynamicScale';
8
9const BORESIGHT_LENGTH = 7; // Length of the arrow in world units.
10
11/**
12 * Renders a boresight arrow indicating the forward direction of an object.
13 * This component should be placed inside a <group> that has its rotation set
14 * to the object's orientation. The arrow points along the group's local -Z axis.
15 */
16export function BoresightArrow() {
17 const groupRef = useRef<THREE.Group>(null);
18
19 // Apply dynamic scaling
20 useDynamicScale(groupRef);
21
22 const arrowHelper = useMemo(() => {
23 const dir = new THREE.Vector3(0, 0, -1); // Points "forward" along local -Z axis.
24 const origin = new THREE.Vector3(0, 0, 0); // Arrow starts at the object's origin.
25 return new THREE.ArrowHelper(
26 dir,
27 origin,
28 BORESIGHT_LENGTH,
29 fersColors.physics.boresight
30 );
31 }, []);
32
33 // Use the <primitive> element to add the pre-built ArrowHelper object to the scene.
34 return (
35 <group ref={groupRef}>
36 <primitive object={arrowHelper} />
37 </group>
38 );
39}