![]() |
![]() |
![]() |
Cogl Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
struct CoglMatrix; void cogl_matrix_init_identity (CoglMatrix *matrix
); void cogl_matrix_frustum (CoglMatrix *matrix
,float left
,float right
,float bottom
,float top
,float z_near
,float z_far
); void cogl_matrix_ortho (CoglMatrix *matrix
,float left
,float right
,float bottom
,float top
,float z_near
,float z_far
); void cogl_matrix_perspective (CoglMatrix *matrix
,float fov_y
,float aspect
,float z_near
,float z_far
); void cogl_matrix_transform_point (const CoglMatrix *matrix
,float *x
,float *y
,float *z
,float *w
); void cogl_matrix_multiply (CoglMatrix *result
,const CoglMatrix *a
,const CoglMatrix *b
); void cogl_matrix_rotate (CoglMatrix *matrix
,float angle
,float x
,float y
,float z
); void cogl_matrix_translate (CoglMatrix *matrix
,float x
,float y
,float z
); void cogl_matrix_scale (CoglMatrix *matrix
,float sx
,float sy
,float sz
); void cogl_matrix_init_from_array (CoglMatrix *matrix
,const float *array
); const float * cogl_matrix_get_array (const CoglMatrix *matrix
); gboolean cogl_matrix_get_inverse (const CoglMatrix *matrix
,CoglMatrix *inverse
);
Matrices are used in Cogl to describe affine model-view transforms, texture transforms, and projective transforms. This exposes a utility API that can be used for direct manipulation of these matrices.
struct CoglMatrix { /* column 0 */ float xx; float yx; float zx; float wx; /* column 1 */ float xy; float yy; float zy; float wy; /* column 2 */ float xz; float yz; float zz; float wz; /* column 3 */ float xw; float yw; float zw; float ww; };
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:
1 2 3 4 |
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
cogl_matrix_init_from_array()
.
void cogl_matrix_init_identity (CoglMatrix *matrix
);
Resets matrix to the identity matrix:
1 2 3 4 |
.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; |
|
A 4x4 transformation matrix |
void cogl_matrix_frustum (CoglMatrix *matrix
,float left
,float right
,float bottom
,float top
,float z_near
,float z_far
);
Multiplies matrix
by the given frustum perspective matrix.
|
A 4x4 transformation matrix |
|
coord of left vertical clipping plane |
|
coord of right vertical clipping plane |
|
coord of bottom horizontal clipping plane |
|
coord of top horizontal clipping plane |
|
positive distance to near depth clipping plane |
|
positive distance to far depth clipping plane |
void cogl_matrix_ortho (CoglMatrix *matrix
,float left
,float right
,float bottom
,float top
,float z_near
,float z_far
);
Multiplies matrix
by a parallel projection matrix.
|
A 4x4 transformation matrix |
|
The coordinate for the left clipping plane |
|
The coordinate for the right clipping plane |
|
The coordinate for the bottom clipping plane |
|
The coordinate for the top clipping plane |
|
The coordinate for the near clipping plane (may be negative if the plane is behind the viewer) |
|
The coordinate for the far clipping plane (may be negative if the plane is behind the viewer) |
void cogl_matrix_perspective (CoglMatrix *matrix
,float fov_y
,float aspect
,float z_near
,float z_far
);
Multiplies matrix
by the described perspective matrix
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.
|
A 4x4 transformation matrix |
|
A field of view angle for the Y axis |
|
The ratio of width to height determining the field of view angle for the x axis. |
|
The distance to the near clip plane. Never pass 0 and always pass a positive number. |
|
The distance to the far clip plane. (Should always be positive) |
void cogl_matrix_transform_point (const CoglMatrix *matrix
,float *x
,float *y
,float *z
,float *w
);
Transforms a point whos position is given and returned as four float components.
|
A 4x4 transformation matrix |
|
The X component of your points position. [inout] |
|
The Y component of your points position. [inout] |
|
The Z component of your points position. [inout] |
|
The W component of your points position. [inout] |
void cogl_matrix_multiply (CoglMatrix *result
,const CoglMatrix *a
,const CoglMatrix *b
);
Multiplies the two supplied matrices together and stores
the resulting matrix inside result
|
The address of a 4x4 matrix to store the result in |
|
A 4x4 transformation matrix |
|
A 4x4 transformation matrix |
void cogl_matrix_rotate (CoglMatrix *matrix
,float angle
,float x
,float y
,float z
);
Multiplies matrix
with a rotation matrix that applies a rotation
of angle
degrees around the specified 3D vector.
|
A 4x4 transformation matrix |
|
The angle you want to rotate in degrees |
|
X component of your rotation vector |
|
Y component of your rotation vector |
|
Z component of your rotation vector |
void cogl_matrix_translate (CoglMatrix *matrix
,float x
,float y
,float z
);
Multiplies matrix
with a transform matrix that translates along
the X, Y and Z axis.
|
A 4x4 transformation matrix |
|
The X translation you want to apply |
|
The Y translation you want to apply |
|
The Z translation you want to apply |
void cogl_matrix_scale (CoglMatrix *matrix
,float sx
,float sy
,float sz
);
Multiplies matrix
with a transform matrix that scales along the X,
Y and Z axis.
|
A 4x4 transformation matrix |
|
The X scale factor |
|
The Y scale factor |
|
The Z scale factor |
void cogl_matrix_init_from_array (CoglMatrix *matrix
,const float *array
);
Initializes matrix
with the contents of array
|
A 4x4 transformation matrix |
|
A linear array of 16 floats (column-major order) |
const float * cogl_matrix_get_array (const CoglMatrix *matrix
);
Casts matrix
to a float array which can be directly passed to OpenGL.
|
A 4x4 transformation matrix |
Returns : |
a pointer to the float array |
gboolean cogl_matrix_get_inverse (const CoglMatrix *matrix
,CoglMatrix *inverse
);
Gets the inverse transform of a given matrix and uses it to initialize a new CoglMatrix.
|
A 4x4 transformation matrix |
|
The destination for a 4x4 inverse transformation matrix. [out] |
Returns : |
TRUE if the inverse was successfully calculated or FALSE
for degenerate transformations that can't be inverted (in this case the
inverse matrix will simply be initialized with the identity matrix)
|
Since 1.2