E
E
Ensiouel2019-03-24 15:22:48
OpenGL
Ensiouel, 2019-03-24 15:22:48

How does lookAt work?

I'm trying to implement a camera in a 3d game, I'm not doing it using OpenGL, but I'm trying to implement the lookAt function in another programming language, more precisely in Lua
And that's what happened, but I don't really understand what to do with this matrix next

function vec:lookAt(eye, target, upDir)
  local forward = (eye - target):normalize()
  local left = vec:cross(upDir, forward):normalize()

  local up = vec:cross(forward, left)

  matrix = { 
    left[1], up[1], forward[1], 0,
    left[2], up[2], forward[2], 0,
    left[3], up[3], forward[3], 0,
    -left[1] * eye[1] - left[2] * eye[2] - left[3] * eye[3], -up[1] * eye[1] - up[2] * eye[2] - up[3] * eye[3], -forward[1] * eye[1] - forward[2] * eye[2] - forward[3] * eye[3], 0
  }
  return matrix
end

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question