65 lines
1.5 KiB
Lua
65 lines
1.5 KiB
Lua
BF = BF or {}
|
|
|
|
BF.Vector3 = function(x, y, z)
|
|
return {x = x, y = y, z = z}
|
|
end
|
|
|
|
BF.Vector4 = function(x, y, z, w)
|
|
return {x = x, y = y, z = z, w = w}
|
|
end
|
|
|
|
BF.Vector2 = function(x, y)
|
|
return {x = x, y = y}
|
|
end
|
|
|
|
BF.Vector2Zero = CS.UnityEngine.Vector2(0, 0)
|
|
BF.Vector3Zero = CS.UnityEngine.Vector3(0, 0, 0)
|
|
BF.Vector3Right = CS.UnityEngine.Vector3(1, 0, 0)
|
|
BF.Vector3Up = CS.UnityEngine.Vector3(0, 1, 0)
|
|
BF.Vector3Forward = CS.UnityEngine.Vector3(0, 0, 1)
|
|
BF.CacheVector2 = CS.UnityEngine.Vector2(0, 0)
|
|
BF.CacheVector3 = CS.UnityEngine.Vector3(0, 0, 0)
|
|
|
|
|
|
BF.Color = function(r, g, b, a)
|
|
return {r = r, g = g, b = b, a = a}
|
|
end
|
|
|
|
BF.ColorWhite = CS.UnityEngine.Color(1, 1, 1, 1)
|
|
BF.ColorPurple = CS.UnityEngine.Color(1, 0, 1, 1)
|
|
BF.ColorWhiteAlpha = CS.UnityEngine.Color(1, 1, 1, 0)
|
|
BF.ColorBlack = CS.UnityEngine.Color(0, 0, 0, 1)
|
|
BF.ColorBlackAlpha = CS.UnityEngine.Color(0, 0, 0, 0)
|
|
|
|
|
|
BF.Vector2Cross = function (l, r)
|
|
return l.x * r.y - l.y * r.x
|
|
end
|
|
|
|
BF.Vector2Dot = function (l, r)
|
|
return l.x * r.x + l.y * r.y
|
|
end
|
|
|
|
BF.Vector2Magnitude = function(v)
|
|
return math.sqrt(v.x * v.x + v.y * v.y)
|
|
end
|
|
|
|
BF.Vector2Normalize = function (v)
|
|
local normal = BF.Vector2(0, 0)
|
|
local m = BF.Vector2Magnitude(v)
|
|
if m~=0 then
|
|
normal.x = v.x/m
|
|
normal.y = v.y/m
|
|
end
|
|
return normal
|
|
end
|
|
|
|
BF.Vector2Distance = function (v1, v2)
|
|
local deltax = v2.x - v1.x
|
|
local deltay = v2.y - v1.y
|
|
return math.sqrt(deltax*deltax + deltay*deltay)
|
|
end
|
|
|
|
BF.Vector3Magnitude = function(v)
|
|
return math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
|
|
end |