Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 1 | /* |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 2 | * Copyright (C) 2015 The Android Open Source Project |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 3 | * |
| 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 17 | // Don't edit this file! It is auto-generated by frameworks/rs/api/gen_runtime. |
| 18 | |
| 19 | /* |
| 20 | * rs_matrix.rsh: Matrix functions |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 21 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 22 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 26 | * 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 Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 28 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 29 | * 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 Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 32 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 33 | * To create a transformation matrix that performs two transformations at |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 34 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 36 | * transformation s1 followed by s2, call rsMatrixLoadMultiply(&combined, &s2, &s1). |
| 37 | * This derives from s2 * (s1 * v), which is (s2 * s1) * v. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 38 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 39 | * We have two style of functions to create transformation matrices: |
| 40 | * rsMatrixLoadTransformation and rsMatrixTransformation. The |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 41 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 43 | * transformation happens first. E.g. if you call rsMatrixTranslate() |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 44 | * 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 46 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 47 | #ifndef RENDERSCRIPT_RS_MATRIX_RSH |
| 48 | #define RENDERSCRIPT_RS_MATRIX_RSH |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 49 | |
Jean-Luc Brouillet | be21638 | 2015-03-22 12:44:27 -0700 | [diff] [blame^] | 50 | #include "rs_vector_math.rsh" |
| 51 | |
| 52 | /* |
| 53 | * Computes 6 frustum planes from the view projection matrix |
| 54 | * |
| 55 | * Parameters: |
| 56 | * viewProj matrix to extract planes from |
| 57 | * left left plane |
| 58 | * right right plane |
| 59 | * top top plane |
| 60 | * bottom bottom plane |
| 61 | * near near plane |
| 62 | * far far plane |
| 63 | */ |
| 64 | static inline void __attribute__((always_inline, overloadable)) |
| 65 | rsExtractFrustumPlanes(const rs_matrix4x4* viewProj, float4* left, float4* right, float4* top, |
| 66 | float4* bottom, float4* near, float4* far) { |
| 67 | // x y z w = a b c d in the plane equation |
| 68 | left->x = viewProj->m[3] + viewProj->m[0]; |
| 69 | left->y = viewProj->m[7] + viewProj->m[4]; |
| 70 | left->z = viewProj->m[11] + viewProj->m[8]; |
| 71 | left->w = viewProj->m[15] + viewProj->m[12]; |
| 72 | |
| 73 | right->x = viewProj->m[3] - viewProj->m[0]; |
| 74 | right->y = viewProj->m[7] - viewProj->m[4]; |
| 75 | right->z = viewProj->m[11] - viewProj->m[8]; |
| 76 | right->w = viewProj->m[15] - viewProj->m[12]; |
| 77 | |
| 78 | top->x = viewProj->m[3] - viewProj->m[1]; |
| 79 | top->y = viewProj->m[7] - viewProj->m[5]; |
| 80 | top->z = viewProj->m[11] - viewProj->m[9]; |
| 81 | top->w = viewProj->m[15] - viewProj->m[13]; |
| 82 | |
| 83 | bottom->x = viewProj->m[3] + viewProj->m[1]; |
| 84 | bottom->y = viewProj->m[7] + viewProj->m[5]; |
| 85 | bottom->z = viewProj->m[11] + viewProj->m[9]; |
| 86 | bottom->w = viewProj->m[15] + viewProj->m[13]; |
| 87 | |
| 88 | near->x = viewProj->m[3] + viewProj->m[2]; |
| 89 | near->y = viewProj->m[7] + viewProj->m[6]; |
| 90 | near->z = viewProj->m[11] + viewProj->m[10]; |
| 91 | near->w = viewProj->m[15] + viewProj->m[14]; |
| 92 | |
| 93 | far->x = viewProj->m[3] - viewProj->m[2]; |
| 94 | far->y = viewProj->m[7] - viewProj->m[6]; |
| 95 | far->z = viewProj->m[11] - viewProj->m[10]; |
| 96 | far->w = viewProj->m[15] - viewProj->m[14]; |
| 97 | |
| 98 | float len = length(left->xyz); |
| 99 | *left /= len; |
| 100 | len = length(right->xyz); |
| 101 | *right /= len; |
| 102 | len = length(top->xyz); |
| 103 | *top /= len; |
| 104 | len = length(bottom->xyz); |
| 105 | *bottom /= len; |
| 106 | len = length(near->xyz); |
| 107 | *near /= len; |
| 108 | len = length(far->xyz); |
| 109 | *far /= len; |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | * Checks if a sphere is withing the 6 frustum planes |
| 114 | * |
| 115 | * Parameters: |
| 116 | * sphere float4 representing the sphere |
| 117 | * left left plane |
| 118 | * right right plane |
| 119 | * top top plane |
| 120 | * bottom bottom plane |
| 121 | * near near plane |
| 122 | * far far plane |
| 123 | */ |
| 124 | static inline bool __attribute__((always_inline, overloadable)) |
| 125 | rsIsSphereInFrustum(float4* sphere, float4* left, float4* right, float4* top, float4* bottom, |
| 126 | float4* near, float4* far) { |
| 127 | float distToCenter = dot(left->xyz, sphere->xyz) + left->w; |
| 128 | if (distToCenter < -sphere->w) { |
| 129 | return false; |
| 130 | } |
| 131 | distToCenter = dot(right->xyz, sphere->xyz) + right->w; |
| 132 | if (distToCenter < -sphere->w) { |
| 133 | return false; |
| 134 | } |
| 135 | distToCenter = dot(top->xyz, sphere->xyz) + top->w; |
| 136 | if (distToCenter < -sphere->w) { |
| 137 | return false; |
| 138 | } |
| 139 | distToCenter = dot(bottom->xyz, sphere->xyz) + bottom->w; |
| 140 | if (distToCenter < -sphere->w) { |
| 141 | return false; |
| 142 | } |
| 143 | distToCenter = dot(near->xyz, sphere->xyz) + near->w; |
| 144 | if (distToCenter < -sphere->w) { |
| 145 | return false; |
| 146 | } |
| 147 | distToCenter = dot(far->xyz, sphere->xyz) + far->w; |
| 148 | if (distToCenter < -sphere->w) { |
| 149 | return false; |
| 150 | } |
| 151 | return true; |
| 152 | } |
| 153 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 154 | /* |
| 155 | * rsMatrixGet: Get one element |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 156 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 157 | * Returns one element of a matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 158 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 159 | * Warning: The order of the column and row parameters may be unexpected. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 160 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 161 | * Parameters: |
| 162 | * m The matrix to extract the element from. |
| 163 | * col The zero-based column of the element to be extracted. |
| 164 | * row The zero-based row of the element to extracted. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 165 | */ |
Jean-Luc Brouillet | 129c147 | 2015-03-02 15:37:07 -0800 | [diff] [blame] | 166 | extern float __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 167 | rsMatrixGet(const rs_matrix4x4* m, uint32_t col, uint32_t row); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 168 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 169 | extern float __attribute__((overloadable)) |
| 170 | rsMatrixGet(const rs_matrix3x3* m, uint32_t col, uint32_t row); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 171 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 172 | extern float __attribute__((overloadable)) |
| 173 | rsMatrixGet(const rs_matrix2x2* m, uint32_t col, uint32_t row); |
| 174 | |
| 175 | /* |
| 176 | * rsMatrixInverse: Inverts a matrix in place |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 177 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 178 | * Returns true if the matrix was successfully inverted. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 179 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 180 | * Parameters: |
| 181 | * m The matrix to invert. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 182 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 183 | extern bool __attribute__((overloadable)) |
| 184 | rsMatrixInverse(rs_matrix4x4* m); |
| 185 | |
| 186 | /* |
| 187 | * rsMatrixInverseTranspose: Inverts and transpose a matrix in place |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 188 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 189 | * The matrix is first inverted then transposed. |
| 190 | * Returns true if the matrix was successfully inverted. |
| 191 | * |
| 192 | * Parameters: |
| 193 | * m The matrix to modify. |
| 194 | */ |
| 195 | extern bool __attribute__((overloadable)) |
| 196 | rsMatrixInverseTranspose(rs_matrix4x4* m); |
| 197 | |
| 198 | /* |
| 199 | * rsMatrixLoad: Load or copy a matrix |
| 200 | * |
| 201 | * Set the elements of a matrix from an array of floats or from another matrix. |
| 202 | * |
| 203 | * If loading from an array, the floats should be in row-major order, i.e. the element a |
| 204 | * row 0, column 0 should be first, followed by the element at |
| 205 | * row 0, column 1, etc. |
| 206 | * |
| 207 | * If loading from a matrix and the source is smaller than the destination, the rest of the |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 208 | * destination is filled with elements of the identity matrix. E.g. |
| 209 | * loading a rs_matrix2x2 into a rs_matrix4x4 will give: |
| 210 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 211 | * m00 m01 0.0 0.0 |
| 212 | * m10 m11 0.0 0.0 |
| 213 | * 0.0 0.0 1.0 0.0 |
| 214 | * 0.0 0.0 0.0 1.0 |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 215 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 216 | * |
| 217 | * Parameters: |
| 218 | * destination The matrix to set. |
| 219 | * 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. |
| 220 | * source The source matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 221 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 222 | extern void __attribute__((overloadable)) |
| 223 | rsMatrixLoad(rs_matrix4x4* destination, const float* array); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 224 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 225 | extern void __attribute__((overloadable)) |
| 226 | rsMatrixLoad(rs_matrix3x3* destination, const float* array); |
| 227 | |
| 228 | extern void __attribute__((overloadable)) |
| 229 | rsMatrixLoad(rs_matrix2x2* destination, const float* array); |
| 230 | |
| 231 | extern void __attribute__((overloadable)) |
| 232 | rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix4x4* source); |
| 233 | |
| 234 | extern void __attribute__((overloadable)) |
| 235 | rsMatrixLoad(rs_matrix3x3* destination, const rs_matrix3x3* source); |
| 236 | |
| 237 | extern void __attribute__((overloadable)) |
| 238 | rsMatrixLoad(rs_matrix2x2* destination, const rs_matrix2x2* source); |
| 239 | |
| 240 | extern void __attribute__((overloadable)) |
| 241 | rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix3x3* source); |
| 242 | |
| 243 | extern void __attribute__((overloadable)) |
| 244 | rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix2x2* source); |
| 245 | |
| 246 | /* |
| 247 | * rsMatrixLoadFrustum: Load a frustum projection matrix |
| 248 | * |
| 249 | * Constructs a frustum projection matrix, transforming the box |
| 250 | * identified by the six clipping planes left, right, bottom, top, |
| 251 | * near, far. |
| 252 | * |
| 253 | * To apply this projection to a vector, multiply the vector by the |
| 254 | * created matrix using rsMatrixMultiply(). |
| 255 | * |
| 256 | * Parameters: |
| 257 | * m The matrix to set. |
| 258 | */ |
| 259 | extern void __attribute__((overloadable)) |
| 260 | rsMatrixLoadFrustum(rs_matrix4x4* m, float left, float right, float bottom, float top, |
| 261 | float near, float far); |
| 262 | |
| 263 | /* |
| 264 | * rsMatrixLoadIdentity: Load identity matrix |
| 265 | * |
| 266 | * Set the elements of a matrix to the identity matrix. |
| 267 | * |
| 268 | * Parameters: |
| 269 | * m The matrix to set. |
| 270 | */ |
| 271 | extern void __attribute__((overloadable)) |
| 272 | rsMatrixLoadIdentity(rs_matrix4x4* m); |
| 273 | |
| 274 | extern void __attribute__((overloadable)) |
| 275 | rsMatrixLoadIdentity(rs_matrix3x3* m); |
| 276 | |
| 277 | extern void __attribute__((overloadable)) |
| 278 | rsMatrixLoadIdentity(rs_matrix2x2* m); |
| 279 | |
| 280 | /* |
| 281 | * rsMatrixLoadMultiply: Multiply two matrices |
| 282 | * |
| 283 | * Sets m to the matrix product of lhs * rhs. |
| 284 | * |
| 285 | * To combine two 4x4 transformaton matrices, multiply the second transformation matrix |
| 286 | * by the first transformation matrix. E.g. to create a transformation matrix that applies |
| 287 | * the transformation s1 followed by s2, call |
| 288 | * rsMatrixLoadMultiply(&combined, &s2, &s1). |
| 289 | * |
| 290 | * Warning: Prior to version 21, storing the result back into right matrix is not supported and |
| 291 | * will result in undefined behavior. Use rsMatrixMulitply instead. E.g. instead of doing |
| 292 | * rsMatrixLoadMultiply (&m2r, &m2r, &m2l), use rsMatrixMultiply (&m2r, &m2l). |
| 293 | * rsMatrixLoadMultiply (&m2l, &m2r, &m2l) works as expected. |
| 294 | * |
| 295 | * Parameters: |
| 296 | * m The matrix to set. |
| 297 | * lhs The left matrix of the product. |
| 298 | * rhs The right matrix of the product. |
| 299 | */ |
| 300 | extern void __attribute__((overloadable)) |
| 301 | rsMatrixLoadMultiply(rs_matrix4x4* m, const rs_matrix4x4* lhs, const rs_matrix4x4* rhs); |
| 302 | |
| 303 | extern void __attribute__((overloadable)) |
| 304 | rsMatrixLoadMultiply(rs_matrix3x3* m, const rs_matrix3x3* lhs, const rs_matrix3x3* rhs); |
| 305 | |
| 306 | extern void __attribute__((overloadable)) |
| 307 | rsMatrixLoadMultiply(rs_matrix2x2* m, const rs_matrix2x2* lhs, const rs_matrix2x2* rhs); |
| 308 | |
| 309 | /* |
| 310 | * rsMatrixLoadOrtho: Load an orthographic projection matrix |
| 311 | * |
| 312 | * Constructs an orthographic projection matrix, transforming the box |
| 313 | * identified by the six clipping planes left, right, bottom, top, |
| 314 | * near, far into a unit cube with a corner at |
| 315 | * (-1, -1, -1) and the opposite at (1, 1, 1). |
| 316 | * |
| 317 | * To apply this projection to a vector, multiply the vector by the |
| 318 | * created matrix using rsMatrixMultiply(). |
| 319 | * |
| 320 | * See https://en.wikipedia.org/wiki/Orthographic_projection . |
| 321 | * |
| 322 | * Parameters: |
| 323 | * m The matrix to set. |
| 324 | */ |
| 325 | extern void __attribute__((overloadable)) |
| 326 | rsMatrixLoadOrtho(rs_matrix4x4* m, float left, float right, float bottom, float top, float near, |
| 327 | float far); |
| 328 | |
| 329 | /* |
| 330 | * rsMatrixLoadPerspective: Load a perspective projection matrix |
| 331 | * |
| 332 | * Constructs a perspective projection matrix, assuming a symmetrical field of view. |
| 333 | * |
| 334 | * To apply this projection to a vector, multiply the vector by the |
| 335 | * created matrix using rsMatrixMultiply(). |
| 336 | * |
| 337 | * Parameters: |
| 338 | * m The matrix to set. |
| 339 | * fovy Field of view, in degrees along the Y axis. |
| 340 | * aspect Ratio of x / y. |
| 341 | * near The near clipping plane. |
| 342 | * far The far clipping plane. |
| 343 | */ |
| 344 | extern void __attribute__((overloadable)) |
| 345 | rsMatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far); |
| 346 | |
| 347 | /* |
| 348 | * rsMatrixLoadRotate: Load a rotation matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 349 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 350 | * This function creates a rotation matrix. The axis of rotation is the |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 351 | * (x, y, z) vector. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 352 | * |
| 353 | * To rotate a vector, multiply the vector by the created matrix |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 354 | * using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 355 | * |
| 356 | * See http://en.wikipedia.org/wiki/Rotation_matrix . |
| 357 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 358 | * Parameters: |
| 359 | * m The matrix to set. |
| 360 | * rot How much rotation to do, in degrees. |
| 361 | * x The x component of the vector that is the axis of rotation. |
| 362 | * y The y component of the vector that is the axis of rotation. |
| 363 | * z The z component of the vector that is the axis of rotation. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 364 | */ |
| 365 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 366 | rsMatrixLoadRotate(rs_matrix4x4* m, float rot, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 367 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 368 | /* |
| 369 | * rsMatrixLoadScale: Load a scaling matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 370 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 371 | * This function creates a scaling matrix, where each component of a |
| 372 | * vector is multiplied by a number. This number can be negative. |
| 373 | * |
| 374 | * To scale a vector, multiply the vector by the created matrix |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 375 | * using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 376 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 377 | * Parameters: |
| 378 | * m The matrix to set. |
| 379 | * x The multiple to scale the x components by. |
| 380 | * y The multiple to scale the y components by. |
| 381 | * z The multiple to scale the z components by. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 382 | */ |
| 383 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 384 | rsMatrixLoadScale(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 385 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 386 | /* |
| 387 | * rsMatrixLoadTranslate: Load a translation matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 388 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 389 | * This function creates a translation matrix, where a |
| 390 | * number is added to each element of a vector. |
| 391 | * |
| 392 | * To translate a vector, multiply the vector by the created matrix |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 393 | * using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 394 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 395 | * Parameters: |
| 396 | * m The matrix to set. |
| 397 | * x The number to add to each x component. |
| 398 | * y The number to add to each y component. |
| 399 | * z The number to add to each z component. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 400 | */ |
| 401 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 402 | rsMatrixLoadTranslate(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 403 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 404 | /* |
| 405 | * rsMatrixMultiply: Multiply a matrix by a vector or another matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 406 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 407 | * For the matrix by matrix variant, sets m to the matrix product m * rhs. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 408 | * |
| 409 | * When combining two 4x4 transformation matrices using this function, the resulting |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 410 | * matrix will correspond to performing the rhs transformation first followed by |
| 411 | * the original m transformation. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 412 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 413 | * For the matrix by vector variant, returns the post-multiplication of the vector |
| 414 | * by the matrix, ie. m * in. |
| 415 | * |
| 416 | * When multiplying a float3 to a rs_matrix4x4, the vector is expanded with (1). |
| 417 | * |
| 418 | * When multiplying a float2 to a rs_matrix4x4, the vector is expanded with (0, 1). |
| 419 | * |
| 420 | * When multiplying a float2 to a rs_matrix3x3, the vector is expanded with (0). |
| 421 | * |
| 422 | * Starting with API 14, this function takes a const matrix as the first argument. |
| 423 | * |
| 424 | * Parameters: |
| 425 | * m The left matrix of the product and the matrix to be set. |
| 426 | * rhs The right matrix of the product. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 427 | */ |
| 428 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 429 | rsMatrixMultiply(rs_matrix4x4* m, const rs_matrix4x4* rhs); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 430 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 431 | extern void __attribute__((overloadable)) |
| 432 | rsMatrixMultiply(rs_matrix3x3* m, const rs_matrix3x3* rhs); |
| 433 | |
| 434 | extern void __attribute__((overloadable)) |
| 435 | rsMatrixMultiply(rs_matrix2x2* m, const rs_matrix2x2* rhs); |
| 436 | |
| 437 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 438 | extern float4 __attribute__((overloadable)) |
| 439 | rsMatrixMultiply(rs_matrix4x4* m, float4 in); |
| 440 | #endif |
| 441 | |
| 442 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 443 | extern float4 __attribute__((overloadable)) |
| 444 | rsMatrixMultiply(rs_matrix4x4* m, float3 in); |
| 445 | #endif |
| 446 | |
| 447 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 448 | extern float4 __attribute__((overloadable)) |
| 449 | rsMatrixMultiply(rs_matrix4x4* m, float2 in); |
| 450 | #endif |
| 451 | |
| 452 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 453 | extern float3 __attribute__((overloadable)) |
| 454 | rsMatrixMultiply(rs_matrix3x3* m, float3 in); |
| 455 | #endif |
| 456 | |
| 457 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 458 | extern float3 __attribute__((overloadable)) |
| 459 | rsMatrixMultiply(rs_matrix3x3* m, float2 in); |
| 460 | #endif |
| 461 | |
| 462 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 463 | extern float2 __attribute__((overloadable)) |
| 464 | rsMatrixMultiply(rs_matrix2x2* m, float2 in); |
| 465 | #endif |
| 466 | |
| 467 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 468 | extern float4 __attribute__((overloadable)) |
| 469 | rsMatrixMultiply(const rs_matrix4x4* m, float4 in); |
| 470 | #endif |
| 471 | |
| 472 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 473 | extern float4 __attribute__((overloadable)) |
| 474 | rsMatrixMultiply(const rs_matrix4x4* m, float3 in); |
| 475 | #endif |
| 476 | |
| 477 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 478 | extern float4 __attribute__((overloadable)) |
| 479 | rsMatrixMultiply(const rs_matrix4x4* m, float2 in); |
| 480 | #endif |
| 481 | |
| 482 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 483 | extern float3 __attribute__((overloadable)) |
| 484 | rsMatrixMultiply(const rs_matrix3x3* m, float3 in); |
| 485 | #endif |
| 486 | |
| 487 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 488 | extern float3 __attribute__((overloadable)) |
| 489 | rsMatrixMultiply(const rs_matrix3x3* m, float2 in); |
| 490 | #endif |
| 491 | |
| 492 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 493 | extern float2 __attribute__((overloadable)) |
| 494 | rsMatrixMultiply(const rs_matrix2x2* m, float2 in); |
| 495 | #endif |
| 496 | |
| 497 | /* |
| 498 | * rsMatrixRotate: Apply a rotation to a transformation matrix |
| 499 | * |
| 500 | * Multiply the matrix m with a rotation matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 501 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 502 | * This function modifies a transformation matrix to first do a rotation. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 503 | * The axis of rotation is the (x, y, z) vector. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 504 | * |
| 505 | * To apply this combined transformation to a vector, multiply |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 506 | * the vector by the created matrix using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 507 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 508 | * Parameters: |
| 509 | * m The matrix to modify. |
| 510 | * rot How much rotation to do, in degrees. |
| 511 | * x The x component of the vector that is the axis of rotation. |
| 512 | * y The y component of the vector that is the axis of rotation. |
| 513 | * z The z component of the vector that is the axis of rotation. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 514 | */ |
| 515 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 516 | rsMatrixRotate(rs_matrix4x4* m, float rot, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 517 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 518 | /* |
| 519 | * rsMatrixScale: Apply a scaling to a transformation matrix |
| 520 | * |
| 521 | * Multiply the matrix m with a scaling matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 522 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 523 | * This function modifies a transformation matrix to first do a scaling. |
| 524 | * When scaling, each component of a vector is multiplied by a number. |
| 525 | * This number can be negative. |
| 526 | * |
| 527 | * To apply this combined transformation to a vector, multiply |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 528 | * the vector by the created matrix using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 529 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 530 | * Parameters: |
| 531 | * m The matrix to modify. |
| 532 | * x The multiple to scale the x components by. |
| 533 | * y The multiple to scale the y components by. |
| 534 | * z The multiple to scale the z components by. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 535 | */ |
| 536 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 537 | rsMatrixScale(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 538 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 539 | /* |
| 540 | * rsMatrixSet: Set one element |
| 541 | * |
| 542 | * Set an element of a matrix. |
| 543 | * |
| 544 | * Warning: The order of the column and row parameters may be unexpected. |
| 545 | * |
| 546 | * Parameters: |
| 547 | * m The matrix that will be modified. |
| 548 | * col The zero-based column of the element to be set. |
| 549 | * row The zero-based row of the element to be set. |
| 550 | * v The value to set. |
| 551 | */ |
| 552 | extern void __attribute__((overloadable)) |
| 553 | rsMatrixSet(rs_matrix4x4* m, uint32_t col, uint32_t row, float v); |
| 554 | |
| 555 | extern void __attribute__((overloadable)) |
| 556 | rsMatrixSet(rs_matrix3x3* m, uint32_t col, uint32_t row, float v); |
| 557 | |
| 558 | extern void __attribute__((overloadable)) |
| 559 | rsMatrixSet(rs_matrix2x2* m, uint32_t col, uint32_t row, float v); |
| 560 | |
| 561 | /* |
| 562 | * rsMatrixTranslate: Apply a translation to a transformation matrix |
| 563 | * |
| 564 | * Multiply the matrix m with a translation matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 565 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 566 | * This function modifies a transformation matrix to first |
| 567 | * do a translation. When translating, a number is added |
| 568 | * to each component of a vector. |
| 569 | * |
| 570 | * To apply this combined transformation to a vector, multiply |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 571 | * the vector by the created matrix using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 572 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 573 | * Parameters: |
| 574 | * m The matrix to modify. |
| 575 | * x The number to add to each x component. |
| 576 | * y The number to add to each y component. |
| 577 | * z The number to add to each z component. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 578 | */ |
| 579 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 580 | rsMatrixTranslate(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 581 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 582 | /* |
| 583 | * rsMatrixTranspose: Transpose a matrix place |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 584 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 585 | * Transpose the matrix m in place. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 586 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 587 | * Parameters: |
| 588 | * m The matrix to transpose. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 589 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 590 | extern void __attribute__((overloadable)) |
| 591 | rsMatrixTranspose(rs_matrix4x4* m); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 592 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 593 | extern void __attribute__((overloadable)) |
| 594 | rsMatrixTranspose(rs_matrix3x3* m); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 595 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 596 | extern void __attribute__((overloadable)) |
| 597 | rsMatrixTranspose(rs_matrix2x2* m); |
| 598 | |
| 599 | #endif // RENDERSCRIPT_RS_MATRIX_RSH |