CameraMatrix4

Package: Libraries.Game.Graphics · Inherits from: Libraries.Compute.Matrix4, Libraries.Language.Object

Actions

OrthographicProjection(number left, number right, number bottom, number top, number nearPlane, number farPlane)

This action sets the matrix to an orthographic projection, which shows everything at the same size however far away it is. The box between left and right, bottom and top, and the near and far planes is mapped to the screen. The coordinate system and depth range are the game's defaults, from DeviceCoordinates.

Parameters

  • left number: The left edge of the visible area
  • right number: The right edge of the visible area
  • bottom number: The bottom edge of the visible area
  • top number: The top edge of the visible area
  • nearPlane number: The near plane
  • farPlane number: The far plane

Returns

Libraries.Compute.Matrix4: The matrix as an orthographic projection matrix

Example

use Libraries.Game.Graphics.CameraMatrix4

CameraMatrix4 matrix
matrix:OrthographicProjection(0, 100, 0, 100, 0, 1)

OrthographicProjection(number left, number right, number bottom, number top, number nearPlane, number farPlane, integer coordinateSystem, integer depthRange)

This action sets the matrix to an orthographic projection with the given coordinate system and depth range, using the constants in DeviceCoordinates. In a left-handed system the camera looks along +z, so depth grows as z grows. In a right-handed system it looks along -z, so depth grows as z shrinks. The depth range is the range the near and far planes are mapped to: 0 to 1 (Vulkan) or -1 to 1 (OpenGL).

Parameters

  • left number: The left edge of the visible area
  • right number: The right edge of the visible area
  • bottom number: The bottom edge of the visible area
  • top number: The top edge of the visible area
  • nearPlane number: The near plane
  • farPlane number: The far plane
  • coordinateSystem integer: LEFT_HANDED or RIGHT_HANDED, from DeviceCoordinates
  • depthRange integer: DEPTH_ZERO_TO_ONE or DEPTH_NEGATIVE_ONE_TO_ONE, from DeviceCoordinates

Returns

Libraries.Compute.Matrix4: The matrix as an orthographic projection matrix

Example

use Libraries.Game.Graphics.CameraMatrix4
use Libraries.Game.Graphics.DeviceCoordinates

CameraMatrix4 matrix
DeviceCoordinates ndc
matrix:OrthographicProjection(0, 100, 0, 100, 0, 1, ndc:LEFT_HANDED, ndc:DEPTH_ZERO_TO_ONE)

PerspectiveProjection(number nearPlane, number farPlane, number fieldOfViewHeight, number aspectRatio)

This action sets the matrix to a projection matrix with the near and far planes, the field of view height, and the aspect ratio.

Parameters

  • nearPlane number: The near plane
  • farPlane number: The far plane
  • fieldOfViewHeight number: The height of the field of view
  • aspectRatio number: the aspect ratio

Returns

Libraries.Compute.Matrix4: The matrix as a projection matrix

Example

use Libraries.Game.Graphics.CameraMatrix4

CameraMatrix4 matrix

matrix:SetToProjection(0, 1, 10, 2)

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

PerspectiveProjection(number nearPlane, number farPlane, number fieldOfViewHeight, number aspectRatio, integer coordinateSystem, integer depthRange)

This action sets the matrix to a projection matrix with the near and far planes, the field of view height, and the aspect ratio. The coordinate system and depth range used are defined by constants available in MatrixCoordinateSpace.

Parameters

  • nearPlane number: The near plane
  • farPlane number: The far plane
  • fieldOfViewHeight number: The height of the field of view
  • aspectRatio number: the aspect ratio
  • coordinateSystem integer: A constant from MatrixCoordinateSpace indicating which coordinate system the matrix is projecting to.
  • depthRange integer: A constant from MatrixCoordinateSpace indicating the depth range the matrix will project to.

Returns

Libraries.Compute.Matrix4: The matrix as a projection matrix

Example

use Libraries.Game.Graphics.CameraMatrix4
use Libraries.Game.Graphics.DeviceCoordinates

CameraMatrix4 matrix
DeviceCoordinates deviceCoords

matrix:SetToProjection(0, 1, 10, 2, deviceCoords:LEFT_HANDED, deviceCoords:DEPTH_ZERO_TO_ONE)

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

SetToLookAt(Libraries.Compute.Vector3 position, Libraries.Compute.Vector3 target, Libraries.Compute.Vector3 up)

This action sets the matrix to look at another matrix with a direction, target, and up vector. When multiplied with a translation matrix, we get a camera model view matrix.

Parameters

Returns

Libraries.Compute.Matrix4: the matrix

Example

use Libraries.Compute.Matrix4
use Libraries.Compute.Vector3

Matrix4 matrix
Vector3 direction
Vector3 target
Vector3 up

direction:Set(0, 0, 1)
target:Set(0, 0, 3)
up:Set(0, 1, 0)

matrix:SetToLookAt(direction, target, up)

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

SetToLookAt(Libraries.Compute.Vector3 direction, Libraries.Compute.Vector3 up)

This action sets the matrix to look at another matrix with a direction and an up vector. When multiplied with a translation matrix, we get a camera model view matrix.

Parameters

Returns

Libraries.Compute.Matrix4: the matrix

Example

use Libraries.Game.Graphics.CameraMatrix4
use Libraries.Compute.Vector3

CameraMatrix4 matrix
Vector3 direction
Vector3 up

direction:Set(0, 0, 1)
up:Set(0, 1, 0)

matrix:SetToLookAt(direction, up)

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The new matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"

Inherited Actions

71 actions from Libraries.Compute.Matrix4
3 actions from Libraries.Language.Object