67 lines
1.2 KiB
Lua
67 lines
1.2 KiB
Lua
require "math"
|
|
|
|
function table.shallow_copy(t)
|
|
local t2 = {}
|
|
for k,v in pairs(t) do
|
|
t2[k] = v
|
|
end
|
|
return t2
|
|
end
|
|
|
|
function thisorthat(c, a, b)
|
|
if c then return a else return b end
|
|
end
|
|
|
|
function pingpong(at, over)
|
|
local c = (over - 1) * 2
|
|
if math.fmod(at, c) >= over then
|
|
return c - math.fmod(at, c)
|
|
else
|
|
return math.fmod(at, c)
|
|
end
|
|
end
|
|
|
|
function linease(c, t, d, b)
|
|
return c * t / d + b
|
|
end
|
|
|
|
function sinease(c, t, d, b)
|
|
return -c*math.cos(t/d*(math.pi/2)) + c + b
|
|
end
|
|
|
|
function vec3_cross(a, b)
|
|
return {
|
|
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
|
|
|
|
function vec3_dot(a, b)
|
|
return a.x * b.x + a.y * b.y + a.z * b.z
|
|
end
|
|
|
|
function vec3_scale(a, s)
|
|
return {
|
|
x = a.x * s,
|
|
y = a.y * s,
|
|
z = a.z * s,
|
|
}
|
|
end
|
|
|
|
function vec3_norm(a)
|
|
return vec3_scale(a, 1.0 / math.sqrt(vec3_dot(a, a)))
|
|
end
|
|
|
|
function vec3_add(a, b)
|
|
return { x = a.x + b.x, y = a.y + b.y, z = a.z + b.z }
|
|
end
|
|
|
|
function vec3_sub(a, b)
|
|
return { x = a.x - b.x, y = a.y - b.y, z = a.z - b.z }
|
|
end
|
|
|
|
function vec3_length(a)
|
|
return math.sqrt(a.x * a.x + a.y * a.y + a.z * a.z)
|
|
end
|