lovr.math.lookAt

Returns the angle/axis orientation to use to get an object to look at a point.

angle, ax, ay, az = lovr.math.lookAt(x, y, z, tx, ty, tz, ux, uy, uz)

Arguments

NameTypeDefaultDescription
xnumberThe x position of the object.
ynumberThe y position of the object.
znumberThe z position of the object.
txnumberThe x position of the target to look at.
tynumberThe y position of the target to look at.
tznumberThe z position of the target to look at.
uxnumber0The x component of the global up vector.
uynumber1The y component of the global up vector.
uznumber0The z component of the global up vector.

Returns

NameTypeDescription
anglenumberThe number of radians to rotate around the axis of rotation.
axnumberThe x component of the axis of rotation.
aynumberThe y component of the axis of rotation.
aznumberThe z component of the axis of rotation.

Notes

With the default up vector, strange things will happen when trying to look in directions that line up with the up vector, similar to how the cameras in a first person shooter work. Sometimes this is alright, but other times you may want to keep track of the up vector of the camera as it rotates and pass that in as the up vector to avoid issues.

Example

Rotate a texture so it always faces the headset.

function lovr.load()
  eye = lovr.graphics.newTexture('texture.png')
end

function lovr.draw()
  local x, y, z = 0, 2, -2
  local angle, ax, ay, az = lovr.math.lookAt(x, y, z, lovr.headset.getPosition())
  lovr.graphics.plane(eye, x, y, z, 1, angle, ax, ay, az)
end

See also