Pass:setProjection

Edit

Sets the camera projection. This can set the projection for a single view by giving its index, otherwise the projection will be set for all views. The number of views is determined by the number of array layers in the canvas textures.

The Pass returned by lovr.headset.getPass will have its views automatically configured to match the headset.






Arguments

NameTypeDescription
typeProjectionType The type of projection to set.
...number Parameters for the projection.

Returns

Nothing

Arguments

NameTypeDescription
matrixMat4 The projection matrix.

Returns

Nothing

Arguments

NameTypeDescription
viewnumber The index of the view to update.
typeProjectionType The type of projection to set.
...number Parameters for the projection.

Returns

Nothing

Arguments

NameTypeDescription
viewnumber The index of the view to update.
matrixMat4 The projection matrix.

Returns

Nothing

Arguments

NameTypeDefaultDescription
viewnumber The index of the view to update.
leftnumber The left field of view angle, in radians. Positive values are to the left of the view center.
rightnumber The right field of view angle, in radians. Positive values are to the right of the view center.
upnumber The top field of view angle, in radians. Positive values are above the view center.
downnumber The bottom field of view angle, in radians. Positive values are below the view center.
nearnumber.01 The near clipping plane distance, in meters.
farnumber0.0 The far clipping plane distance, in meters.

Returns

Nothing

Notes

By default, the projection is set by the headset. Each HMD has a specific field of view given by lovr.headset.getViewAngles, and the clipping planes can be customized with lovr.headset.setClipDistance.

Example

function lovr.draw(pass)
  -- Orthographic/2D
  pass:setProjection('orthographic')

  -- 90 degree perspective projection
  pass:setProjection('perspective', math.rad(90))

  -- Asymmetric, for 1 view
  local fov = math.rad(60) / 2
  pass:setProjection(1, fov, fov, fov, fov, .1, 0)

  -- Copying from headset
  for i = 1, lovr.headset.getViewCount() do
    local left, right, up, down = lovr.headset.getViewAngles(i)
    local near, far = lovr.headset.getClipDistance()
    pass:setProjection(i, left, right, up, down, near, far)
  end
end

See also