From c128d8ab0c6535cefb5628d036a6796c561187df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Fri, 16 Feb 2024 10:00:09 -0600 Subject: [PATCH] fix: division by 0 --- src/components/ArmorMesh/components/Armor/index.tsx | 13 +++++++------ .../components/Armor/shaders/fragment.glsl | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/components/ArmorMesh/components/Armor/index.tsx b/src/components/ArmorMesh/components/Armor/index.tsx index a46b6f96e..05647e651 100644 --- a/src/components/ArmorMesh/components/Armor/index.tsx +++ b/src/components/ArmorMesh/components/Armor/index.tsx @@ -230,12 +230,13 @@ export function ArmorMesh({ shell.caliber > 2 * (event.object.userData.thickness * thicknessCoefficient); - const normalization = twoCalibersRule - ? ((shell.normalization ?? 0) * 1.4 * shell.caliber) / - (2 * - event.object.userData.thickness * - thicknessCoefficient) - : shell.normalization ?? 0; + const normalization = + twoCalibersRule && event.object.userData.thickness > 0 + ? ((shell.normalization ?? 0) * 1.4 * shell.caliber) / + (2 * + event.object.userData.thickness * + thicknessCoefficient) + : shell.normalization ?? 0; const angled = (event.object.userData.thickness * thicknessCoefficient) / Math.cos(angle - degToRad(normalization)); diff --git a/src/components/ArmorMesh/components/Armor/shaders/fragment.glsl b/src/components/ArmorMesh/components/Armor/shaders/fragment.glsl index 17754268e..b7387df3b 100644 --- a/src/components/ArmorMesh/components/Armor/shaders/fragment.glsl +++ b/src/components/ArmorMesh/components/Armor/shaders/fragment.glsl @@ -63,7 +63,7 @@ void main() { if (isUnderSpacedArmor) { // spaced armor on the other hand, does care about angle - bool spacedArmorTwoCalibersRule = caliber > 2.0 * spacedArmorNominalThickness; + bool spacedArmorTwoCalibersRule = caliber > 2.0 * spacedArmorNominalThickness && spacedArmorNominalThickness > 0.0; float finalSpacedArmorNormalization = spacedArmorTwoCalibersRule ? (normalization * 1.4 * caliber) / (2.0 * spacedArmorNominalThickness) : normalization; float finalSpacedArmorThickness = spacedArmorNominalThickness / cos(spacedArmorAngle - finalSpacedArmorNormalization); remainingPenetration -= finalSpacedArmorThickness; @@ -79,7 +79,7 @@ void main() { remainingPenetration -= 0.5 * remainingPenetration * distanceFromSpacedArmor; } - bool coreArmorTwoCalibersRule = caliber > 2.0 * thickness; + bool coreArmorTwoCalibersRule = caliber > 2.0 * thickness && thickness > 0.0; float finalNormalization = coreArmorTwoCalibersRule ? (normalization * 1.4 * caliber) / (2.0 * thickness) : normalization; float finalCoreArmorThickness = thickness / cos(coreArmorangle - finalNormalization); float deltaPenetration = finalCoreArmorThickness - remainingPenetration;