Matrix
Object Hierarchy:
Description:
[ CCode ( type_id = "COGL_TYPE_MATRIX" ) ]
public struct Matrix
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
Matrix.from_array.
Content:
Static methods:
Creation methods:
- public Matrix.from_array (float[] array)
Initializes this with the contents of
array
- public Matrix.identity ()
Resets matrix to the identity matrix:
- public Matrix.multiply (Matrix a, Matrix b)
Multiplies the two supplied matrices together and stores the resulting
matrix inside this.
Methods:
- public void frustum (float left, float right, float bottom, float top, float z_near, float z_far)
Multiplies this by the given frustum
perspective matrix.
- public unowned float[] get_array ()
Casts this to a float array which can be
directly passed to OpenGL.
- public bool get_inverse (out Matrix inverse)
Gets the inverse transform of a given matrix and uses it to initialize a new
Matrix.
- public void ortho (float left, float right, float bottom, float top, float z_near, float z_far)
Multiplies this by a parallel projection
matrix.
- public void perspective (float fov_y, float aspect, float z_near, float z_far)
Multiplies this by the described
perspective matrix
- public void rotate (float angle, float x, float y, float z)
Multiplies this with a rotation matrix
that applies a rotation of angle
degrees around the specified 3D vector.
- public void scale (float sx, float sy, float sz)
Multiplies this with a transform matrix
that scales along the X, Y and Z axis.
- public void transform_point (ref float x, ref float y, ref float z, ref float w)
Transforms a point whos position is given and returned as four float
components.
- public void translate (float x, float y, float z)
Multiplies this with a transform matrix
that translates along the X, Y and Z axis.
Fields: