4
* An object oriented GL/GLES Abstraction/Utility Layer
6
* Copyright (C) 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, see <http://www.gnu.org/licenses/>.
24
* Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
26
* Permission is hereby granted, free of charge, to any person obtaining a
27
* copy of this software and associated documentation files (the "Software"),
28
* to deal in the Software without restriction, including without limitation
29
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
30
* and/or sell copies of the Software, and to permit persons to whom the
31
* Software is furnished to do so, subject to the following conditions:
33
* The above copyright notice and this permission notice shall be included
34
* in all copies or substantial portions of the Software.
36
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
37
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
40
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46
* \file math/m_matrix.h
47
* Defines basic structures for matrix-handling.
53
#include <cogl-matrix.h>
58
* \name Symbolic names to some of the entries in the matrix
60
* These are handy for the viewport mapping, which is expressed as a matrix.
73
* Different kinds of 4x4 transformation matrices.
74
* We use these to select specific optimized vertex transformation routines.
77
COGL_MATRIX_TYPE_GENERAL, /**< general 4x4 matrix */
78
COGL_MATRIX_TYPE_IDENTITY, /**< identity matrix */
79
COGL_MATRIX_TYPE_3D_NO_ROT, /**< orthogonal projection and others... */
80
COGL_MATRIX_TYPE_PERSPECTIVE, /**< perspective projection matrix */
81
COGL_MATRIX_TYPE_2D, /**< 2-D transformation */
82
COGL_MATRIX_TYPE_2D_NO_ROT, /**< 2-D scale & translate only */
83
COGL_MATRIX_TYPE_3D /**< 3-D transformation */
89
* Matrix type to represent 4x4 transformation matrices.
92
float *m; /**< 16 matrix elements (16-byte aligned) */
93
float *inv; /**< optional 16-element inverse (16-byte aligned) */
94
unsigned int flags; /**< possible values determined by (of \link
95
* MatFlags MAT_FLAG_* flags\endlink)
97
enum CoglMatrixType type;
103
_math_matrix_multiply (CoglMatrix *result,
105
const CoglMatrix *b);
108
_math_matrix_multiply_array (CoglMatrix *result, const float *b);
111
_math_matrix_init_from_array (CoglMatrix *matrix, const float *array);
114
_math_matrix_translate (CoglMatrix *matrix, float x, float y, float z);
117
_math_matrix_rotate (CoglMatrix *matrix, float angle,
118
float x, float y, float z);
121
_math_matrix_scale (CoglMatrix *matrix, float x, float y, float z);
124
_math_matrix_ortho (CoglMatrix *matrix,
125
float left, float right,
126
float bottom, float top,
127
float nearval, float farval);
130
_math_matrix_frustum (CoglMatrix *matrix,
131
float left, float right,
132
float bottom, float top,
133
float nearval, float farval);
136
_math_matrix_viewport (CoglMatrix *matrix,
137
int x, int y, int width, int height,
138
float z_near, float z_far, float depth_max);
141
_math_matrix_init_identity (CoglMatrix *matrix);
144
_math_matrix_update_inverse (CoglMatrix *matrix);
147
_math_matrix_update_type_and_flags (CoglMatrix *matrix);
150
_math_matrix_print (const CoglMatrix *matrix);
153
_math_matrix_is_length_preserving (const CoglMatrix *matrix);
156
_math_matrix_has_rotation (const CoglMatrix *matrix);
159
_math_matrix_is_general_scale (const CoglMatrix *matrix);
162
_math_matrix_is_dirty (const CoglMatrix *matrix);
166
* \name Related functions that don't actually operate on CoglMatrix structs
171
_math_transposef ( float to[16], const float from[16]);
174
_math_transposed (double to[16], const double from[16]);
177
_math_transposefd (float to[16], const double from[16]);
181
* Transform a point (column vector) by a matrix: Q = M * P
183
#define TRANSFORM_POINT( Q, M, P ) \
184
Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12] * P[3]; \
185
Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13] * P[3]; \
186
Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14] * P[3]; \
187
Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15] * P[3];
190
#define TRANSFORM_POINT3( Q, M, P ) \
191
Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] * P[2] + M[12]; \
192
Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] * P[2] + M[13]; \
193
Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14]; \
194
Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15];
198
* Transform a normal (row vector) by a matrix: [NX NY NZ] = N * MAT
200
#define TRANSFORM_NORMAL( TO, N, MAT ) \
202
TO[0] = N[0] * MAT[0] + N[1] * MAT[1] + N[2] * MAT[2]; \
203
TO[1] = N[0] * MAT[4] + N[1] * MAT[5] + N[2] * MAT[6]; \
204
TO[2] = N[0] * MAT[8] + N[1] * MAT[9] + N[2] * MAT[10]; \
209
* Transform a direction by a matrix.
211
#define TRANSFORM_DIRECTION( TO, DIR, MAT ) \
213
TO[0] = DIR[0] * MAT[0] + DIR[1] * MAT[4] + DIR[2] * MAT[8]; \
214
TO[1] = DIR[0] * MAT[1] + DIR[1] * MAT[5] + DIR[2] * MAT[9]; \
215
TO[2] = DIR[0] * MAT[2] + DIR[1] * MAT[6] + DIR[2] * MAT[10];\
220
_mesa_transform_vector (float u[4], const float v[4], const float m[16]);