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 | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 17 | // Don't edit this file! It is auto-generated by frameworks/rs/api/generate.sh. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 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 | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 47 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 48 | #ifndef RENDERSCRIPT_RS_MATRIX_RSH |
| 49 | #define RENDERSCRIPT_RS_MATRIX_RSH |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 50 | |
Jean-Luc Brouillet | be21638 | 2015-03-22 12:44:27 -0700 | [diff] [blame] | 51 | #include "rs_vector_math.rsh" |
| 52 | |
| 53 | /* |
| 54 | * Computes 6 frustum planes from the view projection matrix |
| 55 | * |
| 56 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 57 | * 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 Brouillet | be21638 | 2015-03-22 12:44:27 -0700 | [diff] [blame] | 64 | */ |
| 65 | static 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 Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 117 | * 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 Brouillet | be21638 | 2015-03-22 12:44:27 -0700 | [diff] [blame] | 124 | */ |
| 125 | static 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 155 | /* |
| 156 | * rsMatrixGet: Get one element |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 157 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 158 | * Returns one element of a matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 159 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 160 | * 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] | 161 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 162 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 163 | * 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 166 | */ |
Jean-Luc Brouillet | 129c147 | 2015-03-02 15:37:07 -0800 | [diff] [blame] | 167 | extern float __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 168 | rsMatrixGet(const rs_matrix4x4* m, uint32_t col, uint32_t row); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 169 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 170 | extern float __attribute__((overloadable)) |
| 171 | rsMatrixGet(const rs_matrix3x3* m, uint32_t col, uint32_t row); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 172 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 173 | extern 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 178 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 179 | * Returns true if the matrix was successfully inverted. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 180 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 181 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 182 | * m: The matrix to invert. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 183 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 184 | extern bool __attribute__((overloadable)) |
| 185 | rsMatrixInverse(rs_matrix4x4* m); |
| 186 | |
| 187 | /* |
| 188 | * rsMatrixInverseTranspose: Inverts and transpose a matrix in place |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 189 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 190 | * The matrix is first inverted then transposed. |
| 191 | * Returns true if the matrix was successfully inverted. |
| 192 | * |
| 193 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 194 | * m: The matrix to modify. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 195 | */ |
| 196 | extern 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 Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 209 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 212 | * 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 Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 216 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 217 | * |
| 218 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 219 | * 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 222 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 223 | extern void __attribute__((overloadable)) |
| 224 | rsMatrixLoad(rs_matrix4x4* destination, const float* array); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 225 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 226 | extern void __attribute__((overloadable)) |
| 227 | rsMatrixLoad(rs_matrix3x3* destination, const float* array); |
| 228 | |
| 229 | extern void __attribute__((overloadable)) |
| 230 | rsMatrixLoad(rs_matrix2x2* destination, const float* array); |
| 231 | |
| 232 | extern void __attribute__((overloadable)) |
| 233 | rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix4x4* source); |
| 234 | |
| 235 | extern void __attribute__((overloadable)) |
| 236 | rsMatrixLoad(rs_matrix3x3* destination, const rs_matrix3x3* source); |
| 237 | |
| 238 | extern void __attribute__((overloadable)) |
| 239 | rsMatrixLoad(rs_matrix2x2* destination, const rs_matrix2x2* source); |
| 240 | |
| 241 | extern void __attribute__((overloadable)) |
| 242 | rsMatrixLoad(rs_matrix4x4* destination, const rs_matrix3x3* source); |
| 243 | |
| 244 | extern 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 Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 258 | * m: The matrix to set. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 259 | */ |
| 260 | extern 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 Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 270 | * m: The matrix to set. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 271 | */ |
| 272 | extern void __attribute__((overloadable)) |
| 273 | rsMatrixLoadIdentity(rs_matrix4x4* m); |
| 274 | |
| 275 | extern void __attribute__((overloadable)) |
| 276 | rsMatrixLoadIdentity(rs_matrix3x3* m); |
| 277 | |
| 278 | extern 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 Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 297 | * m: The matrix to set. |
| 298 | * lhs: The left matrix of the product. |
| 299 | * rhs: The right matrix of the product. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 300 | */ |
| 301 | extern void __attribute__((overloadable)) |
| 302 | rsMatrixLoadMultiply(rs_matrix4x4* m, const rs_matrix4x4* lhs, const rs_matrix4x4* rhs); |
| 303 | |
| 304 | extern void __attribute__((overloadable)) |
| 305 | rsMatrixLoadMultiply(rs_matrix3x3* m, const rs_matrix3x3* lhs, const rs_matrix3x3* rhs); |
| 306 | |
| 307 | extern 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 Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 324 | * m: The matrix to set. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 325 | */ |
| 326 | extern 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 Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 339 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 344 | */ |
| 345 | extern 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 350 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 351 | * 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] | 352 | * (x, y, z) vector. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 353 | * |
| 354 | * To rotate a vector, multiply the vector by the created matrix |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 355 | * using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 356 | * |
| 357 | * See http://en.wikipedia.org/wiki/Rotation_matrix . |
| 358 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 359 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 360 | * 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 365 | */ |
| 366 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 367 | rsMatrixLoadRotate(rs_matrix4x4* m, float rot, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 368 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 369 | /* |
| 370 | * rsMatrixLoadScale: Load a scaling matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 371 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 372 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 376 | * using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 377 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 378 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 379 | * 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 383 | */ |
| 384 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 385 | rsMatrixLoadScale(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 386 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 387 | /* |
| 388 | * rsMatrixLoadTranslate: Load a translation matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 389 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 390 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 394 | * using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 395 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 396 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 397 | * 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 401 | */ |
| 402 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 403 | rsMatrixLoadTranslate(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 404 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 405 | /* |
| 406 | * rsMatrixMultiply: Multiply a matrix by a vector or another matrix |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 407 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 408 | * 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] | 409 | * |
| 410 | * When combining two 4x4 transformation matrices using this function, the resulting |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 411 | * matrix will correspond to performing the rhs transformation first followed by |
| 412 | * the original m transformation. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 413 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 414 | * 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 Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 426 | * m: The left matrix of the product and the matrix to be set. |
| 427 | * rhs: The right matrix of the product. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 428 | */ |
| 429 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 430 | rsMatrixMultiply(rs_matrix4x4* m, const rs_matrix4x4* rhs); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 431 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 432 | extern void __attribute__((overloadable)) |
| 433 | rsMatrixMultiply(rs_matrix3x3* m, const rs_matrix3x3* rhs); |
| 434 | |
| 435 | extern void __attribute__((overloadable)) |
| 436 | rsMatrixMultiply(rs_matrix2x2* m, const rs_matrix2x2* rhs); |
| 437 | |
| 438 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 439 | extern float4 __attribute__((overloadable)) |
| 440 | rsMatrixMultiply(rs_matrix4x4* m, float4 in); |
| 441 | #endif |
| 442 | |
| 443 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 444 | extern float4 __attribute__((overloadable)) |
| 445 | rsMatrixMultiply(rs_matrix4x4* m, float3 in); |
| 446 | #endif |
| 447 | |
| 448 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 449 | extern float4 __attribute__((overloadable)) |
| 450 | rsMatrixMultiply(rs_matrix4x4* m, float2 in); |
| 451 | #endif |
| 452 | |
| 453 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 454 | extern float3 __attribute__((overloadable)) |
| 455 | rsMatrixMultiply(rs_matrix3x3* m, float3 in); |
| 456 | #endif |
| 457 | |
| 458 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 459 | extern float3 __attribute__((overloadable)) |
| 460 | rsMatrixMultiply(rs_matrix3x3* m, float2 in); |
| 461 | #endif |
| 462 | |
| 463 | #if !defined(RS_VERSION) || (RS_VERSION <= 13) |
| 464 | extern float2 __attribute__((overloadable)) |
| 465 | rsMatrixMultiply(rs_matrix2x2* m, float2 in); |
| 466 | #endif |
| 467 | |
| 468 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 469 | extern float4 __attribute__((overloadable)) |
| 470 | rsMatrixMultiply(const rs_matrix4x4* m, float4 in); |
| 471 | #endif |
| 472 | |
| 473 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 474 | extern float4 __attribute__((overloadable)) |
| 475 | rsMatrixMultiply(const rs_matrix4x4* m, float3 in); |
| 476 | #endif |
| 477 | |
| 478 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 479 | extern float4 __attribute__((overloadable)) |
| 480 | rsMatrixMultiply(const rs_matrix4x4* m, float2 in); |
| 481 | #endif |
| 482 | |
| 483 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 484 | extern float3 __attribute__((overloadable)) |
| 485 | rsMatrixMultiply(const rs_matrix3x3* m, float3 in); |
| 486 | #endif |
| 487 | |
| 488 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 489 | extern float3 __attribute__((overloadable)) |
| 490 | rsMatrixMultiply(const rs_matrix3x3* m, float2 in); |
| 491 | #endif |
| 492 | |
| 493 | #if (defined(RS_VERSION) && (RS_VERSION >= 14)) |
| 494 | extern 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 502 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 503 | * This function modifies a transformation matrix to first do a rotation. |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 504 | * The axis of rotation is the (x, y, z) vector. |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 505 | * |
| 506 | * To apply this combined transformation to a vector, multiply |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 507 | * the vector by the created matrix using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 508 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 509 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 510 | * 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 515 | */ |
| 516 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 517 | rsMatrixRotate(rs_matrix4x4* m, float rot, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 518 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 519 | /* |
| 520 | * rsMatrixScale: Apply a scaling to a transformation matrix |
| 521 | * |
| 522 | * Multiply the matrix m with a scaling matrix. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 523 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 524 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 529 | * the vector by the created matrix using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 530 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 531 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 532 | * 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 536 | */ |
| 537 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 538 | rsMatrixScale(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 539 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 540 | /* |
| 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 Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 548 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 552 | */ |
| 553 | extern void __attribute__((overloadable)) |
| 554 | rsMatrixSet(rs_matrix4x4* m, uint32_t col, uint32_t row, float v); |
| 555 | |
| 556 | extern void __attribute__((overloadable)) |
| 557 | rsMatrixSet(rs_matrix3x3* m, uint32_t col, uint32_t row, float v); |
| 558 | |
| 559 | extern 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 566 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 567 | * 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 Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 572 | * the vector by the created matrix using rsMatrixMultiply(). |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 573 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 574 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 575 | * 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 Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 579 | */ |
| 580 | extern void __attribute__((overloadable)) |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 581 | rsMatrixTranslate(rs_matrix4x4* m, float x, float y, float z); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 582 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 583 | /* |
| 584 | * rsMatrixTranspose: Transpose a matrix place |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 585 | * |
Jean-Luc Brouillet | 1bb2eed | 2014-09-05 17:44:48 -0700 | [diff] [blame] | 586 | * Transpose the matrix m in place. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 587 | * |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 588 | * Parameters: |
Jean-Luc Brouillet | 4a73004 | 2015-04-02 16:15:25 -0700 | [diff] [blame^] | 589 | * m: The matrix to transpose. |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 590 | */ |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 591 | extern void __attribute__((overloadable)) |
| 592 | rsMatrixTranspose(rs_matrix4x4* m); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 593 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 594 | extern void __attribute__((overloadable)) |
| 595 | rsMatrixTranspose(rs_matrix3x3* m); |
Jason Sams | 044e2ee | 2011-08-08 16:52:30 -0700 | [diff] [blame] | 596 | |
Jean-Luc Brouillet | c5184e2 | 2015-03-13 13:51:24 -0700 | [diff] [blame] | 597 | extern void __attribute__((overloadable)) |
| 598 | rsMatrixTranspose(rs_matrix2x2* m); |
| 599 | |
| 600 | #endif // RENDERSCRIPT_RS_MATRIX_RSH |