~oem-solutions-group/unity-2d/clutter-1.0

« back to all changes in this revision

Viewing changes to clutter/cogl/cogl/cogl-matrix-mesa.h

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2010-03-21 13:27:56 UTC
  • mto: (2.1.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100321132756-nf8yd30yxo3zzwcm
Tags: upstream-1.2.2
ImportĀ upstreamĀ versionĀ 1.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Cogl
 
3
 *
 
4
 * An object oriented GL/GLES Abstraction/Utility Layer
 
5
 *
 
6
 * Copyright (C) 2009 Intel Corporation.
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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/>.
 
20
 *
 
21
 *
 
22
 */
 
23
/*
 
24
 * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
 
25
 *
 
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:
 
32
 *
 
33
 * The above copyright notice and this permission notice shall be included
 
34
 * in all copies or substantial portions of the Software.
 
35
 *
 
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.
 
42
 */
 
43
 
 
44
 
 
45
/*
 
46
 * \file math/m_matrix.h
 
47
 * Defines basic structures for matrix-handling.
 
48
 */
 
49
 
 
50
#ifndef _M_MATRIX_H
 
51
#define _M_MATRIX_H
 
52
 
 
53
#include <cogl-matrix.h>
 
54
 
 
55
#include <glib.h>
 
56
 
 
57
/*
 
58
 * \name Symbolic names to some of the entries in the matrix
 
59
 *
 
60
 * These are handy for the viewport mapping, which is expressed as a matrix.
 
61
 */
 
62
/*@{*/
 
63
#define MAT_SX 0
 
64
#define MAT_SY 5
 
65
#define MAT_SZ 10
 
66
#define MAT_TX 12
 
67
#define MAT_TY 13
 
68
#define MAT_TZ 14
 
69
/*@}*/
 
70
 
 
71
 
 
72
/*
 
73
 * Different kinds of 4x4 transformation matrices.
 
74
 * We use these to select specific optimized vertex transformation routines.
 
75
 */
 
76
enum CoglMatrixType {
 
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 */
 
84
} ;
 
85
 
 
86
 
 
87
#if 0
 
88
/*
 
89
 * Matrix type to represent 4x4 transformation matrices.
 
90
 */
 
91
typedef struct {
 
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)
 
96
                         */
 
97
   enum CoglMatrixType type;
 
98
} CoglMatrix;
 
99
#endif
 
100
 
 
101
 
 
102
void
 
103
_math_matrix_multiply (CoglMatrix *result,
 
104
                       const CoglMatrix *a,
 
105
                       const CoglMatrix *b);
 
106
 
 
107
void
 
108
_math_matrix_multiply_array (CoglMatrix *result, const float *b);
 
109
 
 
110
void
 
111
_math_matrix_init_from_array (CoglMatrix *matrix, const float *array);
 
112
 
 
113
void
 
114
_math_matrix_translate (CoglMatrix *matrix, float x, float y, float z);
 
115
 
 
116
void
 
117
_math_matrix_rotate (CoglMatrix *matrix, float angle,
 
118
                     float x, float y, float z);
 
119
 
 
120
void
 
121
_math_matrix_scale (CoglMatrix *matrix, float x, float y, float z);
 
122
 
 
123
void
 
124
_math_matrix_ortho (CoglMatrix *matrix,
 
125
                    float left, float right,
 
126
                    float bottom, float top,
 
127
                    float nearval, float farval);
 
128
 
 
129
void
 
130
_math_matrix_frustum (CoglMatrix *matrix,
 
131
                      float left, float right,
 
132
                      float bottom, float top,
 
133
                      float nearval, float farval);
 
134
 
 
135
void
 
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);
 
139
 
 
140
void
 
141
_math_matrix_init_identity (CoglMatrix *matrix);
 
142
 
 
143
gboolean
 
144
_math_matrix_update_inverse (CoglMatrix *matrix);
 
145
 
 
146
void
 
147
_math_matrix_update_type_and_flags (CoglMatrix *matrix);
 
148
 
 
149
void
 
150
_math_matrix_print (const CoglMatrix *matrix);
 
151
 
 
152
gboolean
 
153
_math_matrix_is_length_preserving (const CoglMatrix *matrix);
 
154
 
 
155
gboolean
 
156
_math_matrix_has_rotation (const CoglMatrix *matrix);
 
157
 
 
158
gboolean
 
159
_math_matrix_is_general_scale (const CoglMatrix *matrix);
 
160
 
 
161
gboolean
 
162
_math_matrix_is_dirty (const CoglMatrix *matrix);
 
163
 
 
164
 
 
165
/*
 
166
 * \name Related functions that don't actually operate on CoglMatrix structs
 
167
 */
 
168
/*@{*/
 
169
 
 
170
void
 
171
_math_transposef ( float to[16], const float from[16]);
 
172
 
 
173
void
 
174
_math_transposed (double to[16], const double from[16]);
 
175
 
 
176
void
 
177
_math_transposefd (float to[16], const double from[16]);
 
178
 
 
179
 
 
180
/*
 
181
 * Transform a point (column vector) by a matrix:   Q = M * P
 
182
 */
 
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];
 
188
 
 
189
 
 
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];
 
195
 
 
196
 
 
197
/*
 
198
 * Transform a normal (row vector) by a matrix:  [NX NY NZ] = N * MAT
 
199
 */
 
200
#define TRANSFORM_NORMAL( TO, N, MAT )                          \
 
201
do {                                                            \
 
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];      \
 
205
} while (0)
 
206
 
 
207
 
 
208
/*
 
209
 * Transform a direction by a matrix.
 
210
 */
 
211
#define TRANSFORM_DIRECTION( TO, DIR, MAT )                     \
 
212
do {                                                            \
 
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];\
 
216
} while (0)
 
217
 
 
218
 
 
219
void
 
220
_mesa_transform_vector (float u[4], const float v[4], const float m[16]);
 
221
 
 
222
 
 
223
/*@}*/
 
224
 
 
225
 
 
226
#endif