|
|
@ -1,7 +1,7 @@ |
|
|
|
-- Create a Vector3 class |
|
|
|
-- Create a Vector3 class |
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
---@class Vector3 |
|
|
|
local Vector3 = {} |
|
|
|
local Vector3 = { } |
|
|
|
Vector3.__index = Vector3 |
|
|
|
Vector3.__index = Vector3 |
|
|
|
|
|
|
|
|
|
|
|
---@return string |
|
|
|
---@return string |
|
|
@ -69,87 +69,129 @@ function Vector3:__index(k) |
|
|
|
return Vector3[k] |
|
|
|
return Vector3[k] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field length number |
|
|
|
if k == "length" then |
|
|
|
if k == "length" then |
|
|
|
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) |
|
|
|
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field normalized Vector3 |
|
|
|
if k == "normalized" then |
|
|
|
if k == "normalized" then |
|
|
|
local length = math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) |
|
|
|
local length = math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) |
|
|
|
return Vector3:New(self.x / length, self.y / length, self.z / length) |
|
|
|
return Vector3:New(self.x / length, self.y / length, self.z / length) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field magnitude number |
|
|
|
if k == "magnitude" then |
|
|
|
if k == "magnitude" then |
|
|
|
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) |
|
|
|
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field sqrMagnitude number |
|
|
|
if k == "sqrMagnitude" then |
|
|
|
if k == "sqrMagnitude" then |
|
|
|
return self.x * self.x + self.y * self.y + self.z * self.z |
|
|
|
return self.x * self.x + self.y * self.y + self.z * self.z |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field zero Vector3 |
|
|
|
if k == "zero" then |
|
|
|
if k == "zero" then |
|
|
|
return Vector3:New(0, 0, 0) |
|
|
|
return Vector3:New(0, 0, 0) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field one Vector3 |
|
|
|
if k == "one" then |
|
|
|
if k == "one" then |
|
|
|
return Vector3:New(1, 1, 1) |
|
|
|
return Vector3:New(1, 1, 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field up Vector3 |
|
|
|
if k == "up" then |
|
|
|
if k == "up" then |
|
|
|
return Vector3:New(0, 1, 0) |
|
|
|
return Vector3:New(0, 1, 0) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field down Vector3 |
|
|
|
if k == "down" then |
|
|
|
if k == "down" then |
|
|
|
return Vector3:New(0, -1, 0) |
|
|
|
return Vector3:New(0, -1, 0) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field left Vector3 |
|
|
|
if k == "left" then |
|
|
|
if k == "left" then |
|
|
|
return Vector3:New(-1, 0, 0) |
|
|
|
return Vector3:New(-1, 0, 0) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field right Vector3 |
|
|
|
if k == "right" then |
|
|
|
if k == "right" then |
|
|
|
return Vector3:New(1, 0, 0) |
|
|
|
return Vector3:New(1, 0, 0) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field forward Vector3 |
|
|
|
if k == "forward" then |
|
|
|
if k == "forward" then |
|
|
|
return Vector3:New(0, 0, 1) |
|
|
|
return Vector3:New(0, 0, 1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field back Vector3 |
|
|
|
if k == "back" then |
|
|
|
if k == "back" then |
|
|
|
return Vector3:New(0, 0, -1) |
|
|
|
return Vector3:New(0, 0, -1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field positiveInfinity Vector3 |
|
|
|
if k == "positiveInfinity" then |
|
|
|
if k == "positiveInfinity" then |
|
|
|
return Vector3:New(math.huge, math.huge, math.huge) |
|
|
|
return Vector3:New(math.huge, math.huge, math.huge) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field negativeInfinity Vector3 |
|
|
|
if k == "negativeInfinity" then |
|
|
|
if k == "negativeInfinity" then |
|
|
|
return Vector3:New(-math.huge, -math.huge, -math.huge) |
|
|
|
return Vector3:New(-math.huge, -math.huge, -math.huge) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field nan Vector3 |
|
|
|
if k == "nan" then |
|
|
|
if k == "nan" then |
|
|
|
return Vector3:New(0 / 0, 0 / 0, 0 / 0) |
|
|
|
return Vector3:New(0 / 0, 0 / 0, 0 / 0) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field epsilon number |
|
|
|
if k == "epsilon" then |
|
|
|
if k == "epsilon" then |
|
|
|
return 1.401298E-45 |
|
|
|
return 1.401298E-45 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field maxValue number |
|
|
|
if k == "maxValue" then |
|
|
|
if k == "maxValue" then |
|
|
|
return 3.402823E+38 |
|
|
|
return 3.402823E+38 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field minValue number |
|
|
|
if k == "minValue" then |
|
|
|
if k == "minValue" then |
|
|
|
return -3.402823E+38 |
|
|
|
return -3.402823E+38 |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field x number |
|
|
|
if k == "x" then |
|
|
|
if k == "x" then |
|
|
|
return self[1] |
|
|
|
return self[1] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field y number |
|
|
|
if k == "y" then |
|
|
|
if k == "y" then |
|
|
|
return self[2] |
|
|
|
return self[2] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
---@class Vector3 |
|
|
|
|
|
|
|
---@field z number |
|
|
|
if k == "z" then |
|
|
|
if k == "z" then |
|
|
|
return self[3] |
|
|
|
return self[3] |
|
|
|
end |
|
|
|
end |
|
|
@ -272,7 +314,7 @@ function Vector3:ProjectOnPlane(planeNormal) |
|
|
|
return self - self:Project(planeNormal) |
|
|
|
return self - self:Project(planeNormal) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
---@param inDirection Vector3 |
|
|
|
---@param inNormal Vector3 |
|
|
|
---@return Vector3 |
|
|
|
---@return Vector3 |
|
|
|
function Vector3:Reflect(inNormal) |
|
|
|
function Vector3:Reflect(inNormal) |
|
|
|
return -2 * inNormal:Dot(self) * inNormal + self |
|
|
|
return -2 * inNormal:Dot(self) * inNormal + self |
|
|
|