From b00f73c37f6d552ae03108b0ff57ee61cf535a8d Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 5 May 2021 14:36:34 +0200 Subject: [PATCH] feat: update utils to current birb --- sonic-radiance.love/birb/utils/math.lua | 28 ++++++++++++++++++++++++ sonic-radiance.love/birb/utils/table.lua | 3 +-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/birb/utils/math.lua b/sonic-radiance.love/birb/utils/math.lua index 871bd2d..e8f884d 100644 --- a/sonic-radiance.love/birb/utils/math.lua +++ b/sonic-radiance.love/birb/utils/math.lua @@ -105,6 +105,34 @@ function Math.lengthdir(lenght, dir) return x, y end +-- 3D MATH FUNCTIONS +-- Basic math calculations for 3D + +function Math.getMiddlePoint3D(x1, y1, z1, x2, y2, z2) + local newx, newy, newz, vecx, vecy, vecz + + vecx = math.max(x1, x2) - math.min(x1, x2) + vecy = math.max(y1, y2) - math.min(y1, y2) + vecz = math.max(z1, z2) - math.min(z1, z2) + + newx = math.min(x1, x2) + (vecx / 2) + newy = math.min(y1, y2) + (vecy / 2) + newz = math.min(z1, z2) + (vecz / 2) + + return newx, newy, newz +end + +function Math.pointDistance3D(x1, y1, z1, x2, y2, z2) + local vecx, vecy, vecz + + vecx = math.max(x1, x2) - math.min(x1, x2) + vecy = math.max(y1, y2) - math.min(y1, y2) + vecz = math.max(z1, z2) - math.min(z1, z2) + + return math.sqrt(vecx^2 + vecy^2 + vecz^2) + +end + -- STRING FUNCTIONS -- Transform into string numbers diff --git a/sonic-radiance.love/birb/utils/table.lua b/sonic-radiance.love/birb/utils/table.lua index f7d4f14..e76fb92 100644 --- a/sonic-radiance.love/birb/utils/table.lua +++ b/sonic-radiance.love/birb/utils/table.lua @@ -1,8 +1,7 @@ -- loveutils.table : simple functions for table manipulation and computation. --- TODO: could be a part of loveutils.math ? --[[ - Copyright © 2019 Kazhnuz + Copyright © 2021 Kazhnuz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in