Mat4

Undocumented

  • Create an identity matrix.

    Declaration

    Swift

    public static var identity: Mat4
  • return the upper left matrix

    Declaration

    Swift

    public var mat3: Mat3
  • get the the translation component

    Declaration

    Swift

    public var translation: Vec4
  • Create a scaling matrix.

    Declaration

    Swift

    public static func scale(x: Float, _ y: Float, _ z: Float = 1.0) -> Mat4

    Parameters

    x

    Amount to scale x by.

    y

    Amount to scale y by.

    z

    Amount to scale z by.

    Return Value

    A new Mat4 representing a scaling.

  • Create a 2D rotation matrix around the z-axis.

    Declaration

    Swift

    public static func rotate(degrees: Float) -> Mat4

    Parameters

    degrees

    The amount to rotate by in degrees.

    Return Value

    A new Mat4 representing a 2D rotation.

  • Create a rotation matrix around a certain axis or vector.

    Declaration

    Swift

    public static func rotateAround(axis: Vec3, _ degrees: Float) -> Mat4

    Parameters

    axis

    The axis to rotate around.

    degrees

    The angle to rotate by in degrees.

    Return Value

    A new Mat4 representing a rotation around an axis.

  • Creates a translation matrix.

    Declaration

    Swift

    public static func translate(x: Float, _ y: Float, _ z: Float = 0.0) -> Mat4

    Parameters

    x

    x amount to translate.

    y

    y amount to translate.

    z

    z amount to translate.

    Return Value

    A new Mat4 representing a translation.

  • Note

    I honestly forget how this works.

  • discussion: I’ll figure out what this is for someday. I know I used it for lighting but I forget the math and why this was required.

  • Declaration

    Swift

    public static func normalMatrix(m: Mat4, nonUniformScaling: Bool = true) -> Mat3

    Parameters

    m

    A model matrix?

    nonUniformScaling

    Whether it has been non-uniformly scaled.

    Return Value

    a Mat3 matrix representing the normals?

  • Create a matrix that transforms from world to eye coordinates.

    Declaration

    Swift

    public static func lookAt(eye: Vec3, center: Vec3, up: Vec3 = Vec3(x: 0.0, y: 1.0, z: 0.0)) -> Mat4

    Parameters

    eye

    The coordinate of the eye position.

    center

    The coordinate of the point to look at.

    up

    The up direction of the camera.

    Return Value

    A new Mat4 representing the view.

  • Create a perspective projection matrix.

    Note

    This is probably correct but I should verify it at some point. :)

    Declaration

    Swift

    public static func perspective(fovy: Float, aspect: Float, near: Float, far: Float) -> Mat4

    Parameters

    fovy

    The verticle field of view in radians.

    aspect

    The aspect ratio of the screen/viewing area.

    near

    The near clipping distance. Should be > 0.

    far

    The far clipping distance. Should be greater than near and > 0.

    Return Value

    a Mat4 matrix to be used for projection.

  • Create an orthographic projection matrix. I believe these are sane defaults for iOS/Metal. Setting only right and top should be sufficient in most cases.

    Note

    Near is set to -1.0 and far is set to 1.0 since Metal’s NDC z space is only size 1.

    Declaration

    Swift

    public static func orthographic(left: Float = 0.0, right: Float, bottom: Float = 0.0, top: Float, near: Float = -1.0, far: Float = 1.0) -> Mat4

    Parameters

    left

    The left coordinate of the projection volume.

    right

    The right coordinate of the projection volume. The width/height of the screen.

    bottom

    The bottom coordinate of the projection volume.

    top

    The top coordinate of the projection volume. The width/height of the screen.

    near

    The near coordinate of the projection volume.

    far

    The far coordinate of the projection volume. Must be greater than near.

    Return Value

    a Mat4 matrix to be used for projection.

  • Convenience init for creating a Mat4 using Vec3s.

    Note

    Need to verify what this does if not passed 4 columns.

    Declaration

    Swift

    public init(columns: Vec3 ...)

    Parameters

    columns

    The columns in the matrix.

    Return Value

    a new Mat4.