Gjsify LogoGjsify Logo

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>
@record

Hierarchy

  • Matrix

Index

Constructors

Properties

ww: number
wx: number
wy: number
wz: number
xw: number
xx: number
xy: number
xz: number
yw: number
yx: number
yy: number
yz: number
zw: number
zx: number
zy: number
zz: number
name: string

Methods

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

    Returns Cogl.Matrix

  • free(): void
  • Frees a #CoglMatrix that was previously allocated via a call to cogl_matrix_copy().

    Returns void

  • frustum(left: number, right: number, bottom: number, top: number, zNear: number, zFar: number): void
  • Multiplies matrix by the given frustum perspective matrix.

    Parameters

    • left: number

      X position of the left clipping plane where it intersects the near clipping plane

    • right: number

      X position of the right clipping plane where it intersects the near clipping plane

    • bottom: number

      Y position of the bottom clipping plane where it intersects the near clipping plane

    • top: number

      Y position of the top clipping plane where it intersects the near clipping plane

    • zNear: number

      The distance to the near clipping plane (Must be positive)

    • zFar: number

      The distance to the far clipping plane (Must be positive)

    Returns void

  • getArray(): number
  • Casts matrix to a float array which can be directly passed to OpenGL.

    Returns number

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

    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.

    Returns [number, Cogl.Matrix]

  • initFromArray(array: number): void
  • Initializes matrix with the contents of array

    Parameters

    • array: number

      A linear array of 16 floats (column-major order)

    Returns void

  • initIdentity(): void
  • 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;

    
    

    Returns void

  • initTranslation(tx: number, ty: number, tz: number): void
  • 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;


    @param tx x coordinate of the translation vector
    @param ty y coordinate of the translation vector
    @param tz z coordinate of the translation vector

    Parameters

    • tx: number
    • ty: number
    • tz: number

    Returns void

  • isIdentity(): number
  • Determines if the given matrix is an identity matrix.

    Returns number

  • lookAt(eyePositionX: number, eyePositionY: number, eyePositionZ: number, objectX: number, objectY: number, objectZ: number, worldUpX: number, worldUpY: number, worldUpZ: number): void
  • 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.

    You should never look directly along the world-up vector.

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

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

    Parameters

    • eyePositionX: number

      The X coordinate to look from

    • eyePositionY: number

      The Y coordinate to look from

    • eyePositionZ: number

      The Z coordinate to look from

    • objectX: number

      The X coordinate of the object to look at

    • objectY: number

      The Y coordinate of the object to look at

    • objectZ: number

      The Z coordinate of the object to look at

    • worldUpX: number

      The X component of the world's up direction vector

    • worldUpY: number

      The Y component of the world's up direction vector

    • worldUpZ: number

      The Z component of the world's up direction vector

    Returns void

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

    It is possible to multiply the a matrix in-place, so result can be equal to a but can't be equal to b.

    Parameters

    Returns void

  • ortho(left: number, right: number, bottom: number, top: number, near: number, far: number): void
  • Multiplies matrix by a parallel projection matrix.

    Parameters

    • left: number

      The coordinate for the left clipping plane

    • right: number

      The coordinate for the right clipping plane

    • bottom: number

      The coordinate for the bottom clipping plane

    • top: number

      The coordinate for the top clipping plane

    • near: number

      The distance to the near clipping plane (will be negative if the plane is behind the viewer)

    • far: number

      The distance to the far clipping plane (will be negative if the plane is behind the viewer)

    Returns void

  • orthographic(x1: number, y1: number, x2: number, y2: number, near: number, far: number): void
  • Multiplies matrix by a parallel projection matrix.

    Parameters

    • x1: number

      The x coordinate for the first vertical clipping plane

    • y1: number

      The y coordinate for the first horizontal clipping plane

    • x2: number

      The x coordinate for the second vertical clipping plane

    • y2: number

      The y coordinate for the second horizontal clipping plane

    • near: number

      The distance to the near clipping plane (will be negative if the plane is behind the viewer)

    • far: number

      The distance to the far clipping plane (will be negative if the plane is behind the viewer)

    Returns void

  • perspective(fovY: number, aspect: number, zNear: number, zFar: number): void
  • Multiplies matrix by the described perspective matrix

    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.

    Parameters

    • fovY: number

      Vertical field of view angle in degrees.

    • aspect: number

      The (width over height) aspect ratio for display

    • zNear: number

      The distance to the near clipping plane (Must be positive, and must not be 0)

    • zFar: number

      The distance to the far clipping plane (Must be positive)

    Returns void

  • projectPoints(nComponents: number, strideIn: number, pointsIn: object, strideOut: number, pointsOut: object, nPoints: number): void
  • Projects an array of input points and writes the result to another array of output points. The input points can either have 2, 3 or 4 components each. The output points always have 4 components (known as homogenous coordinates). The output array can simply point to the input array to do the transform in-place.

    Here's an example with differing input/output strides: |[ typedef struct { float x,y; uint8_t r,g,b,a; float s,t,p; } MyInVertex; typedef struct { uint8_t r,g,b,a; float x,y,z; } MyOutVertex; MyInVertex vertices[N_VERTICES]; MyOutVertex results[N_VERTICES]; CoglMatrix matrix;

    my_load_vertices (vertices); my_get_matrix (&matrix);

    cogl_matrix_project_points (&matrix, 2, sizeof (MyInVertex), &vertices[0].x, sizeof (MyOutVertex), &results[0].x, N_VERTICES);


    @param nComponents The number of position components for each input point. (either 2, 3 or 4)
    @param strideIn The stride in bytes between input points.
    @param pointsIn A pointer to the first component of the first input point.
    @param strideOut The stride in bytes between output points.
    @param pointsOut A pointer to the first component of the first output point.
    @param nPoints The number of points to transform.

    Parameters

    • nComponents: number
    • strideIn: number
    • pointsIn: object
    • strideOut: number
    • pointsOut: object
    • nPoints: number

    Returns void

  • rotate(angle: number, x: number, y: number, z: number): void
  • Multiplies matrix with a rotation matrix that applies a rotation of angle degrees around the specified 3D vector.

    Parameters

    • angle: number

      The angle you want to rotate in degrees

    • x: number

      X component of your rotation vector

    • y: number

      Y component of your rotation vector

    • z: number

      Z component of your rotation vector

    Returns void

  • Multiplies matrix with a rotation transformation described by the given #CoglEuler.

    Parameters

    • euler: Cogl.Euler

      A euler describing a rotation

    Returns void

  • Multiplies matrix with a rotation transformation described by the given #CoglQuaternion.

    Parameters

    Returns void

  • scale(sx: number, sy: number, sz: number): void
  • Multiplies matrix with a transform matrix that scales along the X, Y and Z axis.

    Parameters

    • sx: number

      The X scale factor

    • sy: number

      The Y scale factor

    • sz: number

      The Z scale factor

    Returns void

  • transformPoint(x: number, y: number, z: number, w: number): [number, number, number, number]
  • Transforms a point whos position is given and returned as four float components.

    Parameters

    • x: number

      The X component of your points position

    • y: number

      The Y component of your points position

    • z: number

      The Z component of your points position

    • w: number

      The W component of your points position

    Returns [number, number, number, number]

  • transformPoints(nComponents: number, strideIn: number, pointsIn: object, strideOut: number, pointsOut: object, nPoints: number): void
  • Transforms an array of input points and writes the result to another array of output points. The input points can either have 2 or 3 components each. The output points always have 3 components. The output array can simply point to the input array to do the transform in-place.

    If you need to transform 4 component points see cogl_matrix_project_points().

    Here's an example with differing input/output strides: |[ typedef struct { float x,y; uint8_t r,g,b,a; float s,t,p; } MyInVertex; typedef struct { uint8_t r,g,b,a; float x,y,z; } MyOutVertex; MyInVertex vertices[N_VERTICES]; MyOutVertex results[N_VERTICES]; CoglMatrix matrix;

    my_load_vertices (vertices); my_get_matrix (&matrix);

    cogl_matrix_transform_points (&matrix, 2, sizeof (MyInVertex), &vertices[0].x, sizeof (MyOutVertex), &results[0].x, N_VERTICES);


    @param nComponents The number of position components for each input point. (either 2 or 3)
    @param strideIn The stride in bytes between input points.
    @param pointsIn A pointer to the first component of the first input point.
    @param strideOut The stride in bytes between output points.
    @param pointsOut A pointer to the first component of the first output point.
    @param nPoints The number of points to transform.

    Parameters

    • nComponents: number
    • strideIn: number
    • pointsIn: object
    • strideOut: number
    • pointsOut: object
    • nPoints: number

    Returns void

  • translate(x: number, y: number, z: number): void
  • Multiplies matrix with a transform matrix that translates along the X, Y and Z axis.

    Parameters

    • x: number

      The X translation you want to apply

    • y: number

      The Y translation you want to apply

    • z: number

      The Z translation you want to apply

    Returns void

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

    Returns void

  • view2dInFrustum(left: number, right: number, bottom: number, top: number, zNear: number, z2d: number, width2d: number, height2d: number): void
  • Multiplies matrix by a view transform that maps the 2D coordinates (0,0) top left and (width_2d,height_2d) bottom right the full viewport size. Geometry at a depth of 0 will now lie on this 2D plane.

    Note: this doesn't multiply the matrix by any projection matrix, but it assumes you have a perspective projection as defined by passing the corresponding arguments to cogl_matrix_frustum().

    Toolkits such as Clutter that mix 2D and 3D drawing can use this to create a 2D coordinate system within a 3D perspective projected view frustum.

    Parameters

    • left: number

      coord of left vertical clipping plane

    • right: number

      coord of right vertical clipping plane

    • bottom: number

      coord of bottom horizontal clipping plane

    • top: number

      coord of top horizontal clipping plane

    • zNear: number

      The distance to the near clip plane. Never pass 0 and always pass a positive number.

    • z2d: number

      The distance to the 2D plane. (Should always be positive and be between z_near and the z_far value that was passed to cogl_matrix_frustum())

    • width2d: number

      The width of the 2D coordinate system

    • height2d: number

      The height of the 2D coordinate system

    Returns void

  • view2dInPerspective(fovY: number, aspect: number, zNear: number, z2d: number, width2d: number, height2d: number): void
  • Multiplies matrix by a view transform that maps the 2D coordinates (0,0) top left and (width_2d,height_2d) bottom right the full viewport size. Geometry at a depth of 0 will now lie on this 2D plane.

    Note: this doesn't multiply the matrix by any projection matrix, but it assumes you have a perspective projection as defined by passing the corresponding arguments to cogl_matrix_perspective().

    Toolkits such as Clutter that mix 2D and 3D drawing can use this to create a 2D coordinate system within a 3D perspective projected view frustum.

    Parameters

    • fovY: number

      A field of view angle for the Y axis

    • aspect: number

      The ratio of width to height determining the field of view angle for the x axis.

    • zNear: number

      The distance to the near clip plane. Never pass 0 and always pass a positive number.

    • z2d: number

      The distance to the 2D plane. (Should always be positive and be between z_near and the z_far value that was passed to cogl_matrix_frustum())

    • width2d: number

      The width of the 2D coordinate system

    • height2d: number

      The height of the 2D coordinate system

    Returns void

  • equal(v1: object, v2: object): number
  • Compares two matrices to see if they represent the same transformation. Although internally the matrices may have different annotations associated with them and may potentially have a cached inverse matrix these are not considered in the comparison.

    Parameters

    • v1: object

      A 4x4 transformation matrix

    • v2: object

      A 4x4 transformation matrix

    Returns number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method