blob: aafc864da68ac575d66afc0336fc32b4521f7fd3 [file] [log] [blame]
Ying Wangb335bb02011-11-29 10:23:55 -08001/*
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -07002 * Copyright (C) 2015 The Android Open Source Project
Ying Wangb335bb02011-11-29 10:23:55 -08003 *
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
Stephen Hines3f868232015-04-10 09:22:19 -070017// Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070018
19/*
Stephen Hines3f868232015-04-10 09:22:19 -070020 * rs_matrix.rsh: Matrix Functions
Ying Wangb335bb02011-11-29 10:23:55 -080021 *
Stephen Hines271efdf2014-10-01 20:25:12 -070022 * These functions let you manipulate square matrices of rank 2x2, 3x3, and 4x4.
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -070023 * They are particularly useful for graphical transformations and are compatible
24 * with OpenGL.
Stephen Hines271efdf2014-10-01 20:25:12 -070025 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -070026 * We use a zero-based index for rows and columns. E.g. the last element of a
27 * rs_matrix4x4 is found at (3, 3).
Stephen Hines271efdf2014-10-01 20:25:12 -070028 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -070029 * RenderScript uses column-major matrices and column-based vectors. Transforming
30 * a vector is done by postmultiplying the vector, e.g. (matrix * vector),
31 * as provided by rsMatrixMultiply().
Stephen Hines271efdf2014-10-01 20:25:12 -070032 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -070033 * To create a transformation matrix that performs two transformations at once,
34 * multiply the two source matrices, with the first transformation as the right
35 * argument. E.g. to create a transformation matrix that applies the
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070036 * transformation s1 followed by s2, call rsMatrixLoadMultiply(&combined, &s2, &s1).
37 * This derives from s2 * (s1 * v), which is (s2 * s1) * v.
Stephen Hines271efdf2014-10-01 20:25:12 -070038 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070039 * We have two style of functions to create transformation matrices:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -070040 * rsMatrixLoadTransformation and rsMatrixTransformation. The former
41 * style simply stores the transformation matrix in the first argument. The latter
42 * modifies a pre-existing transformation matrix so that the new transformation
43 * happens first. E.g. if you call rsMatrixTranslate() on a matrix that already
44 * does a scaling, the resulting matrix when applied to a vector will first do the
45 * translation then the scaling.
Ying Wangb335bb02011-11-29 10:23:55 -080046 */
Stephen Hines3f868232015-04-10 09:22:19 -070047
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070048#ifndef RENDERSCRIPT_RS_MATRIX_RSH
49#define RENDERSCRIPT_RS_MATRIX_RSH
Ying Wangb335bb02011-11-29 10:23:55 -080050
Jean-Luc Brouillet4fbd9032015-04-02 14:46:27 -070051#include "rs_vector_math.rsh"
52
53/*
Stephen Hines3f868232015-04-10 09:22:19 -070054 * rsExtractFrustumPlanes: Compute frustum planes
55 *
Jean-Luc Brouillet4fbd9032015-04-02 14:46:27 -070056 * Computes 6 frustum planes from the view projection matrix
57 *
58 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -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 Brouillet4fbd9032015-04-02 14:46: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/*
Stephen Hines3f868232015-04-10 09:22:19 -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 Brouillet4fbd9032015-04-02 14:46:27 -0700119 *
120 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -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 Brouillet4fbd9032015-04-02 14:46: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
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700159/*
160 * rsMatrixGet: Get one element
Ying Wangb335bb02011-11-29 10:23:55 -0800161 *
Stephen Hines271efdf2014-10-01 20:25:12 -0700162 * Returns one element of a matrix.
Ying Wangb335bb02011-11-29 10:23:55 -0800163 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700164 * Warning: The order of the column and row parameters may be unexpected.
Stephen Hines271efdf2014-10-01 20:25:12 -0700165 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700166 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700167 * m: Matrix to extract the element from.
168 * col: Zero-based column of the element to be extracted.
169 * row: Zero-based row of the element to extracted.
Ying Wangb335bb02011-11-29 10:23:55 -0800170 */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700171extern float __attribute__((overloadable))
172 rsMatrixGet(const rs_matrix4x4* m, uint32_t col, uint32_t row);
Ying Wangb335bb02011-11-29 10:23:55 -0800173
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700174extern float __attribute__((overloadable))
175 rsMatrixGet(const rs_matrix3x3* m, uint32_t col, uint32_t row);
Ying Wangb335bb02011-11-29 10:23:55 -0800176
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -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
Ying Wangb335bb02011-11-29 10:23:55 -0800182 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700183 * Returns true if the matrix was successfully inverted.
Stephen Hines271efdf2014-10-01 20:25:12 -0700184 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700185 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700186 * m: Matrix to invert.
Ying Wangb335bb02011-11-29 10:23:55 -0800187 */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700188extern bool __attribute__((overloadable))
189 rsMatrixInverse(rs_matrix4x4* m);
190
191/*
192 * rsMatrixInverseTranspose: Inverts and transpose a matrix in place
Stephen Hines271efdf2014-10-01 20:25:12 -0700193 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700194 * The matrix is first inverted then transposed. Returns true if the matrix was
195 * successfully inverted.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700196 *
197 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700198 * m: Matrix to modify.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -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 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700212 * If loading from a matrix and the source is smaller than the destination, the rest
213 * of the destination is filled with elements of the identity matrix. E.g.
Stephen Hines271efdf2014-10-01 20:25:12 -0700214 * loading a rs_matrix2x2 into a rs_matrix4x4 will give:
215 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -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
Stephen Hines271efdf2014-10-01 20:25:12 -0700220 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700221 *
222 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700223 * destination: Matrix to set.
224 * array: 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: Source matrix.
Ying Wangb335bb02011-11-29 10:23:55 -0800226 */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700227extern void __attribute__((overloadable))
228 rsMatrixLoad(rs_matrix4x4* destination, const float* array);
Ying Wangb335bb02011-11-29 10:23:55 -0800229
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -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 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700254 * Constructs a frustum projection matrix, transforming the box identified by
255 * the six clipping planes left, right, bottom, top, near, far.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700256 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700257 * To apply this projection to a vector, multiply the vector by the created
258 * matrix using rsMatrixMultiply().
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700259 *
260 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700261 * m: Matrix to set.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700262 */
263extern void __attribute__((overloadable))
264 rsMatrixLoadFrustum(rs_matrix4x4* m, float left, float right, float bottom, float top,
265 float near, float far);
266
267/*
268 * rsMatrixLoadIdentity: Load identity matrix
269 *
270 * Set the elements of a matrix to the identity matrix.
271 *
272 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700273 * m: Matrix to set.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700274 */
275extern void __attribute__((overloadable))
276 rsMatrixLoadIdentity(rs_matrix4x4* m);
277
278extern void __attribute__((overloadable))
279 rsMatrixLoadIdentity(rs_matrix3x3* m);
280
281extern void __attribute__((overloadable))
282 rsMatrixLoadIdentity(rs_matrix2x2* m);
283
284/*
285 * rsMatrixLoadMultiply: Multiply two matrices
286 *
287 * Sets m to the matrix product of lhs * rhs.
288 *
289 * To combine two 4x4 transformaton matrices, multiply the second transformation matrix
290 * by the first transformation matrix. E.g. to create a transformation matrix that applies
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700291 * the transformation s1 followed by s2, call rsMatrixLoadMultiply(&combined, &s2, &s1).
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700292 *
293 * Warning: Prior to version 21, storing the result back into right matrix is not supported and
294 * will result in undefined behavior. Use rsMatrixMulitply instead. E.g. instead of doing
295 * rsMatrixLoadMultiply (&m2r, &m2r, &m2l), use rsMatrixMultiply (&m2r, &m2l).
296 * rsMatrixLoadMultiply (&m2l, &m2r, &m2l) works as expected.
297 *
298 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700299 * m: Matrix to set.
300 * lhs: Left matrix of the product.
301 * rhs: Right matrix of the product.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700302 */
303extern void __attribute__((overloadable))
304 rsMatrixLoadMultiply(rs_matrix4x4* m, const rs_matrix4x4* lhs, const rs_matrix4x4* rhs);
305
306extern void __attribute__((overloadable))
307 rsMatrixLoadMultiply(rs_matrix3x3* m, const rs_matrix3x3* lhs, const rs_matrix3x3* rhs);
308
309extern void __attribute__((overloadable))
310 rsMatrixLoadMultiply(rs_matrix2x2* m, const rs_matrix2x2* lhs, const rs_matrix2x2* rhs);
311
312/*
313 * rsMatrixLoadOrtho: Load an orthographic projection matrix
314 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700315 * Constructs an orthographic projection matrix, transforming the box identified by the
316 * six clipping planes left, right, bottom, top, near, far into a unit cube
317 * with a corner at (-1, -1, -1) and the opposite at (1, 1, 1).
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700318 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700319 * To apply this projection to a vector, multiply the vector by the created matrix
320 * using rsMatrixMultiply().
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700321 *
322 * See https://en.wikipedia.org/wiki/Orthographic_projection .
323 *
324 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700325 * m: Matrix to set.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700326 */
327extern void __attribute__((overloadable))
328 rsMatrixLoadOrtho(rs_matrix4x4* m, float left, float right, float bottom, float top, float near,
329 float far);
330
331/*
332 * rsMatrixLoadPerspective: Load a perspective projection matrix
333 *
334 * Constructs a perspective projection matrix, assuming a symmetrical field of view.
335 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700336 * To apply this projection to a vector, multiply the vector by the created matrix
337 * using rsMatrixMultiply().
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700338 *
339 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700340 * m: Matrix to set.
Stephen Hines3f868232015-04-10 09:22:19 -0700341 * fovy: Field of view, in degrees along the Y axis.
342 * aspect: Ratio of x / y.
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700343 * near: Near clipping plane.
344 * far: Far clipping plane.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700345 */
346extern void __attribute__((overloadable))
347 rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far);
348
349/*
350 * rsMatrixLoadRotate: Load a rotation matrix
Ying Wangb335bb02011-11-29 10:23:55 -0800351 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700352 * This function creates a rotation matrix. The axis of rotation is the (x, y, z) vector.
Stephen Hines271efdf2014-10-01 20:25:12 -0700353 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700354 * To rotate a vector, multiply the vector by the created matrix using rsMatrixMultiply().
Stephen Hines271efdf2014-10-01 20:25:12 -0700355 *
356 * See http://en.wikipedia.org/wiki/Rotation_matrix .
357 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700358 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700359 * m: Matrix to set.
Stephen Hines3f868232015-04-10 09:22:19 -0700360 * rot: How much rotation to do, in degrees.
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700361 * x: X component of the vector that is the axis of rotation.
362 * y: Y component of the vector that is the axis of rotation.
363 * z: Z component of the vector that is the axis of rotation.
Ying Wangb335bb02011-11-29 10:23:55 -0800364 */
365extern void __attribute__((overloadable))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700366 rsMatrixLoadRotate(rs_matrix4x4* m, float rot, float x, float y, float z);
Ying Wangb335bb02011-11-29 10:23:55 -0800367
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700368/*
369 * rsMatrixLoadScale: Load a scaling matrix
Ying Wangb335bb02011-11-29 10:23:55 -0800370 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700371 * This function creates a scaling matrix, where each component of a vector is multiplied
372 * by a number. This number can be negative.
Stephen Hines271efdf2014-10-01 20:25:12 -0700373 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700374 * To scale a vector, multiply the vector by the created matrix using rsMatrixMultiply().
Stephen Hines271efdf2014-10-01 20:25:12 -0700375 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700376 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700377 * m: Matrix to set.
378 * x: Multiple to scale the x components by.
379 * y: Multiple to scale the y components by.
380 * z: Multiple to scale the z components by.
Ying Wangb335bb02011-11-29 10:23:55 -0800381 */
382extern void __attribute__((overloadable))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700383 rsMatrixLoadScale(rs_matrix4x4* m, float x, float y, float z);
Ying Wangb335bb02011-11-29 10:23:55 -0800384
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700385/*
386 * rsMatrixLoadTranslate: Load a translation matrix
Ying Wangb335bb02011-11-29 10:23:55 -0800387 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700388 * This function creates a translation matrix, where a number is added to each element of
389 * a vector.
Stephen Hines271efdf2014-10-01 20:25:12 -0700390 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700391 * To translate a vector, multiply the vector by the created matrix using
392 * rsMatrixMultiply().
Stephen Hines271efdf2014-10-01 20:25:12 -0700393 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700394 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700395 * m: Matrix to set.
396 * x: Number to add to each x component.
397 * y: Number to add to each y component.
398 * z: Number to add to each z component.
Ying Wangb335bb02011-11-29 10:23:55 -0800399 */
400extern void __attribute__((overloadable))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700401 rsMatrixLoadTranslate(rs_matrix4x4* m, float x, float y, float z);
Ying Wangb335bb02011-11-29 10:23:55 -0800402
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700403/*
404 * rsMatrixMultiply: Multiply a matrix by a vector or another matrix
Ying Wangb335bb02011-11-29 10:23:55 -0800405 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700406 * For the matrix by matrix variant, sets m to the matrix product m * rhs.
Stephen Hines271efdf2014-10-01 20:25:12 -0700407 *
408 * When combining two 4x4 transformation matrices using this function, the resulting
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700409 * matrix will correspond to performing the rhs transformation first followed by
410 * the original m transformation.
Stephen Hines271efdf2014-10-01 20:25:12 -0700411 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700412 * For the matrix by vector variant, returns the post-multiplication of the vector
413 * by the matrix, ie. m * in.
414 *
415 * When multiplying a float3 to a rs_matrix4x4, the vector is expanded with (1).
416 *
417 * When multiplying a float2 to a rs_matrix4x4, the vector is expanded with (0, 1).
418 *
419 * When multiplying a float2 to a rs_matrix3x3, the vector is expanded with (0).
420 *
421 * Starting with API 14, this function takes a const matrix as the first argument.
422 *
423 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700424 * m: Left matrix of the product and the matrix to be set.
425 * rhs: Right matrix of the product.
Ying Wangb335bb02011-11-29 10:23:55 -0800426 */
427extern void __attribute__((overloadable))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700428 rsMatrixMultiply(rs_matrix4x4* m, const rs_matrix4x4* rhs);
Ying Wangb335bb02011-11-29 10:23:55 -0800429
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700430extern void __attribute__((overloadable))
431 rsMatrixMultiply(rs_matrix3x3* m, const rs_matrix3x3* rhs);
432
433extern void __attribute__((overloadable))
434 rsMatrixMultiply(rs_matrix2x2* m, const rs_matrix2x2* rhs);
435
436#if !defined(RS_VERSION) || (RS_VERSION <= 13)
437extern float4 __attribute__((overloadable))
438 rsMatrixMultiply(rs_matrix4x4* m, float4 in);
439#endif
440
441#if !defined(RS_VERSION) || (RS_VERSION <= 13)
442extern float4 __attribute__((overloadable))
443 rsMatrixMultiply(rs_matrix4x4* m, float3 in);
444#endif
445
446#if !defined(RS_VERSION) || (RS_VERSION <= 13)
447extern float4 __attribute__((overloadable))
448 rsMatrixMultiply(rs_matrix4x4* m, float2 in);
449#endif
450
451#if !defined(RS_VERSION) || (RS_VERSION <= 13)
452extern float3 __attribute__((overloadable))
453 rsMatrixMultiply(rs_matrix3x3* m, float3 in);
454#endif
455
456#if !defined(RS_VERSION) || (RS_VERSION <= 13)
457extern float3 __attribute__((overloadable))
458 rsMatrixMultiply(rs_matrix3x3* m, float2 in);
459#endif
460
461#if !defined(RS_VERSION) || (RS_VERSION <= 13)
462extern float2 __attribute__((overloadable))
463 rsMatrixMultiply(rs_matrix2x2* m, float2 in);
464#endif
465
466#if (defined(RS_VERSION) && (RS_VERSION >= 14))
467extern float4 __attribute__((overloadable))
468 rsMatrixMultiply(const rs_matrix4x4* m, float4 in);
469#endif
470
471#if (defined(RS_VERSION) && (RS_VERSION >= 14))
472extern float4 __attribute__((overloadable))
473 rsMatrixMultiply(const rs_matrix4x4* m, float3 in);
474#endif
475
476#if (defined(RS_VERSION) && (RS_VERSION >= 14))
477extern float4 __attribute__((overloadable))
478 rsMatrixMultiply(const rs_matrix4x4* m, float2 in);
479#endif
480
481#if (defined(RS_VERSION) && (RS_VERSION >= 14))
482extern float3 __attribute__((overloadable))
483 rsMatrixMultiply(const rs_matrix3x3* m, float3 in);
484#endif
485
486#if (defined(RS_VERSION) && (RS_VERSION >= 14))
487extern float3 __attribute__((overloadable))
488 rsMatrixMultiply(const rs_matrix3x3* m, float2 in);
489#endif
490
491#if (defined(RS_VERSION) && (RS_VERSION >= 14))
492extern float2 __attribute__((overloadable))
493 rsMatrixMultiply(const rs_matrix2x2* m, float2 in);
494#endif
495
496/*
497 * rsMatrixRotate: Apply a rotation to a transformation matrix
498 *
499 * Multiply the matrix m with a rotation matrix.
Ying Wangb335bb02011-11-29 10:23:55 -0800500 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700501 * This function modifies a transformation matrix to first do a rotation. The axis of
502 * rotation is the (x, y, z) vector.
Stephen Hines271efdf2014-10-01 20:25:12 -0700503 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700504 * To apply this combined transformation to a vector, multiply the vector by the created
505 * matrix using rsMatrixMultiply().
Stephen Hines271efdf2014-10-01 20:25:12 -0700506 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700507 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700508 * m: Matrix to modify.
Stephen Hines3f868232015-04-10 09:22:19 -0700509 * rot: How much rotation to do, in degrees.
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700510 * x: X component of the vector that is the axis of rotation.
511 * y: Y component of the vector that is the axis of rotation.
512 * z: Z component of the vector that is the axis of rotation.
Ying Wangb335bb02011-11-29 10:23:55 -0800513 */
514extern void __attribute__((overloadable))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700515 rsMatrixRotate(rs_matrix4x4* m, float rot, float x, float y, float z);
Ying Wangb335bb02011-11-29 10:23:55 -0800516
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700517/*
518 * rsMatrixScale: Apply a scaling to a transformation matrix
519 *
520 * Multiply the matrix m with a scaling matrix.
Ying Wangb335bb02011-11-29 10:23:55 -0800521 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700522 * This function modifies a transformation matrix to first do a scaling. When scaling,
523 * each component of a vector is multiplied by a number. This number can be negative.
Stephen Hines271efdf2014-10-01 20:25:12 -0700524 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700525 * To apply this combined transformation to a vector, multiply the vector by the created
526 * matrix using rsMatrixMultiply().
Stephen Hines271efdf2014-10-01 20:25:12 -0700527 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700528 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700529 * m: Matrix to modify.
530 * x: Multiple to scale the x components by.
531 * y: Multiple to scale the y components by.
532 * z: Multiple to scale the z components by.
Ying Wangb335bb02011-11-29 10:23:55 -0800533 */
534extern void __attribute__((overloadable))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700535 rsMatrixScale(rs_matrix4x4* m, float x, float y, float z);
Ying Wangb335bb02011-11-29 10:23:55 -0800536
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700537/*
538 * rsMatrixSet: Set one element
539 *
540 * Set an element of a matrix.
541 *
542 * Warning: The order of the column and row parameters may be unexpected.
543 *
544 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700545 * m: Matrix that will be modified.
546 * col: Zero-based column of the element to be set.
547 * row: Zero-based row of the element to be set.
548 * v: Value to set.
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700549 */
550extern void __attribute__((overloadable))
551 rsMatrixSet(rs_matrix4x4* m, uint32_t col, uint32_t row, float v);
552
553extern void __attribute__((overloadable))
554 rsMatrixSet(rs_matrix3x3* m, uint32_t col, uint32_t row, float v);
555
556extern void __attribute__((overloadable))
557 rsMatrixSet(rs_matrix2x2* m, uint32_t col, uint32_t row, float v);
558
559/*
560 * rsMatrixTranslate: Apply a translation to a transformation matrix
561 *
562 * Multiply the matrix m with a translation matrix.
Ying Wangb335bb02011-11-29 10:23:55 -0800563 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700564 * This function modifies a transformation matrix to first do a translation. When
565 * translating, a number is added to each component of a vector.
Stephen Hines271efdf2014-10-01 20:25:12 -0700566 *
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700567 * To apply this combined transformation to a vector, multiply the vector by the
568 * created matrix using rsMatrixMultiply().
Stephen Hines271efdf2014-10-01 20:25:12 -0700569 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700570 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700571 * m: Matrix to modify.
572 * x: Number to add to each x component.
573 * y: Number to add to each y component.
574 * z: Number to add to each z component.
Ying Wangb335bb02011-11-29 10:23:55 -0800575 */
576extern void __attribute__((overloadable))
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700577 rsMatrixTranslate(rs_matrix4x4* m, float x, float y, float z);
Ying Wangb335bb02011-11-29 10:23:55 -0800578
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700579/*
580 * rsMatrixTranspose: Transpose a matrix place
Ying Wangb335bb02011-11-29 10:23:55 -0800581 *
Stephen Hines271efdf2014-10-01 20:25:12 -0700582 * Transpose the matrix m in place.
Ying Wangb335bb02011-11-29 10:23:55 -0800583 *
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700584 * Parameters:
Pirama Arumuga Nainar37fb08a2015-05-11 14:34:37 -0700585 * m: Matrix to transpose.
Ying Wangb335bb02011-11-29 10:23:55 -0800586 */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700587extern void __attribute__((overloadable))
588 rsMatrixTranspose(rs_matrix4x4* m);
Ying Wangb335bb02011-11-29 10:23:55 -0800589
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700590extern void __attribute__((overloadable))
591 rsMatrixTranspose(rs_matrix3x3* m);
Ying Wangb335bb02011-11-29 10:23:55 -0800592
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700593extern void __attribute__((overloadable))
594 rsMatrixTranspose(rs_matrix2x2* m);
595
596#endif // RENDERSCRIPT_RS_MATRIX_RSH