Cogl 2.0 Reference Manual | ||||
---|---|---|---|---|
Top | Description |
CoglMatrix; void cogl_matrix_init_identity (CoglMatrix *matrix
); void cogl_matrix_init_from_array (CoglMatrix *matrix
,const float *array
); void cogl_matrix_init_translation (CoglMatrix *matrix
,float tx
,float ty
,float tz
); void cogl_matrix_init_from_quaternion (CoglMatrix *matrix
,const CoglQuaternion *quaternion
); void cogl_matrix_init_from_euler (CoglMatrix *matrix
,const CoglEuler *euler
); CoglMatrix * cogl_matrix_copy (const CoglMatrix *matrix
); CoglBool cogl_matrix_equal (const void *v1
,const void *v2
); void cogl_matrix_free (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_orthographic (CoglMatrix *matrix
,float x_1
,float y_1
,float x_2
,float y_2
,float near
,float far
); void cogl_matrix_perspective (CoglMatrix *matrix
,float fov_y
,float aspect
,float z_near
,float z_far
); void cogl_matrix_look_at (CoglMatrix *matrix
,float eye_position_x
,float eye_position_y
,float eye_position_z
,float object_x
,float object_y
,float object_z
,float world_up_x
,float world_up_y
,float world_up_z
); 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_rotate_quaternion (CoglMatrix *matrix
,const CoglQuaternion *quaternion
); void cogl_matrix_rotate_euler (CoglMatrix *matrix
,const CoglEuler *euler
); 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_transpose (CoglMatrix *matrix
); const float * cogl_matrix_get_array (const CoglMatrix *matrix
); CoglBool cogl_matrix_get_inverse (const CoglMatrix *matrix
,CoglMatrix *inverse
); void cogl_matrix_transform_point (const CoglMatrix *matrix
,float *x
,float *y
,float *z
,float *w
); void cogl_matrix_transform_points (const CoglMatrix *matrix
,int n_components
,size_t stride_in
,const void *points_in
,size_t stride_out
,void *points_out
,int n_points
); void cogl_matrix_project_points (const CoglMatrix *matrix
,int n_components
,size_t stride_in
,const void *points_in
,size_t stride_out
,void *points_out
,int n_points
); CoglBool cogl_matrix_is_identity (const CoglMatrix *matrix
);
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.
typedef struct { /* 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; } CoglMatrix;
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 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
.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_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) |
void cogl_matrix_init_translation (CoglMatrix *matrix
,float tx
,float ty
,float tz
);
Resets matrix to the (tx, ty, tz) translation matrix:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
.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; |
|
A 4x4 transformation matrix |
|
x coordinate of the translation vector |
|
y coordinate of the translation vector |
|
z coordinate of the translation vector |
Since 2.0
void cogl_matrix_init_from_quaternion (CoglMatrix *matrix
,const CoglQuaternion *quaternion
);
Initializes matrix
from a CoglQuaternion rotation.
|
A 4x4 transformation matrix |
|
A CoglQuaternion |
void cogl_matrix_init_from_euler (CoglMatrix *matrix
,const CoglEuler *euler
);
Initializes matrix
from a CoglEuler rotation.
|
A 4x4 transformation matrix |
|
A CoglEuler |
CoglMatrix * cogl_matrix_copy (const CoglMatrix *matrix
);
Allocates a new CoglMatrix on the heap and initializes it with
the same values as matrix
.
|
A 4x4 transformation matrix you want to copy |
Returns : |
A newly allocated CoglMatrix which
should be freed using cogl_matrix_free() . [transfer full]
|
Since 1.6
CoglBool cogl_matrix_equal (const void *v1
,const void *v2
);
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.
|
A 4x4 transformation matrix |
|
A 4x4 transformation matrix |
Since 1.4
void cogl_matrix_free (CoglMatrix *matrix
);
Frees a CoglMatrix that was previously allocated via a call to
cogl_matrix_copy()
.
|
A 4x4 transformation matrix you want to free |
Since 1.6
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 |
|
X position of the left clipping plane where it intersects the near clipping plane |
|
X position of the right clipping plane where it intersects the near clipping plane |
|
Y position of the bottom clipping plane where it intersects the near clipping plane |
|
Y position of the top clipping plane where it intersects the near clipping plane |
|
The distance to the near clipping plane (Must be positive) |
|
The distance to the far clipping plane (Must be positive) |
void cogl_matrix_orthographic (CoglMatrix *matrix
,float x_1
,float y_1
,float x_2
,float y_2
,float near
,float far
);
Multiplies matrix
by a parallel projection matrix.
|
A 4x4 transformation matrix |
|
The x coordinate for the first vertical clipping plane |
|
The y coordinate for the first horizontal clipping plane |
|
The x coordinate for the second vertical clipping plane |
|
The y coordinate for the second horizontal clipping plane |
|
The distance to the near clipping plane (will be negative if the plane is behind the viewer) |
|
The distance to the far clipping plane (will be negative if the plane is behind the viewer) |
Since 1.10
Stability Level: Unstable
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 |
|
Vertical field of view angle in degrees. |
|
The (width over height) aspect ratio for display |
|
The distance to the near clipping plane (Must be positive, and must not be 0) |
|
The distance to the far clipping plane (Must be positive) |
void cogl_matrix_look_at (CoglMatrix *matrix
,float eye_position_x
,float eye_position_y
,float eye_position_z
,float object_x
,float object_y
,float object_z
,float world_up_x
,float world_up_y
,float world_up_z
);
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.
|
A 4x4 transformation matrix |
|
The X coordinate to look from |
|
The Y coordinate to look from |
|
The Z coordinate to look from |
|
The X coordinate of the object to look at |
|
The Y coordinate of the object to look at |
|
The Z coordinate of the object to look at |
|
The X component of the world's up direction vector |
|
The Y component of the world's up direction vector |
|
The Z component of the world's up direction vector |
Since 1.8
Stability Level: Unstable
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
.
a
matrix in-place, so
result
can be equal to a
but can't be equal to b
.
|
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_rotate_quaternion (CoglMatrix *matrix
,const CoglQuaternion *quaternion
);
Multiplies matrix
with a rotation transformation described by the
given CoglQuaternion.
|
A 4x4 transformation matrix |
|
A quaternion describing a rotation |
Since 2.0
void cogl_matrix_rotate_euler (CoglMatrix *matrix
,const CoglEuler *euler
);
Multiplies matrix
with a rotation transformation described by the
given CoglEuler.
|
A 4x4 transformation matrix |
|
A euler describing a rotation |
Since 2.0
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_transpose (CoglMatrix *matrix
);
Replaces matrix
with its transpose. Ie, every element (i,j) in the
new matrix is taken from element (j,i) in the old matrix.
|
A CoglMatrix |
Since 1.10
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 |
CoglBool 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
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_transform_points (const CoglMatrix *matrix
,int n_components
,size_t stride_in
,const void *points_in
,size_t stride_out
,void *points_out
,int n_points
);
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
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); |
|
A transformation matrix |
|
The number of position components for each input point. (either 2 or 3) |
|
The stride in bytes between input points. |
|
A pointer to the first component of the first input point. |
|
The stride in bytes between output points. |
|
A pointer to the first component of the first output point. |
|
The number of points to transform. |
Stability Level: Unstable
void cogl_matrix_project_points (const CoglMatrix *matrix
,int n_components
,size_t stride_in
,const void *points_in
,size_t stride_out
,void *points_out
,int n_points
);
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
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); |
|
A projection matrix |
|
The number of position components for each input point. (either 2, 3 or 4) |
|
The stride in bytes between input points. |
|
A pointer to the first component of the first input point. |
|
The stride in bytes between output points. |
|
A pointer to the first component of the first output point. |
|
The number of points to transform. |
Stability Level: Unstable
CoglBool cogl_matrix_is_identity (const CoglMatrix *matrix
);
Determines if the given matrix is an identity matrix.
|
A CoglMatrix |
Returns : |
TRUE if matrix is an identity matrix else FALSE
|
Since 1.8