feat: infinity aim

This commit is contained in:
tresabhi committed 2024-12-01 22:53:36 -06:00
1 parent e5ddbc7297
commit dced738055
1 file changed
+13 -10
@@ -3,7 +3,6 @@ import { clamp } from 'lodash-es';
import { useRef } from 'react'; import { useRef } from 'react';
import { import {
ArrowHelper, ArrowHelper,
AxesHelper,
Group, Group,
MeshStandardMaterial, MeshStandardMaterial,
TextureLoader, TextureLoader,
@@ -22,7 +21,6 @@ const emptyVector = new Vector2();
const modelDefinitions = await awaitableModelDefinitions; const modelDefinitions = await awaitableModelDefinitions;
export function SceneProps() { export function SceneProps() {
const shellTargetHelper = useRef<AxesHelper>(null);
const shellPathHelper = useRef<ArrowHelper>(null); const shellPathHelper = useRef<ArrowHelper>(null);
const show = TankopediaPersistent.use( const show = TankopediaPersistent.use(
(state) => state.showGrid && !state.showEnvironment, (state) => state.showGrid && !state.showEnvironment,
@@ -81,7 +79,6 @@ export function SceneProps() {
if ( if (
display !== TankopediaDisplay.ShootingRange || display !== TankopediaDisplay.ShootingRange ||
!playground.current || !playground.current ||
!shellTargetHelper.current ||
!shellPathHelper.current !shellPathHelper.current
) { ) {
return; return;
@@ -94,15 +91,22 @@ export function SceneProps() {
true, true,
); );
if (intersections.length === 0) return; let length: number;
let direction: Vector3;
const target = intersections[0].point; if (intersections.length === 0) {
const path = target.clone().sub(shellOrigin); length = 1000;
const direction = path.clone().normalize(); direction = new Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
} else {
const target = intersections[0].point;
const path = target.clone().sub(shellOrigin);
length = path.length();
direction = path.clone().normalize();
}
shellTargetHelper.current.position.copy(intersections[0].point);
shellPathHelper.current.setDirection(direction); shellPathHelper.current.setDirection(direction);
shellPathHelper.current.setLength(path.length()); shellPathHelper.current.setLength(length);
const [pitch, yaw] = applyPitchYawLimits( const [pitch, yaw] = applyPitchYawLimits(
Math.asin(direction.y), Math.asin(direction.y),
@@ -124,7 +128,6 @@ export function SceneProps() {
{display === TankopediaDisplay.ShootingRange && ( {display === TankopediaDisplay.ShootingRange && (
<> <>
<axesHelper ref={shellTargetHelper} />
<arrowHelper ref={shellPathHelper} position={shellOrigin} /> <arrowHelper ref={shellPathHelper} position={shellOrigin} />
<group ref={playground}> <group ref={playground}>