fix: post mid point tracer

This commit is contained in:
TrèsAbhi committed 2024-02-29 15:30:53 -06:00
1 parent 7af1fdcf6b
commit d496b46b6f
3 files changed
+25 -7

No files matched your search

@@ -29,8 +29,8 @@ const layerTypeNames: Record<ArmorType | 'null', string> = {
};
const LENGTH_INFINITY = 4;
const TRACER_THIN = 1 / 128;
const TRACER_THICK = 1 / 64;
const TRACER_THIN = TRACER_THICK / 2;
export function ShotDisplay() {
const shot = useTankopediaTemporary((state) => state.shot);
@@ -53,12 +53,22 @@ export function ShotDisplay() {
0,
shot.layers.indexOf(midPointLayer as ShotLayer),
);
const postMidPointLayers = shot?.layers.slice(
shot.layers.indexOf(midPointLayer as ShotLayer),
shot.layers.length,
);
const preMidPointGap = shot
? preMidPointLayers!.reduce((accumulator, layer) => {
if (layer.type === null) return accumulator + layer.distance;
return accumulator;
}, 0) + LENGTH_INFINITY
: undefined;
const postMidPointGap = shot
? postMidPointLayers!.reduce((accumulator, layer) => {
if (layer.type === null) return accumulator + layer.distance;
return accumulator;
}, 0) || LENGTH_INFINITY
: undefined;
useFrame(({ clock }) => {
if (!shot || !preMidPointTracer.current) return;
@@ -71,7 +81,7 @@ export function ShotDisplay() {
if (!postMidPointTracer.current) return;
postMidPointTracer.current.position.set(0, t2 * preMidPointGap!, 0);
postMidPointTracer.current.position.set(0, t2 * postMidPointGap!, 0);
postMidPointTracer.current.scale.set(1, 1 - 2 * Math.abs(t2 - 0.5), 1);
});
@@ -114,15 +124,18 @@ export function ShotDisplay() {
.multiplyScalar(-1),
)}
>
<mesh position={[0, preMidPointGap! / 2, 0]}>
<mesh position={[0, postMidPointGap! / 2, 0]}>
<cylinderGeometry
args={[TRACER_THIN, TRACER_THIN, preMidPointGap]}
args={[TRACER_THIN, TRACER_THIN, postMidPointGap]}
/>
</mesh>
<mesh position={[0, preMidPointGap! / 2, 0]} ref={postMidPointTracer}>
<mesh
position={[0, postMidPointGap! / 2, 0]}
ref={postMidPointTracer}
>
<cylinderGeometry
args={[TRACER_THICK, TRACER_THICK, preMidPointGap]}
args={[TRACER_THICK, TRACER_THICK, postMidPointGap]}
/>
<meshBasicMaterial color={0xffff00} />
</mesh>
@@ -243,7 +243,6 @@ export function SpacedArmorSceneComponent({
thickness === 0
? 0
: thickness / Math.cos(angle - finalNormalization);
remainingPenetration -= finalThickness;
if (!threeCalibersRule && angle >= ricochet) {
shot.layers.push({
@@ -279,7 +278,9 @@ export function SpacedArmorSceneComponent({
break;
} else {
remainingPenetration -= finalThickness;
const blocked = remainingPenetration < 0;
shot.layers.push({
type,
index: layerIndex,
@@ -299,6 +300,8 @@ export function SpacedArmorSceneComponent({
}
}
console.log(shot);
useTankopediaTemporary.setState({ shot });
},
})}