F-curves: Generating transformation matrix
Found the answer on this page:

https://www.gregslabaugh.net/publications/euler.pdf

So, basically, compute the 3x3 rotation matrix using the formula on that page, and then add the translation coefficients to make it a 4x4 matrix.

Rotation matrix = Rz(φ)Ry(θ)Rx(ψ):
cosθcosφ, sinψsinθcosφ−cosψsinφ, cosψsinθcosφ+sinψsinφ, 
cosθsinφ, sinψsinθsinφ+cosψcosφ, cosψsinθsinφ−sinψcosφ,
−sinθ, sinψcosθ, cosψcosθ