lovr.math.orientationToDirection

Converts a rotation in angle/axis representation into a direction vector.

x, y, z = lovr.math.orientationToDirection(angle, ax, ay, az)

Arguments

NameTypeDefaultDescription
anglenumberThe angle (in radians).
axnumber0The x component of the axis of rotation.
aynumber1The y component of the axis of rotation.
aznumber0The z component of the axis of rotation.

Returns

NameTypeDescription
xnumberThe x component of the direction vector.
ynumberThe y component of the direction vector.
znumberThe z component of the direction vector.

Example

Give Controllers laser beams.

function lovr.draw()
  for i, controller in ipairs(lovr.headset.getControllers()) do
    local x, y, z = controller:getPosition()
    local angle, ax, ay, az = controller:getOrientation()
    local dx, dy, dz = lovr.math.orientationToDirection(angle, ax, ay, az)
    local length = 2
    lovr.graphics.line(x, y, z, x + dx * length, y + dy * length, z + dz * length)
  end
end

See also