;; this is similar to gl_look_at
;; but returns a suitable VIEW matrix
;;
;; same as fill_view_matrix but
;; instead of a target:position
;; we provide a dir:vector
(bind-func fill_view_matrix_dir
(let ((mattt:float* (alloc 16)))
(lambda (matrix:float* vEye:float* vDir vUp)
(let ((vz:float* (salloc 3))
(vy:float* (salloc 3))
(vx:float* (salloc 3))
(i 0)
(mat:float* (salloc 16))
(mtmp1:float* (salloc 16))
(vtmp1:float* (salloc 3))
(vtmp2:float* (salloc 3)))
(vnorm vDir 3 vz)
(vnorm vUp 3 vtmp2)
(vcross vtmp2 vz vtmp1)
(vnorm vtmp1 3 vx)
(vcross vz vx vy)
(pfill! mat
(pref vx 0) (pref vx 1) (pref vx 2) 0.0
(pref vy 0) (pref vy 1) (pref vy 2) 0.0
(pref vz 0) (pref vz 1) (pref vz 2) 0.0
(pref vEye 0) (pref vEye 1) (pref vEye 2) 1.0)
(minvf mat 4 matrix)
void))))