local vec4 = require "vec4"

local transf = { }

function transf.new(col0, col1, col2, col3)
	return {
		col0.x, col0.y, col0.z, col0.w,
		col1.x, col1.y, col1.z, col1.w,
		col2.x, col2.y, col2.z, col2.w,
		col3.x, col3.y, col3.z, col3.w
	}
end

function transf.transl(t)
	return transf.new(
		vec4.new(1.0, .0, .0, .0),
		vec4.new(.0, 1.0, .0, .0),
		vec4.new(.0, .0, 1.0, .0),
		vec4.new(t.x, t.y, t.z, 1.0))
end

function transf.rotYCntTransl(rotY, cnt, transl)
	local sy = math.sin(rotY)
	local cy = math.cos(rotY)

	local tx = cnt.x + transl.x
	local ty = cnt.y + transl.y
	local tz = cnt.z + transl.z

	return transf.new(
		vec4.new(cy, .0, -sy, .0),
		vec4.new(.0, 1.0, .0, .0),
		vec4.new(sy, .0, cy, .0),
		vec4.new(-cy * cnt.x - sy * cnt.z + tx, -cnt.y + ty, sy * cnt.x - cy * cnt.z + tz, 1.0))

end

function transf.scaleRotZTransl(scale, rotZ, transl)
	local sz = math.sin(rotZ)
	local cz = math.cos(rotZ)

	return transf.new(
		vec4.new(scale * cz, scale * sz, .0, .0),
		vec4.new(scale * -sz, scale * cz, .0, .0),
		vec4.new(.0, .0, scale, .0),
		vec4.new(transl.x, transl.y, transl.z, 1.0))
end

return transf
