4
* An object oriented GL/GLES Abstraction/Utility Layer
6
* Copyright (C) 2008,2009 Intel Corporation.
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the
20
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
24
* Robert Bragg <robert@linux.intel.com>
27
#ifndef __COGL_MATRIX_H
28
#define __COGL_MATRIX_H
36
* @short_description: Fuctions for initializing and manipulating 4x4
39
* Matrices are used in Cogl to describe affine model-view transforms, texture
40
* transforms, and projective transforms. This exposes a utility API that can
41
* be used for direct manipulation of these matrices.
44
typedef struct _CoglMatrix CoglMatrix;
49
* A CoglMatrix holds a 4x4 transform matrix. This is a single precision,
50
* column-major matrix which means it is compatible with what OpenGL expects.
52
* A CoglMatrix can represent transforms such as, rotations, scaling,
53
* translation, sheering, and linear projections. You can combine these
54
* transforms by multiplying multiple matrices in the order you want them
57
* The transformation of a vertex (x, y, z, w) by a CoglMatrix is given by:
60
* x_new = xx * x + xy * y + xz * z + xw * w
61
* y_new = yx * x + yy * y + yz * z + yw * w
62
* z_new = zx * x + zy * y + zz * z + zw * w
63
* w_new = wx * x + wy * y + wz * z + ww * w
66
* Where w is normally 1
68
* <note>You must consider the members of the CoglMatrix structure read only,
69
* and all matrix modifications must be done via the cogl_matrix API. This
70
* allows Cogl to annotate the matrices internally. Violation of this will give
71
* undefined results. If you need to initialize a matrix with a constant other
72
* than the identity matrix you can use cogl_matrix_init_from_array().</note>
102
/* Note: we may want to extend this later with private flags
103
* and a cache of the inverse transform matrix. */
111
* cogl_matrix_init_identity:
112
* @matrix: A 4x4 transformation matrix
114
* Resets matrix to the identity matrix:
116
* .xx=1; .xy=0; .xz=0; .xw=0;
117
* .yx=0; .yy=1; .yz=0; .yw=0;
118
* .zx=0; .zy=0; .zz=1; .zw=0;
119
* .wx=0; .wy=0; .wz=0; .ww=1;
122
void cogl_matrix_init_identity (CoglMatrix *matrix);
125
* cogl_matrix_multiply:
126
* @result: The address of a 4x4 matrix to store the result in
127
* @a: A 4x4 transformation matrix
128
* @b: A 4x4 transformation matrix
130
* This function multiples the two supplied matricies together and stores
131
* the result in @result
133
void cogl_matrix_multiply (CoglMatrix *result,
135
const CoglMatrix *b);
138
* cogl_matrix_rotate:
139
* @matrix: A 4x4 transformation matrix
140
* @angle: The angle you want to rotate in degrees
141
* @x: X component of your rotation vector
142
* @y: Y component of your rotation vector
143
* @z: Z component of your rotation vector
145
* This function multiples your matrix with a rotation matrix that applies
146
* a rotation of #angle degrees around the specified 3D vector.
148
void cogl_matrix_rotate (CoglMatrix *matrix,
154
/* cogl_matrix_translate:
155
* @matrix: A 4x4 transformation matrix
156
* @x: The X translation you want to apply
157
* @y: The Y translation you want to apply
158
* @z: The Z translation you want to apply
160
* This function multiples your matrix with a transform matrix that translates
161
* along the X, Y and Z axis.
163
void cogl_matrix_translate (CoglMatrix *matrix,
170
* @matrix: A 4x4 transformation matrix
171
* @sx: The X scale factor
172
* @sy: The Y scale factor
173
* @sz: The Z scale factor
175
* This function multiples your matrix with a transform matrix that scales
176
* along the X, Y and Z axis.
178
void cogl_matrix_scale (CoglMatrix *matrix,
184
* cogl_matrix_frustum:
185
* @matrix: A 4x4 transformation matrix
186
* @left: coord of left vertical clipping plane
187
* @right: coord of right vertical clipping plane
188
* @bottom: coord of bottom horizontal clipping plane
189
* @top: coord of top horizontal clipping plane
190
* @z_near: positive distance to near depth clipping plane
191
* @z_far: positive distance to far depth clipping plane
193
* Multiplies the matrix by the given frustum perspective matrix.
195
void cogl_matrix_frustum (CoglMatrix *matrix,
204
* cogl_matrix_perspective:
205
* @matrix: A 4x4 transformation matrix
206
* @fov_y: A field of view angle for the Y axis
207
* @aspect: The ratio of width to height determining the field of view angle
209
* @z_near: The distance to the near clip plane.
210
* Never pass 0 and always pass a positive number.
211
* @z_far: The distance to the far clip plane. (Should always be positive)
213
* Multiplies the matrix by the described perspective matrix
215
* Note: you should be careful not to have to great a @z_far / @z_near ratio
216
* since that will reduce the effectiveness of depth testing since there wont
217
* be enough precision to identify the depth of objects near to each other.
220
cogl_matrix_perspective (CoglMatrix *matrix,
228
* @matrix: A 4x4 transformation matrix
229
* @left: The coordinate for the left clipping plane
230
* @right: The coordinate for the right clipping plane
231
* @bottom: The coordinate for the bottom clipping plane
232
* @top: The coordinate for the top clipping plane
233
* @z_near: The coordinate for the near clipping plane (may be negative if
234
* the plane is behind the viewer)
235
* @z_far: The coordinate for the far clipping plane (may be negative if
236
* the plane is behind the viewer)
238
* Multiples the matrix by a parallel projection matrix.
241
cogl_matrix_ortho (CoglMatrix *matrix,
250
* cogl_matrix_init_from_array:
251
* @matrix: A 4x4 transformation matrix
252
* @array: A linear array of 16 floats (column-major order)
254
* This initialises @matrix with the contents of @array
256
void cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array);
259
* cogl_matrix_get_array:
260
* @matrix: A 4x4 transformation matrix
262
* This casts a CoglMatrix to a float array which can be directly passed to
265
* Return value: a pointer to the float array
267
G_CONST_RETURN float *cogl_matrix_get_array (const CoglMatrix *matrix);
270
* cogl_matrix_transform_point:
271
* @matrix: A 4x4 transformation matrix
272
* @x: The X component of your points position [in:out]
273
* @y: The Y component of your points position [in:out]
274
* @z: The Z component of your points position [in:out]
275
* @w: The W component of your points position [in:out]
277
* This transforms a point whos position is given and returned
278
* as four float components.
281
cogl_matrix_transform_point (const CoglMatrix *matrix,
289
#endif /* __COGL_MATRIX_H */