Update vector2.lua
This commit is contained in:
parent
219b440204
commit
420ce2bc15
@ -163,6 +163,21 @@ function vector2:dist(vector)
|
|||||||
return result:len()
|
return result:len()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- cross product for vec2 (in 3D space)
|
||||||
|
-- @param {vec2} v - The other vec2
|
||||||
|
-- @return {number} -> float || integer
|
||||||
|
-- @usage
|
||||||
|
-- local v1 = vec2(10, 15)
|
||||||
|
-- local v2 = vec2(15, 10)
|
||||||
|
-- print(v1:cross(v2)) -- Output: -125
|
||||||
|
function vector2:cross(v)
|
||||||
|
if type(v) == "number" then
|
||||||
|
print("\n(( TypeError : cross ))\nType arg cross(vec2)")
|
||||||
|
error("Invalid input argument. Expected a vec2 object.\n")
|
||||||
|
end
|
||||||
|
return self.x * v.y - self.y * v.x
|
||||||
|
end
|
||||||
|
|
||||||
-- rotate vec2
|
-- rotate vec2
|
||||||
-- @param angle {number}
|
-- @param angle {number}
|
||||||
-- @param axis {string} - axis rotate around (x, y, or z)
|
-- @param axis {string} - axis rotate around (x, y, or z)
|
||||||
@ -217,6 +232,28 @@ function vector2.__add(value_1, value_2)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- sub vec
|
||||||
|
function vector2.__sub(value_1, value_2)
|
||||||
|
if type(value_1) == "number" then
|
||||||
|
if value_1 == 0 then
|
||||||
|
return vector2:new(value_2.x, value_2.y)
|
||||||
|
else
|
||||||
|
return vector2:new(value_2.x - value_1, value_2.y - value_1)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if type(value_2) == "number" then
|
||||||
|
if value_2 == 0 then
|
||||||
|
return vector2:new(value_1.x, value_1.y)
|
||||||
|
else
|
||||||
|
return vector2:new(value_1.x - value_2, value_1.y - value_2)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return vector2:new(value_1.x - value_2.x, value_1.y - value_2.y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- mul vec
|
-- mul vec
|
||||||
function vector2.__mul(value_1, value_2)
|
function vector2.__mul(value_1, value_2)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user