--!native --!optimize 2 -- Compiled with roblox-ts v3.0.0 local TS = _G[script] local CFrameTools = TS.import(script, script.Parent, "cframe_tools").CFrameTools local Vector = TS.import(script, script.Parent, "classes", "vector").Vector --TODO finish local MatrixTools = {} do local _container = MatrixTools local function MultiplyMatrices(matrix_1, matrix_2) local collums_1 = #matrix_1[1] local rows_1 = #matrix_1 local collums_2 = #matrix_2[1] local rows_2 = #matrix_2 local _arg0 = collums_1 == rows_2 assert(_arg0, "matrix_1 collums should be equal matrix_2 rows") local out_matrix = table.create(rows_1) for i = 0, rows_1 - 1 do out_matrix[i + 1] = table.create(collums_2) end for y_1 = 0, rows_1 - 1 do local out_row = out_matrix[y_1 + 1] for x_2 = 0, collums_2 - 1 do local summ = 0 for x_1 = 0, collums_1 - 1 do summ += matrix_1[y_1 + 1][x_1 + 1] * matrix_2[x_1 + 1][x_2 + 1] end out_row[x_2 + 1] = summ end end return out_matrix end _container.MultiplyMatrices = MultiplyMatrices local function MultiplyNumberByVector3(matrix_1, matrix_2) local collums_1 = #matrix_1[1] local rows_1 = #matrix_1 local collums_2 = #matrix_2[1] local rows_2 = #matrix_2 local _arg0 = collums_1 == rows_2 assert(_arg0, "matrix_1 collums should be equal matrix_2 rows") local out_matrix = table.create(rows_1) for i = 0, rows_1 - 1 do out_matrix[i + 1] = table.create(collums_2) end for y_1 = 0, rows_1 - 1 do local out_row = out_matrix[y_1 + 1] for x_2 = 0, collums_2 - 1 do local summ = Vector3.zero for x_1 = 0, collums_1 - 1 do local _summ = summ local _exp = matrix_2[x_1 + 1][x_2 + 1] local _arg0_1 = matrix_1[y_1 + 1][x_1 + 1] summ = _summ + (_exp * _arg0_1) end out_row[x_2 + 1] = summ end end return out_matrix end _container.MultiplyNumberByVector3 = MultiplyNumberByVector3 local AddCFrames = CFrameTools.AddCFrames local MulCFrameByNumber = CFrameTools.MulCFrameByNumber local function MultiplyNumberByCFrame(matrix_1, matrix_2) local collums_1 = #matrix_1[1] local rows_1 = #matrix_1 local collums_2 = #matrix_2[1] local rows_2 = #matrix_2 local _arg0 = collums_1 == rows_2 assert(_arg0, "matrix_1 collums should be equal matrix_2 rows") local out_matrix = table.create(rows_1) for i = 0, rows_1 - 1 do out_matrix[i + 1] = table.create(collums_2) end for y_1 = 0, rows_1 - 1 do local out_row = out_matrix[y_1 + 1] for x_2 = 0, collums_2 - 1 do local summ = CFrame.identity for x_1 = 0, collums_1 - 1 do summ = AddCFrames(summ, MulCFrameByNumber(matrix_2[x_1 + 1][x_2 + 1], matrix_1[y_1 + 1][x_1 + 1])) end out_row[x_2 + 1] = summ end end return out_matrix end _container.MultiplyNumberByCFrame = MultiplyNumberByCFrame local function MultiplyNumberByVector(matrix_1, matrix_2) --takes the size of the virst vector local vector_size = matrix_2[1][1]:GetSize() local collums_1 = #matrix_1[1] local rows_1 = #matrix_1 local collums_2 = #matrix_2[1] local rows_2 = #matrix_2 local _arg0 = collums_1 == rows_2 assert(_arg0, "matrix_1 collums should be equal matrix_2 rows") local out_matrix = table.create(rows_1) for i = 0, rows_1 - 1 do out_matrix[i + 1] = table.create(collums_2) end for y_1 = 0, rows_1 - 1 do local out_row = out_matrix[y_1 + 1] for x_2 = 0, collums_2 - 1 do local summ = Vector:CreateWithValue(0, vector_size) for x_1 = 0, collums_1 - 1 do summ = summ:Add(matrix_2[x_1 + 1][x_2 + 1]:MulNum(matrix_1[y_1 + 1][x_1 + 1])) end out_row[x_2 + 1] = summ end end return out_matrix end _container.MultiplyNumberByVector = MultiplyNumberByVector local function MultiplyScalarByNumber(scalar, matrix) local rows = #matrix local collums = #matrix[1] local out_matrix = table.create(rows) for y = 0, rows - 1 do local row = table.create(collums) for x = 0, collums - 1 do row[x + 1] = matrix[y + 1][x + 1] * scalar end out_matrix[y + 1] = row end return out_matrix end _container.MultiplyScalarByNumber = MultiplyScalarByNumber end return { MatrixTools = MatrixTools, }