blob: 169d2b2f59524966bfcc3e69adceeacad241ac00 [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/*
20 * 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/*
54 * Computes 6 frustum planes from the view projection matrix
55 *
56 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -070057 * viewProj: matrix to extract planes from
58 * left: left plane
59 * right: right plane
60 * top: top plane
61 * bottom: bottom plane
62 * near: near plane
63 * far: far plane
Jean-Luc Brouilletbe216382015-03-22 12:44:27 -070064 */
65static inline void __attribute__((always_inline, overloadable))
66 rsExtractFrustumPlanes(const rs_matrix4x4* viewProj, float4* left, float4* right, float4* top,
67 float4* bottom, float4* near, float4* far) {
68 // x y z w = a b c d in the plane equation
69 left->x = viewProj->m[3] + viewProj->m[0];
70 left->y = viewProj->m[7] + viewProj->m[4];
71 left->z = viewProj->m[11] + viewProj->m[8];
72 left->w = viewProj->m[15] + viewProj->m[12];
73
74 right->x = viewProj->m[3] - viewProj->m[0];
75 right->y = viewProj->m[7] - viewProj->m[4];
76 right->z = viewProj->m[11] - viewProj->m[8];
77 right->w = viewProj->m[15] - viewProj->m[12];
78
79 top->x = viewProj->m[3] - viewProj->m[1];
80 top->y = viewProj->m[7] - viewProj->m[5];
81 top->z = viewProj->m[11] - viewProj->m[9];
82 top->w = viewProj->m[15] - viewProj->m[13];
83
84 bottom->x = viewProj->m[3] + viewProj->m[1];
85 bottom->y = viewProj->m[7] + viewProj->m[5];
86 bottom->z = viewProj->m[11] + viewProj->m[9];
87 bottom->w = viewProj->m[15] + viewProj->m[13];
88
89 near->x = viewProj->m[3] + viewProj->m[2];
90 near->y = viewProj->m[7] + viewProj->m[6];
91 near->z = viewProj->m[11] + viewProj->m[10];
92 near->w = viewProj->m[15] + viewProj->m[14];
93
94 far->x = viewProj->m[3] - viewProj->m[2];
95 far->y = viewProj->m[7] - viewProj->m[6];
96 far->z = viewProj->m[11] - viewProj->m[10];
97 far->w = viewProj->m[15] - viewProj->m[14];
98
99 float len = length(left->xyz);
100 *left /= len;
101 len = length(right->xyz);
102 *right /= len;
103 len = length(top->xyz);
104 *top /= len;
105 len = length(bottom->xyz);
106 *bottom /= len;
107 len = length(near->xyz);
108 *near /= len;
109 len = length(far->xyz);
110 *far /= len;
111}
112
113/*
114 * Checks if a sphere is withing the 6 frustum planes
115 *
116 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700117 * sphere: float4 representing the sphere
118 * left: left plane
119 * right: right plane
120 * top: top plane
121 * bottom: bottom plane
122 * near: near plane
123 * far: far plane
Jean-Luc Brouilletbe216382015-03-22 12:44:27 -0700124 */
125static inline bool __attribute__((always_inline, overloadable))
126 rsIsSphereInFrustum(float4* sphere, float4* left, float4* right, float4* top, float4* bottom,
127 float4* near, float4* far) {
128 float distToCenter = dot(left->xyz, sphere->xyz) + left->w;
129 if (distToCenter < -sphere->w) {
130 return false;
131 }
132 distToCenter = dot(right->xyz, sphere->xyz) + right->w;
133 if (distToCenter < -sphere->w) {
134 return false;
135 }
136 distToCenter = dot(top->xyz, sphere->xyz) + top->w;
137 if (distToCenter < -sphere->w) {
138 return false;
139 }
140 distToCenter = dot(bottom->xyz, sphere->xyz) + bottom->w;
141 if (distToCenter < -sphere->w) {
142 return false;
143 }
144 distToCenter = dot(near->xyz, sphere->xyz) + near->w;
145 if (distToCenter < -sphere->w) {
146 return false;
147 }
148 distToCenter = dot(far->xyz, sphere->xyz) + far->w;
149 if (distToCenter < -sphere->w) {
150 return false;
151 }
152 return true;
153}
154
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700155/*
156 * rsMatrixGet: Get one element
Jason Sams044e2ee2011-08-08 16:52:30 -0700157 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700158 * Returns one element of a matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700159 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700160 * Warning: The order of the column and row parameters may be unexpected.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700161 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700162 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700163 * m: The matrix to extract the element from.
164 * col: The zero-based column of the element to be extracted.
165 * row: The zero-based row of the element to extracted.
Jason Sams044e2ee2011-08-08 16:52:30 -0700166 */
Jean-Luc Brouillet129c1472015-03-02 15:37:07 -0800167extern float __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700168 rsMatrixGet(const rs_matrix4x4* m, uint32_t col, uint32_t row);
Jason Sams044e2ee2011-08-08 16:52:30 -0700169
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700170extern float __attribute__((overloadable))
171 rsMatrixGet(const rs_matrix3x3* m, uint32_t col, uint32_t row);
Jason Sams044e2ee2011-08-08 16:52:30 -0700172
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700173extern float __attribute__((overloadable))
174 rsMatrixGet(const rs_matrix2x2* m, uint32_t col, uint32_t row);
175
176/*
177 * rsMatrixInverse: Inverts a matrix in place
Jason Sams044e2ee2011-08-08 16:52:30 -0700178 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700179 * Returns true if the matrix was successfully inverted.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700180 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700181 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700182 * m: The matrix to invert.
Jason Sams044e2ee2011-08-08 16:52:30 -0700183 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700184extern bool __attribute__((overloadable))
185 rsMatrixInverse(rs_matrix4x4* m);
186
187/*
188 * rsMatrixInverseTranspose: Inverts and transpose a matrix in place
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700189 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700190 * The matrix is first inverted then transposed.
191 * Returns true if the matrix was successfully inverted.
192 *
193 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700194 * m: The matrix to modify.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700195 */
196extern bool __attribute__((overloadable))
197 rsMatrixInverseTranspose(rs_matrix4x4* m);
198
199/*
200 * rsMatrixLoad: Load or copy a matrix
201 *
202 * Set the elements of a matrix from an array of floats or from another matrix.
203 *
204 * If loading from an array, the floats should be in row-major order, i.e. the element a
205 * row 0, column 0 should be first, followed by the element at
206 * row 0, column 1, etc.
207 *
208 * 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 -0700209 * destination is filled with elements of the identity matrix. E.g.
210 * loading a rs_matrix2x2 into a rs_matrix4x4 will give:
211 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700212 * m00 m01 0.0 0.0
213 * m10 m11 0.0 0.0
214 * 0.0 0.0 1.0 0.0
215 * 0.0 0.0 0.0 1.0
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700216 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700217 *
218 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700219 * destination: The matrix to set.
220 * 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.
221 * source: The source matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700222 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700223extern void __attribute__((overloadable))
224 rsMatrixLoad(rs_matrix4x4* destination, const float* array);
Jason Sams044e2ee2011-08-08 16:52:30 -0700225
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700226extern void __attribute__((overloadable))
227 rsMatrixLoad(rs_matrix3x3* destination, const float* array);
228
229extern void __attribute__((overloadable))
230 rsMatrixLoad(rs_matrix2x2* destination, const float* array);
231
232extern void __attribute__((overloadable))
233 rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix4x4* source);
234
235extern void __attribute__((overloadable))
236 rsMatrixLoad(rs_matrix3x3* destination, const rs_matrix3x3* source);
237
238extern void __attribute__((overloadable))
239 rsMatrixLoad(rs_matrix2x2* destination, const rs_matrix2x2* source);
240
241extern void __attribute__((overloadable))
242 rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix3x3* source);
243
244extern void __attribute__((overloadable))
245 rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix2x2* source);
246
247/*
248 * rsMatrixLoadFrustum: Load a frustum projection matrix
249 *
250 * Constructs a frustum projection matrix, transforming the box
251 * identified by the six clipping planes left, right, bottom, top,
252 * near, far.
253 *
254 * To apply this projection to a vector, multiply the vector by the
255 * created matrix using rsMatrixMultiply().
256 *
257 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700258 * m: The matrix to set.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700259 */
260extern void __attribute__((overloadable))
261 rsMatrixLoadFrustum(rs_matrix4x4* m, float left, float right, float bottom, float top,
262 float near, float far);
263
264/*
265 * rsMatrixLoadIdentity: Load identity matrix
266 *
267 * Set the elements of a matrix to the identity matrix.
268 *
269 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700270 * m: The matrix to set.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700271 */
272extern void __attribute__((overloadable))
273 rsMatrixLoadIdentity(rs_matrix4x4* m);
274
275extern void __attribute__((overloadable))
276 rsMatrixLoadIdentity(rs_matrix3x3* m);
277
278extern void __attribute__((overloadable))
279 rsMatrixLoadIdentity(rs_matrix2x2* m);
280
281/*
282 * rsMatrixLoadMultiply: Multiply two matrices
283 *
284 * Sets m to the matrix product of lhs * rhs.
285 *
286 * To combine two 4x4 transformaton matrices, multiply the second transformation matrix
287 * by the first transformation matrix. E.g. to create a transformation matrix that applies
288 * the transformation s1 followed by s2, call
289 * rsMatrixLoadMultiply(&combined, &s2, &s1).
290 *
291 * Warning: Prior to version 21, storing the result back into right matrix is not supported and
292 * will result in undefined behavior. Use rsMatrixMulitply instead. E.g. instead of doing
293 * rsMatrixLoadMultiply (&m2r, &m2r, &m2l), use rsMatrixMultiply (&m2r, &m2l).
294 * rsMatrixLoadMultiply (&m2l, &m2r, &m2l) works as expected.
295 *
296 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700297 * m: The matrix to set.
298 * lhs: The left matrix of the product.
299 * rhs: The right matrix of the product.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700300 */
301extern void __attribute__((overloadable))
302 rsMatrixLoadMultiply(rs_matrix4x4* m, const rs_matrix4x4* lhs, const rs_matrix4x4* rhs);
303
304extern void __attribute__((overloadable))
305 rsMatrixLoadMultiply(rs_matrix3x3* m, const rs_matrix3x3* lhs, const rs_matrix3x3* rhs);
306
307extern void __attribute__((overloadable))
308 rsMatrixLoadMultiply(rs_matrix2x2* m, const rs_matrix2x2* lhs, const rs_matrix2x2* rhs);
309
310/*
311 * rsMatrixLoadOrtho: Load an orthographic projection matrix
312 *
313 * Constructs an orthographic projection matrix, transforming the box
314 * identified by the six clipping planes left, right, bottom, top,
315 * near, far into a unit cube with a corner at
316 * (-1, -1, -1) and the opposite at (1, 1, 1).
317 *
318 * To apply this projection to a vector, multiply the vector by the
319 * created matrix using rsMatrixMultiply().
320 *
321 * See https://en.wikipedia.org/wiki/Orthographic_projection .
322 *
323 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700324 * m: The matrix to set.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700325 */
326extern void __attribute__((overloadable))
327 rsMatrixLoadOrtho(rs_matrix4x4* m, float left, float right, float bottom, float top, float near,
328 float far);
329
330/*
331 * rsMatrixLoadPerspective: Load a perspective projection matrix
332 *
333 * Constructs a perspective projection matrix, assuming a symmetrical field of view.
334 *
335 * To apply this projection to a vector, multiply the vector by the
336 * created matrix using rsMatrixMultiply().
337 *
338 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700339 * m: The matrix to set.
340 * fovy: Field of view, in degrees along the Y axis.
341 * aspect: Ratio of x / y.
342 * near: The near clipping plane.
343 * far: The far clipping plane.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700344 */
345extern void __attribute__((overloadable))
346 rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
347
348/*
349 * rsMatrixLoadRotate: Load a rotation matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700350 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700351 * This function creates a rotation matrix. The axis of rotation is the
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700352 * (x, y, z) vector.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700353 *
354 * To rotate a vector, multiply the vector by the created matrix
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700355 * using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700356 *
357 * See http://en.wikipedia.org/wiki/Rotation_matrix .
358 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700359 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700360 * m: The matrix to set.
361 * rot: How much rotation to do, in degrees.
362 * x: The x component of the vector that is the axis of rotation.
363 * y: The y component of the vector that is the axis of rotation.
364 * z: The z component of the vector that is the axis of rotation.
Jason Sams044e2ee2011-08-08 16:52:30 -0700365 */
366extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700367 rsMatrixLoadRotate(rs_matrix4x4* m, float rot, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700368
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700369/*
370 * rsMatrixLoadScale: Load a scaling matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700371 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700372 * This function creates a scaling matrix, where each component of a
373 * vector is multiplied by a number. This number can be negative.
374 *
375 * To scale a vector, multiply the vector by the created matrix
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700376 * using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700377 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700378 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700379 * m: The matrix to set.
380 * x: The multiple to scale the x components by.
381 * y: The multiple to scale the y components by.
382 * z: The multiple to scale the z components by.
Jason Sams044e2ee2011-08-08 16:52:30 -0700383 */
384extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700385 rsMatrixLoadScale(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700386
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700387/*
388 * rsMatrixLoadTranslate: Load a translation matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700389 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700390 * This function creates a translation matrix, where a
391 * number is added to each element of a vector.
392 *
393 * To translate a vector, multiply the vector by the created matrix
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700394 * using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700395 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700396 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700397 * m: The matrix to set.
398 * x: The number to add to each x component.
399 * y: The number to add to each y component.
400 * z: The number to add to each z component.
Jason Sams044e2ee2011-08-08 16:52:30 -0700401 */
402extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700403 rsMatrixLoadTranslate(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700404
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700405/*
406 * rsMatrixMultiply: Multiply a matrix by a vector or another matrix
Jason Sams044e2ee2011-08-08 16:52:30 -0700407 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700408 * For the matrix by matrix variant, sets m to the matrix product m * rhs.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700409 *
410 * When combining two 4x4 transformation matrices using this function, the resulting
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700411 * matrix will correspond to performing the rhs transformation first followed by
412 * the original m transformation.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700413 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700414 * For the matrix by vector variant, returns the post-multiplication of the vector
415 * by the matrix, ie. m * in.
416 *
417 * When multiplying a float3 to a rs_matrix4x4, the vector is expanded with (1).
418 *
419 * When multiplying a float2 to a rs_matrix4x4, the vector is expanded with (0, 1).
420 *
421 * When multiplying a float2 to a rs_matrix3x3, the vector is expanded with (0).
422 *
423 * Starting with API 14, this function takes a const matrix as the first argument.
424 *
425 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700426 * m: The left matrix of the product and the matrix to be set.
427 * rhs: The right matrix of the product.
Jason Sams044e2ee2011-08-08 16:52:30 -0700428 */
429extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700430 rsMatrixMultiply(rs_matrix4x4* m, const rs_matrix4x4* rhs);
Jason Sams044e2ee2011-08-08 16:52:30 -0700431
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700432extern void __attribute__((overloadable))
433 rsMatrixMultiply(rs_matrix3x3* m, const rs_matrix3x3* rhs);
434
435extern void __attribute__((overloadable))
436 rsMatrixMultiply(rs_matrix2x2* m, const rs_matrix2x2* rhs);
437
438#if !defined(RS_VERSION) || (RS_VERSION <= 13)
439extern float4 __attribute__((overloadable))
440 rsMatrixMultiply(rs_matrix4x4* m, float4 in);
441#endif
442
443#if !defined(RS_VERSION) || (RS_VERSION <= 13)
444extern float4 __attribute__((overloadable))
445 rsMatrixMultiply(rs_matrix4x4* m, float3 in);
446#endif
447
448#if !defined(RS_VERSION) || (RS_VERSION <= 13)
449extern float4 __attribute__((overloadable))
450 rsMatrixMultiply(rs_matrix4x4* m, float2 in);
451#endif
452
453#if !defined(RS_VERSION) || (RS_VERSION <= 13)
454extern float3 __attribute__((overloadable))
455 rsMatrixMultiply(rs_matrix3x3* m, float3 in);
456#endif
457
458#if !defined(RS_VERSION) || (RS_VERSION <= 13)
459extern float3 __attribute__((overloadable))
460 rsMatrixMultiply(rs_matrix3x3* m, float2 in);
461#endif
462
463#if !defined(RS_VERSION) || (RS_VERSION <= 13)
464extern float2 __attribute__((overloadable))
465 rsMatrixMultiply(rs_matrix2x2* m, float2 in);
466#endif
467
468#if (defined(RS_VERSION) && (RS_VERSION >= 14))
469extern float4 __attribute__((overloadable))
470 rsMatrixMultiply(const rs_matrix4x4* m, float4 in);
471#endif
472
473#if (defined(RS_VERSION) && (RS_VERSION >= 14))
474extern float4 __attribute__((overloadable))
475 rsMatrixMultiply(const rs_matrix4x4* m, float3 in);
476#endif
477
478#if (defined(RS_VERSION) && (RS_VERSION >= 14))
479extern float4 __attribute__((overloadable))
480 rsMatrixMultiply(const rs_matrix4x4* m, float2 in);
481#endif
482
483#if (defined(RS_VERSION) && (RS_VERSION >= 14))
484extern float3 __attribute__((overloadable))
485 rsMatrixMultiply(const rs_matrix3x3* m, float3 in);
486#endif
487
488#if (defined(RS_VERSION) && (RS_VERSION >= 14))
489extern float3 __attribute__((overloadable))
490 rsMatrixMultiply(const rs_matrix3x3* m, float2 in);
491#endif
492
493#if (defined(RS_VERSION) && (RS_VERSION >= 14))
494extern float2 __attribute__((overloadable))
495 rsMatrixMultiply(const rs_matrix2x2* m, float2 in);
496#endif
497
498/*
499 * rsMatrixRotate: Apply a rotation to a transformation matrix
500 *
501 * Multiply the matrix m with a rotation matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700502 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700503 * This function modifies a transformation matrix to first do a rotation.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700504 * The axis of rotation is the (x, y, z) vector.
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700505 *
506 * To apply this combined transformation to a vector, multiply
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700507 * the vector by the created matrix using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700508 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700509 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700510 * m: The matrix to modify.
511 * rot: How much rotation to do, in degrees.
512 * x: The x component of the vector that is the axis of rotation.
513 * y: The y component of the vector that is the axis of rotation.
514 * z: The z component of the vector that is the axis of rotation.
Jason Sams044e2ee2011-08-08 16:52:30 -0700515 */
516extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700517 rsMatrixRotate(rs_matrix4x4* m, float rot, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700518
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700519/*
520 * rsMatrixScale: Apply a scaling to a transformation matrix
521 *
522 * Multiply the matrix m with a scaling matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700523 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700524 * This function modifies a transformation matrix to first do a scaling.
525 * When scaling, each component of a vector is multiplied by a number.
526 * This number can be negative.
527 *
528 * To apply this combined transformation to a vector, multiply
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700529 * the vector by the created matrix using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700530 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700531 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700532 * m: The matrix to modify.
533 * x: The multiple to scale the x components by.
534 * y: The multiple to scale the y components by.
535 * z: The multiple to scale the z components by.
Jason Sams044e2ee2011-08-08 16:52:30 -0700536 */
537extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700538 rsMatrixScale(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700539
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700540/*
541 * rsMatrixSet: Set one element
542 *
543 * Set an element of a matrix.
544 *
545 * Warning: The order of the column and row parameters may be unexpected.
546 *
547 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700548 * m: The matrix that will be modified.
549 * col: The zero-based column of the element to be set.
550 * row: The zero-based row of the element to be set.
551 * v: The value to set.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700552 */
553extern void __attribute__((overloadable))
554 rsMatrixSet(rs_matrix4x4* m, uint32_t col, uint32_t row, float v);
555
556extern void __attribute__((overloadable))
557 rsMatrixSet(rs_matrix3x3* m, uint32_t col, uint32_t row, float v);
558
559extern void __attribute__((overloadable))
560 rsMatrixSet(rs_matrix2x2* m, uint32_t col, uint32_t row, float v);
561
562/*
563 * rsMatrixTranslate: Apply a translation to a transformation matrix
564 *
565 * Multiply the matrix m with a translation matrix.
Jason Sams044e2ee2011-08-08 16:52:30 -0700566 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700567 * This function modifies a transformation matrix to first
568 * do a translation. When translating, a number is added
569 * to each component of a vector.
570 *
571 * To apply this combined transformation to a vector, multiply
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700572 * the vector by the created matrix using rsMatrixMultiply().
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700573 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700574 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700575 * m: The matrix to modify.
576 * x: The number to add to each x component.
577 * y: The number to add to each y component.
578 * z: The number to add to each z component.
Jason Sams044e2ee2011-08-08 16:52:30 -0700579 */
580extern void __attribute__((overloadable))
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700581 rsMatrixTranslate(rs_matrix4x4* m, float x, float y, float z);
Jason Sams044e2ee2011-08-08 16:52:30 -0700582
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700583/*
584 * rsMatrixTranspose: Transpose a matrix place
Jason Sams044e2ee2011-08-08 16:52:30 -0700585 *
Jean-Luc Brouillet1bb2eed2014-09-05 17:44:48 -0700586 * Transpose the matrix m in place.
Jason Sams044e2ee2011-08-08 16:52:30 -0700587 *
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700588 * Parameters:
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700589 * m: The matrix to transpose.
Jason Sams044e2ee2011-08-08 16:52:30 -0700590 */
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700591extern void __attribute__((overloadable))
592 rsMatrixTranspose(rs_matrix4x4* m);
Jason Sams044e2ee2011-08-08 16:52:30 -0700593
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700594extern void __attribute__((overloadable))
595 rsMatrixTranspose(rs_matrix3x3* m);
Jason Sams044e2ee2011-08-08 16:52:30 -0700596
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700597extern void __attribute__((overloadable))
598 rsMatrixTranspose(rs_matrix2x2* m);
599
600#endif // RENDERSCRIPT_RS_MATRIX_RSH