genereaza un float intre lower si greater
function randomFloat(lower, greater)
return lower+math.random()*(greater-lower)
end
returneaza offset ul unui element in object space
function getPositionFromElementOffset(element, offX, offY, offZ)
local m = getElementMatrix(element)
local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]
local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
return x, y, z
end
self-made: returneaza secundele+ms gametime-ului
local secondChange = 0
local secondStart = getTickCount()
function convertTimeToSeconds()
local hour, minute = getTime()
if minute ~= secondChange then
secondChange = minute
secondStart = getTickCount()
end
return hour*60+minute+((getTickCount()-secondStart)/getMinuteDuration())
end
sterge value dintr-un table
function removeValueFromTable(table, value)
if type(table) == "table" then
for k,v in ipairs(table) then
if v == value then
table.remove(table, k)
return true
end
end
end
return false
end
limiteaza value intr-un interval
function clamp(value, min, max)
return math.max(min, math.min(value, max))
end
returneaza offset-ul unui punct bazat pe rotatie si distanta 2D
function getPointFromDistanceRotation(x, y, dist, angle)
return x+math.cos(math.rad(90-angle))*dist, y+math.sin(math.rad(90-angle))*dist
end
self-made: genereaza un cubic bezier curve in 3D
-- x, y, z - start
-- x2, y2, z2 - end
-- bx, by, bz - start handle
-- b2x, b2y, b2z - end handle
-- t - time float
function cubicBezier3D(x, y, z, x2, y2, z2, bx, by, bz, b2x, b2y, b2z, t)
local p1 = {lerp(x, bx, t), lerp(y, by, t), lerp(z, bz, t)}
local p2 = {lerp(bx, b2x, t), lerp(by, b2y, t), lerp(bz, b2z, t)}
local p3 = {lerp(b2x, x2, t), lerp(b2y, y2, t), lerp(b2z, z2, t)}
local l1 = {lerp(p1[1], p2[1], t), lerp(p1[2], p2[2], t), lerp(p1[3], p2[3], t)}
local l2 = {lerp(p2[1], p3[1], t), lerp(p2[2], p3[2], t), lerp(p2[3], p3[3], t)}
return lerp(l1[1], l2[1], t), lerp(l1[2], l2[2], t), lerp(l1[3], l2[3], t)
end
function lerp(a, b, c)
return a + (b - a) * c
end