MatrixProtocol

public protocol MatrixProtocol

A CoglMatrix holds a 4x4 transform matrix. This is a single precision, column-major matrix which means it is compatible with what OpenGL expects.

A CoglMatrix can represent transforms such as, rotations, scaling, translation, sheering, and linear projections. You can combine these transforms by multiplying multiple matrices in the order you want them applied.

The transformation of a vertex (x, y, z, w) by a CoglMatrix is given by:

  x_new = xx * x + xy * y + xz * z + xw * w
  y_new = yx * x + yy * y + yz * z + yw * w
  z_new = zx * x + zy * y + zz * z + zw * w
  w_new = wx * x + wy * y + wz * z + ww * w

Where w is normally 1

<note>You must consider the members of the CoglMatrix structure read only, and all matrix modifications must be done via the cogl_matrix API. This allows Cogl to annotate the matrices internally. Violation of this will give undefined results. If you need to initialize a matrix with a constant other than the identity matrix you can use cogl_matrix_init_from_array().</note>

The MatrixProtocol protocol exposes the methods and properties of an underlying CoglMatrix instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see Matrix. Alternatively, use MatrixRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying CoglMatrix instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • matrix_ptr Default implementation

    Typed pointer to the underlying CoglMatrix instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the CoglMatrix instance.

    Declaration

    Swift

    var matrix_ptr: UnsafeMutablePointer<CoglMatrix>! { get }
  • Required Initialiser for types conforming to MatrixProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

