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.
-
Untyped pointer to the underlying
CoglMatrixinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
matrix_ptrDefault implementationTyped pointer to the underlying
CoglMatrixinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
CoglMatrixinstance.Declaration
Swift
var matrix_ptr: UnsafeMutablePointer<CoglMatrix>! { get } -
Required Initialiser for types conforming to
MatrixProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
copy()Extension methodAllocates a new
CoglMatrixon the heap and initializes it with the same values asmatrix.Declaration
Swift
@inlinable func copy() -> MatrixRef! -
free()Extension methodFrees a
CoglMatrixthat was previously allocated via a call tocogl_matrix_copy().Declaration
Swift
@inlinable func free() -
frustum(left:Extension methodright: bottom: top: zNear: zFar: ) Multiplies
matrixby the given frustum perspective matrix.Declaration
Swift
@inlinable func frustum(left: CFloat, right: CFloat, bottom: CFloat, top: CFloat, zNear: CFloat, zFar: CFloat) -
getArray()Extension methodCasts
matrixto 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
CoglMatrixso 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
matrixwith the contents ofarrayDeclaration
Swift
@inlinable func initFrom(array: UnsafePointer<CFloat>!) -
initIdentity()Extension methodResets 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:Extension methodty: tz: ) 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) -
lookAt(eyePositionX:Extension methodeyePositionY: eyePositionZ: objectX: objectY: objectZ: worldUpX: worldUpY: worldUpZ: ) Applies a view transform
matrixthat 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:Extension methodb: ) Multiplies the two supplied matrices together and stores the resulting matrix inside
result.<note>It is possible to multiply the
amatrix in-place, soresultcan be equal toabut can’t be equal tob.</note>Declaration
Swift
@inlinable func multiply<MatrixT>(a: MatrixT, b: MatrixT) where MatrixT : MatrixProtocol -
ortho(left:Extension methodright: bottom: top: near: far: ) Multiplies
matrixby 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) -
perspective(fovY:Extension methodaspect: zNear: zFar: ) Multiplies
matrixby the described perspective matrix<note>You should be careful not to have to great a
z_far/z_nearratio 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:Extension methodx: y: z: ) Multiplies
matrixwith a rotation matrix that applies a rotation ofangledegrees around the specified 3D vector.Declaration
Swift
@inlinable func rotate(angle: CFloat, x: CFloat, y: CFloat, z: CFloat) -
scale(sx:Extension methodsy: sz: ) Multiplies
matrixwith 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:Extension methody: z: w: ) 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:Extension methody: z: ) Multiplies
matrixwith 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 methodReplaces
matrixwith 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 methodPrints the contents of a
CoglMatrixto stdout.Declaration
Swift
@inlinable func debugMatrixPrint() -
getModelviewMatrix()Extension methodStores 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 methodStores 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 methodLoads
matrixas 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 methodLoads 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 methodMultiplies the current model-view matrix by the given matrix.
transform is deprecated: Use cogl_framebuffer_transform() instead
Declaration
Swift
@available(*, deprecated) @inlinable func transform() -
arrayExtension methodCasts
matrixto a float array which can be directly passed to OpenGL.Declaration
Swift
@inlinable var array: UnsafePointer<CFloat>! { get } -
isIdentityExtension methodDetermines if the given matrix is an identity matrix.
Declaration
Swift
@inlinable var isIdentity: CoglBool { get } -
xxExtension methodUndocumented
Declaration
Swift
@inlinable var xx: CFloat { get set } -
yxExtension methodUndocumented
Declaration
Swift
@inlinable var yx: CFloat { get set } -
zxExtension methodUndocumented
Declaration
Swift
@inlinable var zx: CFloat { get set } -
wxExtension methodUndocumented
Declaration
Swift
@inlinable var wx: CFloat { get set } -
xyExtension methodUndocumented
Declaration
Swift
@inlinable var xy: CFloat { get set } -
yyExtension methodUndocumented
Declaration
Swift
@inlinable var yy: CFloat { get set } -
zyExtension methodUndocumented
Declaration
Swift
@inlinable var zy: CFloat { get set } -
wyExtension methodUndocumented
Declaration
Swift
@inlinable var wy: CFloat { get set } -
xzExtension methodUndocumented
Declaration
Swift
@inlinable var xz: CFloat { get set } -
yzExtension methodUndocumented
Declaration
Swift
@inlinable var yz: CFloat { get set } -
zzExtension methodUndocumented
Declaration
Swift
@inlinable var zz: CFloat { get set } -
wzExtension methodUndocumented
Declaration
Swift
@inlinable var wz: CFloat { get set } -
xwExtension methodUndocumented
Declaration
Swift
@inlinable var xw: CFloat { get set } -
ywExtension methodUndocumented
Declaration
Swift
@inlinable var yw: CFloat { get set } -
zwExtension methodUndocumented
Declaration
Swift
@inlinable var zw: CFloat { get set } -
wwExtension methodUndocumented
Declaration
Swift
@inlinable var ww: CFloat { get set }
View on GitHub
Install in Dash
MatrixProtocol Protocol Reference