You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
4.7 KiB
163 lines
4.7 KiB
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
local ____exports = {}
|
|
local _, _Mekanome = ...
|
|
local Mekanome = _Mekanome
|
|
local function Create(____bindingPattern0)
|
|
local z
|
|
local y
|
|
local x
|
|
x = ____bindingPattern0.x
|
|
y = ____bindingPattern0.y
|
|
z = ____bindingPattern0.z
|
|
return {x = x, y = y, z = z}
|
|
end
|
|
local function Add(a, b)
|
|
if type(b) == "number" then
|
|
return Create({x = a.x + b, y = a.y + b, z = a.z + b})
|
|
end
|
|
return Create({x = a.x + b.x, y = a.y + b.y, z = a.z + b.z})
|
|
end
|
|
local function Subtract(a, b)
|
|
if type(b) == "number" then
|
|
return Create({x = a.x - b, y = a.y - b, z = a.z - b})
|
|
end
|
|
return Create({x = a.x - b.x, y = a.y - b.y, z = a.z - b.z})
|
|
end
|
|
local function Multiply(a, b)
|
|
if type(b) == "number" then
|
|
return Create({x = a.x * b, y = a.y * b, z = a.z * b})
|
|
end
|
|
return Create({x = a.x * b.x, y = a.y * b.y, z = a.z * b.z})
|
|
end
|
|
local function Divide(a, b)
|
|
if type(b) == "number" then
|
|
return Create({x = a.x / b, y = a.y / b, z = a.z / b})
|
|
end
|
|
return Create({x = a.x / b.x, y = a.y / b.y, z = a.z / b.z})
|
|
end
|
|
local function Equals(a, b)
|
|
return a.x == b.x and a.y == b.y and a.z == b.z
|
|
end
|
|
local function LessThan(a, b)
|
|
return a.x < b.x and a.y < b.y and a.z < b.z
|
|
end
|
|
local function LessThanOrEqualTo(a, b)
|
|
return a.x <= b.x and a.y <= b.y and a.z <= b.z
|
|
end
|
|
local function Dot(a, b)
|
|
return a.x * b.x + a.y * b.y + a.z + b.z
|
|
end
|
|
local function Cross(a, b)
|
|
return Create({x = a.y * b.z - a.z * b.y, y = a.z * b.x - a.x * b.z, z = a.x * b.y - a.y * b.x})
|
|
end
|
|
local function Distance(a, b)
|
|
return FastDistance(
|
|
a.x,
|
|
a.y,
|
|
a.z,
|
|
b.x,
|
|
b.y,
|
|
b.z
|
|
)
|
|
end
|
|
local function NormalizeOrientation(orientation)
|
|
if orientation < 0 then
|
|
local mod = orientation * -1
|
|
mod = mod % (2 * math.pi)
|
|
mod = -mod + 2 * math.pi
|
|
return mod
|
|
else
|
|
return orientation % (2 * math.pi)
|
|
end
|
|
end
|
|
local function GetAbsoluteAngle(a, b)
|
|
return NormalizeOrientation(math.atan2(b.y - a.y, b.x - a.x))
|
|
end
|
|
local function Angle(a, b)
|
|
return math.acos(Dot(a, b) / (math.sqrt(a.x * a.x + a.y * a.y + a.z * a.z) * math.sqrt(b.x * b.x + b.y * b.y + b.z * b.z)))
|
|
end
|
|
local function _GetNormalized(vector)
|
|
local length = math.sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z)
|
|
return Create({x = vector.x / length, y = vector.y / length, z = vector.z / length})
|
|
end
|
|
local function ClampMagnitude(vector, maxLength)
|
|
if Dot(vector, vector) > maxLength * maxLength then
|
|
return Multiply(
|
|
_GetNormalized(vector),
|
|
maxLength
|
|
)
|
|
else
|
|
return vector
|
|
end
|
|
end
|
|
local function _GetMagnitude(vector)
|
|
return math.sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z)
|
|
end
|
|
local function DirectionOrZero(vector)
|
|
local magnitude = _GetMagnitude(vector)
|
|
if magnitude < 1e-7 then
|
|
return Create({x = 0, y = 0, z = 0})
|
|
elseif magnitude < 1.00001 and magnitude > 0.99999 then
|
|
return vector
|
|
else
|
|
return Multiply(vector, 1 / magnitude)
|
|
end
|
|
end
|
|
local function Clamp(x, min, max)
|
|
return x < min and min or (x > max and max or x)
|
|
end
|
|
local function Lerp(a, b, _t)
|
|
local t = Clamp(_t, 0, 1)
|
|
return Create({x = a.x + (b.x - a.x) * t, y = a.y + (b.y - a.y) * t, z = a.z + (b.z - a.z) * t})
|
|
end
|
|
local function MoveTowards(reference, target, maxDistanceDelta)
|
|
local toVector = Subtract(target, reference)
|
|
local distance = _GetMagnitude(toVector)
|
|
if distance <= maxDistanceDelta or distance == 0 then
|
|
return target
|
|
end
|
|
return Divide(
|
|
Add(reference, toVector),
|
|
distance * maxDistanceDelta
|
|
)
|
|
end
|
|
local function Project(reference, normal)
|
|
local num = Dot(normal, normal)
|
|
if num < 1.401298e-45 then
|
|
return Create({x = 0, y = 0, z = 0})
|
|
end
|
|
return Multiply(
|
|
normal,
|
|
Dot(reference, normal) / num
|
|
)
|
|
end
|
|
local function ProjectOnPlane(reference, plane)
|
|
return Subtract(
|
|
reference,
|
|
Project(reference, plane)
|
|
)
|
|
end
|
|
local _VectorUtils = {
|
|
Create = Create,
|
|
Add = Add,
|
|
Subtract = Subtract,
|
|
Multiply = Multiply,
|
|
Divide = Divide,
|
|
Equals = Equals,
|
|
LessThan = LessThan,
|
|
LessThanOrEqualTo = LessThanOrEqualTo,
|
|
Dot = Dot,
|
|
Cross = Cross,
|
|
Distance = Distance,
|
|
Angle = Angle,
|
|
GetAbsoluteAngle = GetAbsoluteAngle,
|
|
ClampMagnitude = ClampMagnitude,
|
|
DirectionOrZero = DirectionOrZero,
|
|
Clamp = Clamp,
|
|
Lerp = Lerp,
|
|
MoveTowards = MoveTowards,
|
|
ProjectOnPlane = ProjectOnPlane
|
|
}
|
|
Mekanome.VectorUtils = _VectorUtils
|
|
____exports.default = {}
|
|
return ____exports
|
|
|