Matrix Record: MatrixProtocol extension (methods and fields)

  • copy() Extension method

    Allocates a new CoglMatrix on the heap and initializes it with the same values as matrix.

    Declaration

    Swift

    @inlinable
    func copy() -> MatrixRef!
  • free() Extension method

    Frees a CoglMatrix that was previously allocated via a call to cogl_matrix_copy().

    Declaration

    Swift

    @inlinable
    func free()
  • Multiplies matrix by the given frustum perspective matrix.

    Declaration

    Swift

    @inlinable
    func frustum(left: CFloat, right: CFloat, bottom: CFloat, top: CFloat, zNear: CFloat, zFar: CFloat)
  • getArray() Extension method

    Casts matrix to a float array which can be directly passed to OpenGL.

    Declaration

    Swift

    @inlinable
    func getArray() -> UnsafePointer<CFloat>!
  • get(inverse:) Extension method

    Gets the inverse transform of a given matrix and uses it to initialize a new CoglMatrix.

    <note>Although the first parameter is annotated as const to indicate that the transform it represents isn’t modified this function may technically save a copy of the inverse transform within the given CoglMatrix so that subsequent requests for the inverse transform may avoid costly inversion calculations.</note>

    Declaration

    Swift

    @inlinable
    func get<MatrixT>(inverse: MatrixT) -> CoglBool where MatrixT : MatrixProtocol
  • initFrom(array:) Extension method

    Initializes matrix with the contents of array

    Declaration

    Swift

    @inlinable
    func initFrom(array: UnsafePointer<CFloat>!)
  • initIdentity() Extension method

    Resets matrix to the identity matrix:

      .xx=1; .xy=0; .xz=0; .xw=0;
      .yx=0; .yy=1; .yz=0; .yw=0;
      .zx=0; .zy=0; .zz=1; .zw=0;
      .wx=0; .wy=0; .wz=0; .ww=1;
    

    Declaration

    Swift

    @inlinable
    func initIdentity()
  • initTranslation(tx:ty:tz:) Extension method

    Resets matrix to the (tx, ty, tz) translation matrix:

      .xx=1; .xy=0; .xz=0; .xw=tx;
      .yx=0; .yy=1; .yz=0; .yw=ty;
      .zx=0; .zy=0; .zz=1; .zw=tz;
      .wx=0; .wy=0; .wz=0; .ww=1;
    

    Declaration

    Swift

    @inlinable
    func initTranslation(tx: CFloat, ty: CFloat, tz: CFloat)
  • Applies a view transform matrix that positions the camera at the coordinate (eye_position_x, eye_position_y, eye_position_z) looking towards an object at the coordinate (object_x, object_y, object_z). The top of the camera is aligned to the given world up vector, which is normally simply (0, 1, 0) to map up to the positive direction of the y axis.

    Because there is a lot of missleading documentation online for gluLookAt regarding the up vector we want to try and be a bit clearer here.

    The up vector should simply be relative to your world coordinates and does not need to change as you move the eye and object positions. Many online sources may claim that the up vector needs to be perpendicular to the vector between the eye and object position (partly because the man page is somewhat missleading) but that is not necessary for this function.

    <note>You should never look directly along the world-up vector.</note>

    <note>It is assumed you are using a typical projection matrix where your origin maps to the center of your viewport.</note>

    <note>Almost always when you use this function it should be the first transform applied to a new modelview transform</note>

    Declaration

    Swift

    @inlinable
    func lookAt(eyePositionX: CFloat, eyePositionY: CFloat, eyePositionZ: CFloat, objectX: CFloat, objectY: CFloat, objectZ: CFloat, worldUpX: CFloat, worldUpY: CFloat, worldUpZ: CFloat)
  • multiply(a:b:) Extension method

    Multiplies the two supplied matrices together and stores the resulting matrix inside result.

    <note>It is possible to multiply the a matrix in-place, so result can be equal to a but can’t be equal to b.</note>

    Declaration

    Swift

    @inlinable
    func multiply<MatrixT>(a: MatrixT, b: MatrixT) where MatrixT : MatrixProtocol
  • Multiplies matrix by a parallel projection matrix.

    ortho is deprecated: Use cogl_matrix_orthographic()

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func ortho(left: CFloat, right: CFloat, bottom: CFloat, top: CFloat, near: CFloat, far: CFloat)
  • Multiplies matrix by the described perspective matrix

    <note>You should be careful not to have to great a z_far / z_near ratio since that will reduce the effectiveness of depth testing since there wont be enough precision to identify the depth of objects near to each other.</note>

    Declaration

    Swift

    @inlinable
    func perspective(fovY: CFloat, aspect: CFloat, zNear: CFloat, zFar: CFloat)
  • rotate(angle:x:y:z:) Extension method

    Multiplies matrix with a rotation matrix that applies a rotation of angle degrees around the specified 3D vector.

    Declaration

    Swift

    @inlinable
    func rotate(angle: CFloat, x: CFloat, y: CFloat, z: CFloat)
  • scale(sx:sy:sz:) Extension method

    Multiplies matrix with a transform matrix that scales along the X, Y and Z axis.

    Declaration

    Swift

    @inlinable
    func scale(sx: CFloat, sy: CFloat, sz: CFloat)
  • transformPoint(x:y:z:w:) Extension method

    Transforms a point whos position is given and returned as four float components.

    Declaration

    Swift

    @inlinable
    func transformPoint(x: UnsafeMutablePointer<CFloat>!, y: UnsafeMutablePointer<CFloat>!, z: UnsafeMutablePointer<CFloat>!, w: UnsafeMutablePointer<CFloat>!)
  • translate(x:y:z:) Extension method

    Multiplies matrix with a transform matrix that translates along the X, Y and Z axis.

    Declaration

    Swift

    @inlinable
    func translate(x: CFloat, y: CFloat, z: CFloat)
  • transpose() Extension method

    Replaces matrix with its transpose. Ie, every element (i,j) in the new matrix is taken from element (j,i) in the old matrix.

    Declaration

    Swift

    @inlinable
    func transpose()
  • debugMatrixPrint() Extension method

    Prints the contents of a CoglMatrix to stdout.

    Declaration

    Swift

    @inlinable
    func debugMatrixPrint()
  • getModelviewMatrix() Extension method

    Stores the current model-view matrix in matrix.

    get_modelview_matrix is deprecated: Use cogl_framebuffer_get_modelview_matrix() instead

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func getModelviewMatrix()
  • getProjectionMatrix() Extension method

    Stores the current projection matrix in matrix.

    get_projection_matrix is deprecated: Use cogl_framebuffer_get_projection_matrix() instead

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func getProjectionMatrix()
  • setModelviewMatrix() Extension method

    Loads matrix as the new model-view matrix.

    set_modelview_matrix is deprecated: Use cogl_framebuffer_set_modelview_matrix() instead

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func setModelviewMatrix()
  • setProjectionMatrix() Extension method

    Loads matrix as the new projection matrix.

    set_projection_matrix is deprecated: Use cogl_framebuffer_set_projection_matrix() instead

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func setProjectionMatrix()
  • transform() Extension method

    Multiplies the current model-view matrix by the given matrix.

    transform is deprecated: Use cogl_framebuffer_transform() instead

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func transform()
  • array Extension method

    Casts matrix to a float array which can be directly passed to OpenGL.

    Declaration

    Swift

    @inlinable
    var array: UnsafePointer<CFloat>! { get }
  • isIdentity Extension method

    Determines if the given matrix is an identity matrix.

    Declaration

    Swift

    @inlinable
    var isIdentity: CoglBool { get }
  • xx Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var xx: CFloat { get set }
  • yx Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var yx: CFloat { get set }
  • zx Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var zx: CFloat { get set }
  • wx Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var wx: CFloat { get set }
  • xy Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var xy: CFloat { get set }
  • yy Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var yy: CFloat { get set }
  • zy Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var zy: CFloat { get set }
  • wy Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var wy: CFloat { get set }
  • xz Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var xz: CFloat { get set }
  • yz Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var yz: CFloat { get set }
  • zz Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var zz: CFloat { get set }
  • wz Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var wz: CFloat { get set }
  • xw Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var xw: CFloat { get set }
  • yw Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var yw: CFloat { get set }
  • zw Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var zw: CFloat { get set }
  • ww Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var ww: CFloat { get set }