blob: bb7c6e837f2fefad015d29ed26aaa115819adf66 [file] [log] [blame]
Jason Sams044e2ee2011-08-08 16:52:30 -07001/*
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -07002 * Copyright (C) 2015 The Android Open Source Project
Jason Sams044e2ee2011-08-08 16:52:30 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -070017// Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070018
19/*
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070020 * rs_matrix.rsh: Matrix Functions
Jason Sams044e2ee2011-08-08 16:52:30 -070021 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070022 * These functions let you manipulate square matrices of rank 2x2, 3x3, and 4x4.
23 * They are particularly useful for graphical transformations and are
24 * compatible with OpenGL.
25 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070026 * We use a zero-based index for rows and columns. E.g. the last element of
27 * a rs_matrix4x4 is found at (3, 3).
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070028 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070029 * RenderScript uses column-major matrices and column-based vectors.
30 * Transforming a vector is done by postmultiplying the vector,
31 * e.g. (matrix * vector), as provided by rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070032 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070033 * To create a transformation matrix that performs two transformations at
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070034 * once, multiply the two source matrices, with the first transformation as the
35 * right argument. E.g. to create a transformation matrix that applies the
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070036 * transformation s1 followed by s2, call rsMatrixLoadMultiply(&combined, &s2, &s1).
37 * This derives from s2 * (s1 * v), which is (s2 * s1) * v.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070038 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070039 * We have two style of functions to create transformation matrices:
40 * rsMatrixLoadTransformation and rsMatrixTransformation. The
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070041 * former style simply stores the transformation matrix in the first argument.
42 * The latter modifies a pre-existing transformation matrix so that the new
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070043 * transformation happens first. E.g. if you call rsMatrixTranslate()
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -070044 * on a matrix that already does a scaling, the resulting matrix when applied
45 * to a vector will first do the translation then the scaling.
Jason Sams044e2ee2011-08-08 16:52:30 -070046 */
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -070047
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070048#ifndef RENDERSCRIPT_RS_MATRIX_RSH
49#define RENDERSCRIPT_RS_MATRIX_RSH
Jason Sams044e2ee2011-08-08 16:52:30 -070050
Jean-Luc Brouilletbe216382015-03-22 12:44:27 -070051#include "rs_vector_math.rsh"
52
53/*
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -070054 * rsExtractFrustumPlanes: Compute frustum planes
55 *
Jean-Luc Brouilletbe216382015-03-22 12:44:27 -070056 * Computes 6 frustum planes from the view projection matrix
57 *
58 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -070059 * viewProj: matrix to extract planes from
60 * left: left plane
61 * right: right plane
62 * top: top plane
63 * bottom: bottom plane
64 * near: near plane
65 * far: far plane
Jean-Luc Brouilletbe216382015-03-22 12:44:27 -070066 */
67static inline void __attribute__((always_inline, overloadable))
68 rsExtractFrustumPlanes(const rs_matrix4x4* viewProj, float4* left, float4* right, float4* top,
69 float4* bottom, float4* near, float4* far) {
70 // x y z w = a b c d in the plane equation
71 left->x = viewProj->m[3] + viewProj->m[0];
72 left->y = viewProj->m[7] + viewProj->m[4];
73 left->z = viewProj->m[11] + viewProj->m[8];
74 left->w = viewProj->m[15] + viewProj->m[12];
75
76 right->x = viewProj->m[3] - viewProj->m[0];
77 right->y = viewProj->m[7] - viewProj->m[4];
78 right->z = viewProj->m[11] - viewProj->m[8];
79 right->w = viewProj->m[15] - viewProj->m[12];
80
81 top->x = viewProj->m[3] - viewProj->m[1];
82 top->y = viewProj->m[7] - viewProj->m[5];
83 top->z = viewProj->m[11] - viewProj->m[9];
84 top->w = viewProj->m[15] - viewProj->m[13];
85
86 bottom->x = viewProj->m[3] + viewProj->m[1];
87 bottom->y = viewProj->m[7] + viewProj->m[5];
88 bottom->z = viewProj->m[11] + viewProj->m[9];
89 bottom->w = viewProj->m[15] + viewProj->m[13];
90
91 near->x = viewProj->m[3] + viewProj->m[2];
92 near->y = viewProj->m[7] + viewProj->m[6];
93 near->z = viewProj->m[11] + viewProj->m[10];
94 near->w = viewProj->m[15] + viewProj->m[14];
95
96 far->x = viewProj->m[3] - viewProj->m[2];
97 far->y = viewProj->m[7] - viewProj->m[6];
98 far->z = viewProj->m[11] - viewProj->m[10];
99 far->w = viewProj->m[15] - viewProj->m[14];
100
101 float len = length(left->xyz);
102 *left /= len;
103 len = length(right->xyz);
104 *right /= len;
105 len = length(top->xyz);
106 *top /= len;
107 len = length(bottom->xyz);
108 *bottom /= len;
109 len = length(near->xyz);
110 *near /= len;
111 len = length(far->xyz);
112 *far /= len;
113}
114
115/*
Jean-Luc Brouillet20b27d62015-04-03 14:39:53 -0700116 * rsIsSphereInFrustum: Checks if a sphere is within the frustum planes
117 *
118 * Returns true if the sphere is within the 6 frustum planes.
Jean-Luc Brouilletbe216382015-03-22 12:44:27 -0700119 *
120 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700121 * sphere: float4 representing the sphere
122 * left: left plane
123 * right: right plane
124 * top: top plane
125 * bottom: bottom plane
126 * near: near plane
127 * far: far plane
Jean-Luc Brouilletbe216382015-03-22 12:44:27 -0700128 */
129static inline bool __attribute__((always_inline, overloadable))
130 rsIsSphereInFrustum(float4* sphere, float4* left, float4* right, float4* top, float4* bottom,
131 float4* near, float4* far) {
132 float distToCenter = dot(left->xyz, sphere->xyz) + left->w;
133 if (distToCenter < -sphere->w) {
134 return false;
135 }
136 distToCenter = dot(right->xyz, sphere->xyz) + right->w;
137 if (distToCenter < -sphere->w) {
138 return false;
139 }
140 distToCenter = dot(top->xyz, sphere->xyz) + top->w;
141 if (distToCenter < -sphere->w) {
142 return false;
143 }
144 distToCenter = dot(bottom->xyz, sphere->xyz) + bottom->w;
145 if (distToCenter < -sphere->w) {
146 return false;
147 }
148 distToCenter = dot(near->xyz, sphere->xyz) + near->w;
149 if (distToCenter < -sphere->w) {
150 return false;
151 }
152 distToCenter = dot(far->xyz, sphere->xyz) + far->w;
153 if (distToCenter < -sphere->w) {
154 return false;
155 }
156 return true;
157}
158
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700159/*
160 * rsMatrixGet: Get one element
Jason Sams044e2ee2011-08-08 16:52:30 -0700161 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700162 * Returns one element of a matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700163 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700164 * Warning: The order of the column and row parameters may be unexpected.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700165 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700166 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700167 * m: The matrix to extract the element from.
168 * col: The zero-based column of the element to be extracted.
169 * row: The zero-based row of the element to extracted.
Jason Sams044e2ee2011-08-08 16:52:30 -0700170 */
Jean-Luc Brouillet129c1472015-03-02 15:37:07 -0800171extern float __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700172 rsMatrixGet(const rs_matrix4x4* m, uint32_t col, uint32_t row);
Jason Sams044e2ee2011-08-08 16:52:30 -0700173
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700174extern float __attribute__((overloadable))
175 rsMatrixGet(const rs_matrix3x3* m, uint32_t col, uint32_t row);
Jason Sams044e2ee2011-08-08 16:52:30 -0700176
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700177extern float __attribute__((overloadable))
178 rsMatrixGet(const rs_matrix2x2* m, uint32_t col, uint32_t row);
179
180/*
181 * rsMatrixInverse: Inverts a matrix in place
Jason Sams044e2ee2011-08-08 16:52:30 -0700182 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700183 * Returns true if the matrix was successfully inverted.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700184 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700185 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700186 * m: The matrix to invert.
Jason Sams044e2ee2011-08-08 16:52:30 -0700187 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700188extern bool __attribute__((overloadable))
189 rsMatrixInverse(rs_matrix4x4* m);
190
191/*
192 * rsMatrixInverseTranspose: Inverts and transpose a matrix in place
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700193 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700194 * The matrix is first inverted then transposed.
195 * Returns true if the matrix was successfully inverted.
196 *
197 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700198 * m: The matrix to modify.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700199 */
200extern bool __attribute__((overloadable))
201 rsMatrixInverseTranspose(rs_matrix4x4* m);
202
203/*
204 * rsMatrixLoad: Load or copy a matrix
205 *
206 * Set the elements of a matrix from an array of floats or from another matrix.
207 *
208 * If loading from an array, the floats should be in row-major order, i.e. the element a
209 * row 0, column 0 should be first, followed by the element at
210 * row 0, column 1, etc.
211 *
212 * If loading from a matrix and the source is smaller than the destination, the rest of the
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700213 * destination is filled with elements of the identity matrix. E.g.
214 * loading a rs_matrix2x2 into a rs_matrix4x4 will give:
215 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700216 * m00 m01 0.0 0.0
217 * m10 m11 0.0 0.0
218 * 0.0 0.0 1.0 0.0
219 * 0.0 0.0 0.0 1.0
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700220 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700221 *
222 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700223 * destination: The matrix to set.
224 * array: The array of values to set the matrix to. These arrays should be 4, 9, or 16 floats long, depending on the matrix size.
225 * source: The source matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700226 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700227extern void __attribute__((overloadable))
228 rsMatrixLoad(rs_matrix4x4* destination, const float* array);
Jason Sams044e2ee2011-08-08 16:52:30 -0700229
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700230extern void __attribute__((overloadable))
231 rsMatrixLoad(rs_matrix3x3* destination, const float* array);
232
233extern void __attribute__((overloadable))
234 rsMatrixLoad(rs_matrix2x2* destination, const float* array);
235
236extern void __attribute__((overloadable))
237 rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix4x4* source);
238
239extern void __attribute__((overloadable))
240 rsMatrixLoad(rs_matrix3x3* destination, const rs_matrix3x3* source);
241
242extern void __attribute__((overloadable))
243 rsMatrixLoad(rs_matrix2x2* destination, const rs_matrix2x2* source);
244
245extern void __attribute__((overloadable))
246 rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix3x3* source);
247
248extern void __attribute__((overloadable))
249 rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix2x2* source);
250
251/*
252 * rsMatrixLoadFrustum: Load a frustum projection matrix
253 *
254 * Constructs a frustum projection matrix, transforming the box
255 * identified by the six clipping planes left, right, bottom, top,
256 * near, far.
257 *
258 * To apply this projection to a vector, multiply the vector by the
259 * created matrix using rsMatrixMultiply().
260 *
261 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700262 * m: The matrix to set.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700263 */
264extern void __attribute__((overloadable))
265 rsMatrixLoadFrustum(rs_matrix4x4* m, float left, float right, float bottom, float top,
266 float near, float far);
267
268/*
269 * rsMatrixLoadIdentity: Load identity matrix
270 *
271 * Set the elements of a matrix to the identity matrix.
272 *
273 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700274 * m: The matrix to set.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700275 */
276extern void __attribute__((overloadable))
277 rsMatrixLoadIdentity(rs_matrix4x4* m);
278
279extern void __attribute__((overloadable))
280 rsMatrixLoadIdentity(rs_matrix3x3* m);
281
282extern void __attribute__((overloadable))
283 rsMatrixLoadIdentity(rs_matrix2x2* m);
284
285/*
286 * rsMatrixLoadMultiply: Multiply two matrices
287 *
288 * Sets m to the matrix product of lhs * rhs.
289 *
290 * To combine two 4x4 transformaton matrices, multiply the second transformation matrix
291 * by the first transformation matrix. E.g. to create a transformation matrix that applies
292 * the transformation s1 followed by s2, call
293 * rsMatrixLoadMultiply(&combined, &s2, &s1).
294 *
295 * Warning: Prior to version 21, storing the result back into right matrix is not supported and
296 * will result in undefined behavior. Use rsMatrixMulitply instead. E.g. instead of doing
297 * rsMatrixLoadMultiply (&m2r, &m2r, &m2l), use rsMatrixMultiply (&m2r, &m2l).
298 * rsMatrixLoadMultiply (&m2l, &m2r, &m2l) works as expected.
299 *
300 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700301 * m: The matrix to set.
302 * lhs: The left matrix of the product.
303 * rhs: The right matrix of the product.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700304 */
305extern void __attribute__((overloadable))
306 rsMatrixLoadMultiply(rs_matrix4x4* m, const rs_matrix4x4* lhs, const rs_matrix4x4* rhs);
307
308extern void __attribute__((overloadable))
309 rsMatrixLoadMultiply(rs_matrix3x3* m, const rs_matrix3x3* lhs, const rs_matrix3x3* rhs);
310
311extern void __attribute__((overloadable))
312 rsMatrixLoadMultiply(rs_matrix2x2* m, const rs_matrix2x2* lhs, const rs_matrix2x2* rhs);
313
314/*
315 * rsMatrixLoadOrtho: Load an orthographic projection matrix
316 *
317 * Constructs an orthographic projection matrix, transforming the box
318 * identified by the six clipping planes left, right, bottom, top,
319 * near, far into a unit cube with a corner at
320 * (-1, -1, -1) and the opposite at (1, 1, 1).
321 *
322 * To apply this projection to a vector, multiply the vector by the
323 * created matrix using rsMatrixMultiply().
324 *
325 * See https://en.wikipedia.org/wiki/Orthographic_projection .
326 *
327 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700328 * m: The matrix to set.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700329 */
330extern void __attribute__((overloadable))
331 rsMatrixLoadOrtho(rs_matrix4x4* m, float left, float right, float bottom, float top, float near,
332 float far);
333
334/*
335 * rsMatrixLoadPerspective: Load a perspective projection matrix
336 *
337 * Constructs a perspective projection matrix, assuming a symmetrical field of view.
338 *
339 * To apply this projection to a vector, multiply the vector by the
340 * created matrix using rsMatrixMultiply().
341 *
342 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700343 * m: The matrix to set.
344 * fovy: Field of view, in degrees along the Y axis.
345 * aspect: Ratio of x / y.
346 * near: The near clipping plane.
347 * far: The far clipping plane.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700348 */
349extern void __attribute__((overloadable))
350 rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
351
352/*
353 * rsMatrixLoadRotate: Load a rotation matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700354 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700355 * This function creates a rotation matrix. The axis of rotation is the
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700356 * (x, y, z) vector.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700357 *
358 * To rotate a vector, multiply the vector by the created matrix
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700359 * using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700360 *
361 * See http://en.wikipedia.org/wiki/Rotation_matrix .
362 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700363 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700364 * m: The matrix to set.
365 * rot: How much rotation to do, in degrees.
366 * x: The x component of the vector that is the axis of rotation.
367 * y: The y component of the vector that is the axis of rotation.
368 * z: The z component of the vector that is the axis of rotation.
Jason Sams044e2ee2011-08-08 16:52:30 -0700369 */
370extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700371 rsMatrixLoadRotate(rs_matrix4x4* m, float rot, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700372
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700373/*
374 * rsMatrixLoadScale: Load a scaling matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700375 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700376 * This function creates a scaling matrix, where each component of a
377 * vector is multiplied by a number. This number can be negative.
378 *
379 * To scale a vector, multiply the vector by the created matrix
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700380 * using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700381 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700382 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700383 * m: The matrix to set.
384 * x: The multiple to scale the x components by.
385 * y: The multiple to scale the y components by.
386 * z: The multiple to scale the z components by.
Jason Sams044e2ee2011-08-08 16:52:30 -0700387 */
388extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700389 rsMatrixLoadScale(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700390
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700391/*
392 * rsMatrixLoadTranslate: Load a translation matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700393 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700394 * This function creates a translation matrix, where a
395 * number is added to each element of a vector.
396 *
397 * To translate a vector, multiply the vector by the created matrix
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700398 * using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700399 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700400 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700401 * m: The matrix to set.
402 * x: The number to add to each x component.
403 * y: The number to add to each y component.
404 * z: The number to add to each z component.
Jason Sams044e2ee2011-08-08 16:52:30 -0700405 */
406extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700407 rsMatrixLoadTranslate(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700408
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700409/*
410 * rsMatrixMultiply: Multiply a matrix by a vector or another matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700411 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700412 * For the matrix by matrix variant, sets m to the matrix product m * rhs.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700413 *
414 * When combining two 4x4 transformation matrices using this function, the resulting
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700415 * matrix will correspond to performing the rhs transformation first followed by
416 * the original m transformation.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700417 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700418 * For the matrix by vector variant, returns the post-multiplication of the vector
419 * by the matrix, ie. m * in.
420 *
421 * When multiplying a float3 to a rs_matrix4x4, the vector is expanded with (1).
422 *
423 * When multiplying a float2 to a rs_matrix4x4, the vector is expanded with (0, 1).
424 *
425 * When multiplying a float2 to a rs_matrix3x3, the vector is expanded with (0).
426 *
427 * Starting with API 14, this function takes a const matrix as the first argument.
428 *
429 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700430 * m: The left matrix of the product and the matrix to be set.
431 * rhs: The right matrix of the product.
Jason Sams044e2ee2011-08-08 16:52:30 -0700432 */
433extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700434 rsMatrixMultiply(rs_matrix4x4* m, const rs_matrix4x4* rhs);
Jason Sams044e2ee2011-08-08 16:52:30 -0700435
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700436extern void __attribute__((overloadable))
437 rsMatrixMultiply(rs_matrix3x3* m, const rs_matrix3x3* rhs);
438
439extern void __attribute__((overloadable))
440 rsMatrixMultiply(rs_matrix2x2* m, const rs_matrix2x2* rhs);
441
442#if !defined(RS_VERSION) || (RS_VERSION <= 13)
443extern float4 __attribute__((overloadable))
444 rsMatrixMultiply(rs_matrix4x4* m, float4 in);
445#endif
446
447#if !defined(RS_VERSION) || (RS_VERSION <= 13)
448extern float4 __attribute__((overloadable))
449 rsMatrixMultiply(rs_matrix4x4* m, float3 in);
450#endif
451
452#if !defined(RS_VERSION) || (RS_VERSION <= 13)
453extern float4 __attribute__((overloadable))
454 rsMatrixMultiply(rs_matrix4x4* m, float2 in);
455#endif
456
457#if !defined(RS_VERSION) || (RS_VERSION <= 13)
458extern float3 __attribute__((overloadable))
459 rsMatrixMultiply(rs_matrix3x3* m, float3 in);
460#endif
461
462#if !defined(RS_VERSION) || (RS_VERSION <= 13)
463extern float3 __attribute__((overloadable))
464 rsMatrixMultiply(rs_matrix3x3* m, float2 in);
465#endif
466
467#if !defined(RS_VERSION) || (RS_VERSION <= 13)
468extern float2 __attribute__((overloadable))
469 rsMatrixMultiply(rs_matrix2x2* m, float2 in);
470#endif
471
472#if (defined(RS_VERSION) && (RS_VERSION >= 14))
473extern float4 __attribute__((overloadable))
474 rsMatrixMultiply(const rs_matrix4x4* m, float4 in);
475#endif
476
477#if (defined(RS_VERSION) && (RS_VERSION >= 14))
478extern float4 __attribute__((overloadable))
479 rsMatrixMultiply(const rs_matrix4x4* m, float3 in);
480#endif
481
482#if (defined(RS_VERSION) && (RS_VERSION >= 14))
483extern float4 __attribute__((overloadable))
484 rsMatrixMultiply(const rs_matrix4x4* m, float2 in);
485#endif
486
487#if (defined(RS_VERSION) && (RS_VERSION >= 14))
488extern float3 __attribute__((overloadable))
489 rsMatrixMultiply(const rs_matrix3x3* m, float3 in);
490#endif
491
492#if (defined(RS_VERSION) && (RS_VERSION >= 14))
493extern float3 __attribute__((overloadable))
494 rsMatrixMultiply(const rs_matrix3x3* m, float2 in);
495#endif
496
497#if (defined(RS_VERSION) && (RS_VERSION >= 14))
498extern float2 __attribute__((overloadable))
499 rsMatrixMultiply(const rs_matrix2x2* m, float2 in);
500#endif
501
502/*
503 * rsMatrixRotate: Apply a rotation to a transformation matrix
504 *
505 * Multiply the matrix m with a rotation matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700506 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700507 * This function modifies a transformation matrix to first do a rotation.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700508 * The axis of rotation is the (x, y, z) vector.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700509 *
510 * To apply this combined transformation to a vector, multiply
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700511 * the vector by the created matrix using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700512 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700513 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700514 * m: The matrix to modify.
515 * rot: How much rotation to do, in degrees.
516 * x: The x component of the vector that is the axis of rotation.
517 * y: The y component of the vector that is the axis of rotation.
518 * z: The z component of the vector that is the axis of rotation.
Jason Sams044e2ee2011-08-08 16:52:30 -0700519 */
520extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700521 rsMatrixRotate(rs_matrix4x4* m, float rot, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700522
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700523/*
524 * rsMatrixScale: Apply a scaling to a transformation matrix
525 *
526 * Multiply the matrix m with a scaling matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700527 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700528 * This function modifies a transformation matrix to first do a scaling.
529 * When scaling, each component of a vector is multiplied by a number.
530 * This number can be negative.
531 *
532 * To apply this combined transformation to a vector, multiply
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700533 * the vector by the created matrix using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700534 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700535 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700536 * m: The matrix to modify.
537 * x: The multiple to scale the x components by.
538 * y: The multiple to scale the y components by.
539 * z: The multiple to scale the z components by.
Jason Sams044e2ee2011-08-08 16:52:30 -0700540 */
541extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700542 rsMatrixScale(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700543
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700544/*
545 * rsMatrixSet: Set one element
546 *
547 * Set an element of a matrix.
548 *
549 * Warning: The order of the column and row parameters may be unexpected.
550 *
551 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700552 * m: The matrix that will be modified.
553 * col: The zero-based column of the element to be set.
554 * row: The zero-based row of the element to be set.
555 * v: The value to set.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700556 */
557extern void __attribute__((overloadable))
558 rsMatrixSet(rs_matrix4x4* m, uint32_t col, uint32_t row, float v);
559
560extern void __attribute__((overloadable))
561 rsMatrixSet(rs_matrix3x3* m, uint32_t col, uint32_t row, float v);
562
563extern void __attribute__((overloadable))
564 rsMatrixSet(rs_matrix2x2* m, uint32_t col, uint32_t row, float v);
565
566/*
567 * rsMatrixTranslate: Apply a translation to a transformation matrix
568 *
569 * Multiply the matrix m with a translation matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700570 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700571 * This function modifies a transformation matrix to first
572 * do a translation. When translating, a number is added
573 * to each component of a vector.
574 *
575 * To apply this combined transformation to a vector, multiply
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700576 * the vector by the created matrix using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700577 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700578 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700579 * m: The matrix to modify.
580 * x: The number to add to each x component.
581 * y: The number to add to each y component.
582 * z: The number to add to each z component.
Jason Sams044e2ee2011-08-08 16:52:30 -0700583 */
584extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700585 rsMatrixTranslate(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700586
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700587/*
588 * rsMatrixTranspose: Transpose a matrix place
Jason Sams044e2ee2011-08-08 16:52:30 -0700589 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700590 * Transpose the matrix m in place.
Jason Sams044e2ee2011-08-08 16:52:30 -0700591 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700592 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700593 * m: The matrix to transpose.
Jason Sams044e2ee2011-08-08 16:52:30 -0700594 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700595extern void __attribute__((overloadable))
596 rsMatrixTranspose(rs_matrix4x4* m);
Jason Sams044e2ee2011-08-08 16:52:30 -0700597
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700598extern void __attribute__((overloadable))
599 rsMatrixTranspose(rs_matrix3x3* m);
Jason Sams044e2ee2011-08-08 16:52:30 -0700600
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700601extern void __attribute__((overloadable))
602 rsMatrixTranspose(rs_matrix2x2* m);
603
604#endif // RENDERSCRIPT_RS_MATRIX_RSH