local ffi = require("ffi")
local C = ffi.C

local math = {}

function math.hash32(x)
    return C.pxl8_hash32(x)
end

function math.mat4_identity()
    return C.pxl8_mat4_identity()
end

function math.mat4_mul(a, b)
    return C.pxl8_mat4_mul(a, b)
end

function math.mat4_translate(x, y, z)
    return C.pxl8_mat4_translate(x, y, z)
end

function math.mat4_rotate_x(angle)
    return C.pxl8_mat4_rotate_x(angle)
end

function math.mat4_rotate_y(angle)
    return C.pxl8_mat4_rotate_y(angle)
end

function math.mat4_rotate_z(angle)
    return C.pxl8_mat4_rotate_z(angle)
end

function math.mat4_scale(x, y, z)
    return C.pxl8_mat4_scale(x, y, z)
end

function math.mat4_ortho(left, right, bottom, top, near, far)
    return C.pxl8_mat4_ortho(left, right, bottom, top, near, far)
end

function math.mat4_perspective(fov, aspect, near, far)
    return C.pxl8_mat4_perspective(fov, aspect, near, far)
end

function math.mat4_lookat(eye, center, up)
    local eye_vec = ffi.new("pxl8_vec3", {x = eye[1], y = eye[2], z = eye[3]})
    local center_vec = ffi.new("pxl8_vec3", {x = center[1], y = center[2], z = center[3]})
    local up_vec = ffi.new("pxl8_vec3", {x = up[1], y = up[2], z = up[3]})
    return C.pxl8_mat4_lookat(eye_vec, center_vec, up_vec)
end

function math.bounds(x, y, w, h)
    return ffi.new("pxl8_bounds", {x = x, y = y, w = w, h = h})
end

return math
