(bind-func rotate_matrix
(lambda (mat:float* alpha:float x:float y:float z:float)
(let ((c (cos alpha))
(c-1 (- 1.0 c))
(s (sin alpha))
(mat2:float* (salloc 16))
(mat3:float* (salloc 16))
(vec1:float* (salloc 3)) ;; axis to rotate around (normalized)
(vec2:float* (salloc 3))) ;; axis to rotate around (normalized)
(pfill! vec1 x y z)
(vnormf vec1 3 vec2)
(set! x (pref vec2 0))
(set! y (pref vec2 1))
(set! z (pref vec2 2))
(pfill! mat2
(+ (* x x c-1) c) (- (* x y c-1) (* z s)) (+ (* x z c-1) (* y s)) 0.0
(+ (* y x c-1) (* z s)) (+ (* y y c-1) c) (- (* y z c-1) (* x s)) 0.0
(- (* x z c-1) (* y s)) (+ (* y z c-1) (* x s)) (+ (* z z c-1) c) 0.0
0.0 0.0 0.0 1.0)
;;(mmulf mat2 4 4 mat 4 4 mat3)
(mmul4 mat2 mat mat3)
(memcpy (cast mat i8*) (cast mat3 i8*) (* 16 4))
void)))