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) -> Mat4Parameters
xAmount to scale x by.
yAmount to scale y by.
zAmount to scale z by.
Return Value
A new
Mat4representing a scaling. -
Create a 2D rotation matrix around the z-axis.
Declaration
Swift
public static func rotate(degrees: Float) -> Mat4Parameters
degreesThe amount to rotate by in degrees.
Return Value
A new
Mat4representing a 2D rotation. -
Create a rotation matrix around a certain axis or vector.
Declaration
Swift
public static func rotateAround(axis: Vec3, _ degrees: Float) -> Mat4Parameters
axisThe axis to rotate around.
degreesThe angle to rotate by in degrees.
Return Value
A new
Mat4representing a rotation around an axis. -
Creates a translation matrix.
Declaration
Swift
public static func translate(x: Float, _ y: Float, _ z: Float = 0.0) -> Mat4Parameters
xx amount to translate.
yy amount to translate.
zz amount to translate.
Return Value
A new
Mat4representing 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) -> Mat3Parameters
mA model matrix?
nonUniformScalingWhether it has been non-uniformly scaled.
Return Value
a
Mat3matrix 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)) -> Mat4Parameters
eyeThe coordinate of the eye position.
centerThe coordinate of the point to look at.
upThe up direction of the camera.
Return Value
A new
Mat4representing 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) -> Mat4Parameters
fovyThe verticle field of view in radians.
aspectThe aspect ratio of the screen/viewing area.
nearThe near clipping distance. Should be > 0.
farThe far clipping distance. Should be greater than near and > 0.
Return Value
a
Mat4matrix 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) -> Mat4Parameters
leftThe left coordinate of the projection volume.
rightThe right coordinate of the projection volume. The width/height of the screen.
bottomThe bottom coordinate of the projection volume.
topThe top coordinate of the projection volume. The width/height of the screen.
nearThe near coordinate of the projection volume.
farThe far coordinate of the projection volume. Must be greater than near.
Return Value
a
Mat4matrix to be used for projection.
-
Undocumented
Mat4 Extension Reference