OpenGL の gluLookAt と glLoadMatrix

gluLookAtをglLoadMatrixで置き換えてみる - 三次元日誌
にあった。感謝です!


gluLookAt(p[0], p[1], p[2], t[0], t[1], t[2], u[0], u[1], u[2])
であるが、変換メソッド

require 'matrix'

def trans(p, t, u)
  pos    = Vector.elements(p)
  target = Vector.elements(t)
  up     = Vector.elements(u)
  
  z = (pos - target).normalize
  x = up.cross(z).normalize
  y =  z.cross(x).normalize
  distance = (target - pos).norm
  Matrix.columns([x.to_a + [0], y.to_a + [0], z.to_a + [-distance], [0, 0, 0, 1]])
end

glLoadMatrixd(trans(p, t, u))

と同等であるという。